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 Sir,

    Could you please guide me or send me to automise Creating new database along with all object and constraints copying from existing database from the same server or may on seperate server using sql server 2005

    Reply
  • Please I need your assitance , I have MCSE NT 4 and I have been out work for some time and will like to get back in the industry and will like to have Knowledge of script writing for SQL, Access, PERL and/or JAVA.
    Please could you point me to the right direction.

    Looking forward to your response.

    Regards,

    Mike

    Reply
  • Is there a way to include the generated scripts in a transaction that that either the new database gets completely updated or else completely fails?

    Thanks!

    Reply
  • Hiii

    I Want to know

    how to get list of tables affected after one transaction occured in the DB?

    Reply
  • Hello Pinal,
    I need to copy data from one DB to another DB on same server and that too on daily basis so i am thinking of creating a scheduled job which will generate a script for entire schema of DB1 and then will execute it for DB2.
    so could you please share script which will automatically generate script for entire schema of a particular database(the one you mentioned at top of this thread).

    Reply
  • Hi Pinal,
    I want to automate the generate script task. I have gone through your posts on this topic but it doesnt seems to work and gives error “‘C:\Program’ is not recognized as an internal or external command,
    operable program or batch file.” Can you please help out and suggest easy to solve this problem

    Reply
  • Could you please send me the details as well, on how to automate this process

    Reply
  • Hi Pinal,

    I need to automate the process of scripting all the indexes of a database to a text file as a output and then dropping all the indexes of the databases.

    Can you please help me to do this.

    Thanks!

    Amit Kumar

    Reply
  • Reblogged this on Code Monkey Wrench and commented:
    Here is a link to my favorite SQL Blogger. He knows how to explain SQL Server concepts better than any other site I have been to.

    Reply
  • Hello Pinal,
    would you please tell me how to take backup of my database ?
    Mehar

    Reply
  • Thank you ………..

    Reply
  • what is dbo and can i create a dbo and also how to assign to db(if it is possible)

    Reply
  • surajmahajan
    March 7, 2012 5:28 pm

    hi
    can i get a table creation script as output ??

    Reply
  • Hi,

    Need to generate Database schema and Data scripts without using any tool or wizard, which are for SQL Azure Database Engine type.

    Can anyone help me on this ?

    Thanks in advance.

    Reply
  • Hi……………pls any one help me how to copy a database into another database by programming.

    Regards,
    Prashant

    Reply
  • I was instructed to do a database restore from backup and then remove the data, instead of scripting the entire database structure to create the new database. Can you explain what the difference could be? Thank you.

    Reply
  • chittaranjan
    May 11, 2012 2:16 pm

    i am using sql server 2008 r2 .my generated script does not have triggers and functions definations
    pls .. tell me what is the problem & how to archieve it

    Reply
  • Hi,

    Could you please send me the same details to automate script generation process.

    Thanks in advance

    Regards
    Atul

    Reply
  • Nalinikanta Tout

    Hi,

    Thank u very much Pinal for helping online

    Reply
  • Thank you :-)

    Reply

Leave a Reply