SQL SERVER – 2005 – Create Script to Copy Database Schema and All The Objects – Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects

Update: This article is re-written with SQL Server 2008 R2 instance over here: SQL SERVER – 2008 – 2008 R2 – Create Script to Copy Database Schema and All The Objects – Data, Schema, Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects

Following quick tutorial demonstrates how to create T-SQL script to copy complete database schema and all of its objects such as Stored Procedure, Functions, Triggers, Tables, Views, Constraints etc. You can review your schema, backup for reference or use it to compare with previous backup.

Step 1 : Start

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy1

Step 2 : Welcome Screen

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy2

Step 3 : Select One or Multiple Database
If Script all objects in the selected database checkbox is not selected it will give options to selected individual objects on respective screen. (e.g. Stored Procedure, Triggers and all other object will have their own screen where they can be selected)

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy3

Step 4 : Select database options

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy4

Step 5 : Select output option

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy5

Step 6 : Review Summary

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy6

Step 7 : Observe script generation process

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy7

Step 8 : Database object script generation completed in new query window

SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects databasecopy8

Reference : Pinal Dave (https://blog.sqlauthority.com), All images are protected by copyright owner SQLAuthority.com

Database, SQL Backup and Restore, SQL Constraint and Keys, SQL Cursor, SQL Download, SQL Function, SQL Index, SQL Scripts, SQL Stored Procedure, SQL Trigger
Previous Post
SQLAuthority News – Principles of Simplicity
Next Post
SQL SERVER – T-SQL Script to Insert Carriage Return and New Line Feed in Code

Related Posts

673 Comments. Leave new

  • Hello,
    I m new to sql server 2005. I have an sql script. But I dont know to run it. Please help me out.
    Thank U

    Reply
  • Sir,

    A)
    Could you please send me the details as well, on how to automate this process.

    B)
    Can you answer me the professional way to create a schema of tables in sql server for database building in develpment of website in asp.net

    Reply
  • rajesh k, you can write your own stored proc to automate this process. google for it.

    Reply
  • Hello,
    i wan to retrieve server objects relating to a user ….using c# if any one have idea do reply me …

    Reply
  • Dear Pinal,

    This is a nice article and thanks for it.

    I have one question. The script generated by this only creates the empty tables & other structures. But the table data is not backed up.

    Is there a way to generate this script including the data that was in the tables too? (much like a mySQL dump)?

    TIA

    Reply
  • Karnak Chakraborty
    February 5, 2010 7:20 pm

    Dear Pinal,

    I just want to know
    “how to get schema and data both in sql server by export”.

    I have create the script for schema and get the schema but when i want to get the data it could not insert into my database. A column TimeStamp datatype is in the all the table so i have faced an error from this.

    Can you please help me out.

    Best Regards
    Karnak

    Reply
  • Dear Pinal,

    I have one problem to solve it.

    I have one server at India and another server in UK.

    I need to export some data from India to UK server

    But condition is we have to send only those data for which in every table selected sysid ( sysid is field in every coulmn).

    there are more than

    Reply
  • Hi
    A question, our website was developed under sql 2005, and the server it will be installed on is sql 2008. can my website run correctly or i will face some troubles? please i need an answer urgenty?

    thank you

    Reply
  • can u please explain what is dataset,dataadapter,schema.gridview with example codes.
    And also with example codes.

    Reply
  • Hanan Salem,

    There wont be much problem
    Also search for Behaviour changes between SQL Server versions in Google/Bing

    Reply
  • Views can provide advantages over tables :
    ———————————————————

    Views can represent a subset of the data contained in a table
    Views can join and simplify multiple tables into a single virtual table
    Views can act as aggregated tables, where the database engine aggregates data (sum, average etc) and presents the calculated results as part of the data
    Views can hide the complexity of data; transparently partitioning the actual underlying table
    Views take very little space to store; the database contains only the definition of a view, not a copy of all the data it presents
    Depending on the SQL engine used, views can provide extra security
    Views can limit the degree of exposure of a table or tables to the outer world

    Reply
  • i know all sp names to be apply in new db, instead of selecting the required sp in th wizard is there any possible way to run the required sp in a db.

    Reply
  • Hello Pinal,

    Thank you for this great resource! I’ve got a SQL 2005 database on a Win2000 server that I need to upgrade. I’ve created a VM with Windows 2003 server and SQL 2005.
    I’d like to copy the database from the original server to the VM (which is on a different computer).

    I’ve generated your script that will copy the db, schema etc. I’m wondering if you would be able to help me figure out how to move the copy to another computer/server?

    Thanks in advance.

    Jeff

    Reply
  • Thanks so much. I was looking for this.

    Reply
  • Hello Pinal,

    Data Synchronization In SQL Server database table using sql script or TSQL script or code.

    I want to Synchronize my SQL Server database table at server end using client database table’s records.

    Actually, I have to updated SQL Server database table data/records with the client database.

    The client is sitting in the districts, who is entering the data/records collected from villages and block where there is no internate connection, so that data/records are entered offline at the client database these records must be updated and reflected at the SQL Server database at the end.

    If this can be accomplish by using TSQL ,Stored Procedure.

    Deepak Chandra

    Reply
  • gr8…!
    Thanks…!

    Reply
  • deepak:

    TableDiff.exe (included in SQL Management Studio) will do the job for you.

    Is a prompt command that is provided with the source parameters and the destination file where the script will be generated.

    Google it and you will find use esamples.

    Byron.

    Reply
  • gr8..!!

    Reply
  • iam required to take the backup of the database on the remote server everyday at a particular time .so i do remote login daily and take backup ( right click>tasks>backup…..) and again i send the backup file back to my local system.Is there any way we can automate the entire process plz help me sir
    thanks in advance

    Reply
    • You can make use of a job and schedule it
      Refer this for code sample which will take backup of database by appending current date in yyyymmdd format

      Reply
  • Hi Pinal,

    Could you please send me the details as well, on how to automate this process. I am trying to copy a database from a sql server management studio express.

    Thanks so much.

    Ryan

    Reply

Leave a Reply