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

  • Dear Sir,

    I installed Microsoft SQL Server 2005 in my pc . But i can’t create a database in my system so plz help in this matter….

    Reply
  • Abdul Razzaq
    May 11, 2011 2:09 pm

    Hi Pinal,

    please send me the same details to automate this process.
    one more thing that I’m not able to find ANSI Padding in my Scrept wizard. i am using sql server 2005

    please assist

    Thanks

    Abdul Razzaq

    Reply
  • hi, could i get the option to create script which will append data in database using sql server 2005?
    where i want to take data from one db & insert it into another(not restore)

    Reply
  • I need a query to Copy all the data from from one database to another database where the databases have same structure.
    please sennd a query ..it is urgent…

    Reply
  • HOW CAN CREATE TABLE USING STORE PROCEDURE USING GET VALUE IN TABLE NAME

    alter PROC sp_TP_CreateTable(@TABLENAME varchar)

    AS
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[@TABLENAME]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)

    create table [dbo].[@TABLENAME](ino int
    )

    sp_TP_CreateTable EMP_TABLE

    TO CREATE PROC BUT NOT CREATE TABLE

    Reply
  • hello
    I am using sql server 2005
    I have a table named users, columns are id,name,age,address.
    first column id is auto increment.
    I inserted all data successfully,
    when i delete a row from table using visual studio 2005,it is deleted successfully,but when i insert new row it does not place on that index i deleted,next index generate and new row places on next index.
    please tell me its solution.

    Reply
  • Hi Pinal,

    Could you please send me the same details to automate this process (SQL 2005)?

    Thanks in advance!!

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

    Thank you.
    Adriana

    Reply
  • Iam trying to come up with the best solution here and need some help. I have one server with about 200+ databases. How would be the best way to copy or script from one server to another? One is our production and the other is our stage. I tried to generate a script with the wizard but its all or one. I need only about 200 of the databases

    I basically need the copy of databases from production to stage automated on a regular basis. We are on SQl 2005 with windows server 2003

    Reply
  • Tirthankar Dey
    July 15, 2011 1:37 pm

    Can u please tell me how i take script with table value in sql server 2008

    Reply
  • Hi

    It is possible to backup database to remote server tap drive, if yes so please can you me send me detail.

    Thank in advance

    Reply
  • Hello sir,

    Reply
  • hello sir,

    I have use sql server 2000 amd 2005 in my same system , but my problem is i cannot marge with 2000 and 2005, then i want retore 2005 db into 2000 it my big problem … give some solution…
    i did do it attach ment and restore all failed how to possible to do

    Reply
  • Hi Pinal,

    Would like to know how to write a script, which can copy some of the fields in a table from 1 database to another table in another database?
    Hope you understand what I am asking here. :-)

    Thanks in advanced.
    Yvonne

    Reply
    • By copy, did you mean updating column values? You can join with other table and update columns

      update t1
      set t1.col=t2.col from table1 as t1
      inner join table2 as t2 on t1.keycol=t2.keycol

      Reply
  • Pinal Dave,

    Could you please email me the details on automating this process in SQL server 2008? Also if you are familiar with any good resources regarding automating script generating, I would be interested in that too.

    Thanks for your help.

    Reply
  • Copy one table one database data to another table different database ????

    Reply
  • and how to get create database back from the sql server generated scripts????

    Reply
  • Hi Pinal,

    Could you please send me the same details on how to automate this process (SQL 2008)?

    Thanks in advance!!

    Reply
  • How do I create a backup of the database schema and then automate it to create a copy overnight?

    Reply
  • Thank you. Very helpful.

    Reply

Leave a Reply