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

  • Hi Pinal,

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

    Thanks,
    Christine

    Reply
  • Hi Dave,

    I would like to have that details also.

    thanks in advance.

    Merry X’mas,

    Jule

    Reply
  • thank you

    Reply
  • Hi Dave;
    Would you please post or provide your method for automatically scripting databases for SQL Server 2008?
    Thaks!

    Reply
  • I would like to see your automation technique for script generation.

    Thanks,
    Dave

    Reply
  • Hi Pinal,
    can you share with us how to automate the creation of existing SQL2005 Scheduled Jobs into T-SQL script for disaster recovery purposes please?

    Thanks.

    Reply
  • SQL Scott Gleason
    January 22, 2011 8:11 pm

    For those of you asking Pinal to show you how to preform automation, please see the CodePlex site. [ ]

    Read the Database Publishing Wizard documentation.
    There are multiple command line switches you can use:

    Command Line Syntax
    sqlpubwiz script
    (
    -C connection_string | -d local_database_name
    [ -U local_user_name ][ -P local_password ][ -S local_server_name ]
    )output_file_or_directory [ -f ]
    )
    [ -schemaonly ]
    [ -dataonly ]
    [ -targetserver server-version ]
    [ -noschemaqualify ]
    [ -nodropexisting ]
    [ -q ]
    [ -? ]

    sqlpubwiz publish
    (
    -C connection_string | -d local_database_name
    [ -U local_user_name ][ -P local_password ][ -S local_server_name ]
    )
    (
    [ -R hoster_name ]
    [ -RW remote_web_service_addr ]
    [ -RWU remote_service_user_name ]
    [ -RWP remote_service_password ]
    [ -RS remote_databse_server ]
    [ -RD remote_database ]
    )
    [ -schemaonly ]
    [ -dataonly ]
    [ -targetserver server-version ]
    [ -noschemaqualify ]
    [ -nodropexisting ]
    [ -notransaction ]
    [ -q ]

    Thanks :-)
    Scott Gleason

    Reply
  • i am just staring to work with sql 2005 server,i have to create
    sql statement for display telphone number that mean there is
    database for all telephone number but when people call us i have to
    split taht phone number like country code ,localID,PBX,Exten for example
    let say one number 0443965045 in this number 0 for country code,
    44 for localID,39650 for PBX the rest 45 for EXTEN,could you
    please help to wrtie sql for this condition and also when i get
    extension number with one digit like 1 or 2 or 3 this must be disply with 0
    that mean like 01 or 02 or 03

    could you please

    Reply
  • how to get speedly data form remote sql server in vb.net

    Reply
  • how to get speedly data form remote sql server in vb.net desktop application

    Reply
    • Hi,
      i am just staring to work with sql 2005 server, for our software jobboss as backend support, where should i get the data stored in the database. how could i modify or change the data in it. please help me, thanx in advance.

      Reply
  • Dear sir
    Please Send this mail to me also.

    Reply
  • HI Pinal Dave,

    CUD U PLZ HELP ME ..

    I WANT TO migrate all tables from mysql to sql server. (Import all schemas to SQL server without data)..
    BUT HOW PLZ TELL ME ..

    REGARDS,
    HIMANSHU

    Reply
  • Manikandan,

    Hai Pinal..

    I need a solution for how to generate a script tables structure with records

    Thank you

    Reply
  • What is the best way to script schema difference and automate the execution of the script .
    for e.g. you want to release next version of your application and some modifications to the database schema. I have a copy of the old version db which I want to compare it to the new one and generate the script for the difference.

    Thanks
    Rakesh

    Reply
  • imagine i have a database “X” and database “Y”

    database X has tables “X1” “X2” “X3” “X4”
    database Y has tables “Y1” “Y2” “Y3” “Y4”

    i have to update table X1 with the values of Y1.

    i dont need too specific like x and y. i need a common query for doing the above mentioned method.

    Reply
  • I wanna wirte automatic script … so can yo explain me and give query… This script want for one month to one month

    Reply
  • How can create a password on my existing database in sql server 2005

    Reply
  • hi

    i am using local database to my application . i want to upload daily transactions into remote database (not for total database )

    could you please tell me how to generate script of one day transactions in sqlserver 2005 and and integrate with database remote server

    Reply
  • Vaibhav Pitale
    April 21, 2011 5:29 pm

    Sir I Want To Copy Stored Procedure From One Database To Other Database In Same SQL Server 2005

    Please Help Me

    Reply
  • Good Day Pinal Dave,

    Can you advice on the script for mirroring the database from MSSQL2008 as live database to MSSQL2005 as backup database?

    Thanks,
    William

    Reply

Leave a Reply