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

  • I want to database with data so i am generate Script but In sql server my ansi padding Option is not available . and only genarete script which is contain table but not data. so how can i get table with data?

    Reply
  • Hi,

    I have two databases : Local , Prod

    Made the table structure changes into the Local DB tables.
    now i want to apply the changes on the production server while preserving data on the production server.

    thanks in adv..
    Vikas

    Reply
    • Take alter table scripts and run them in the production server
      Before that make sure you have a very recent backup of the production database

      Reply
  • Hi Pinal,

    I hav 2 DB’s names TESTDB and SAMPLEDB , both DB table name is same(tableinsert) and fields name also same.

    I got TESTDB backup. Now i want to know whenever i restore .bak file to TESTDB at the same time SAMPLEDB also changed if it’s possible..? pls send me code and ideas..

    Thanks In advance

    Reply
  • Thanks you.

    Reply
  • Excuse my bad english.
    Error on replicated table.
    When i run sqlpubwiz on database with replicated table, i have : Erreurÿ: Erreur de syntaxe dans TextHeader de NumberedStoredProcedure ®ÿsp_MSdel_dboORD_PRO_PreneursOrdres;2ÿ¯.

    Reply
  • thank you thank you thank you I have been pulling my hair out trying to get ms publishing wiz to work but every where I looked I was told to do this longgggggg and complicatedddddd procedure i.e. you got this error because your db engine isn’t on (how do I turn it on? no answer) I was stuck looking and looking reading and reading. I will be the first to admit I still have a long way to go with c#.net, vwd and sql server before I will qualify as a web master but you have helped me immensely toward my goal of getting online and for this I can not thank you enough

    Reply
  • amrut kathavadiya
    April 10, 2010 9:46 am

    Hello Sir,

    i want to configure SQL SERVER 2008. when i give permission on perticular database with particular User id as DBO. that user access only that particular database.but he can see all Databases in his SMO.

    how can set , only the pemissable database see in his SMO. not all database on Server.

    thanks in Advance

    give me Reply as soon as possible.

    Reply
  • Hello sir

    How to import the MS access database into SQL server 2005.

    i want the code in vb.net .

    Reply
  • Im developing a website.. & at d last i hv came to knw that d database must be on SQL server.. how could i create script, and reuse my old DB. i cant create d DB twice.. its too large.. plzzz smbody reply……………………………plzzzzzzzzzzzzzzzzzzz

    Reply
  • I want to know about using SQL 2005 in bassic please

    Reply
  • Please help me
    I want to know about using SQL Server 2005 in bassic

    Reply
  • Thanks — great blog

    Reply
  • I am using VB.NET 2005 and SQL Express 2005. When I run the application it able to insert new records, but when I close the application the data is not reflecting in database.
    Please help.

    Reply
  • hi ,
    i want to generate automated backup from the database in sql server 2005 & 2008, so is it possible? if yes then how and please tell me what is the procedure for that. i m waiting for your reply..

    thanks,

    Reply
    • Hi Ankit

      -After Login,Expand Management->create new Maintenance plan
      -Drag ‘Back Up Database Task’ to design window
      -Then right click and edit the back up database task as per your requirements
      -Finally make a schedule and save it.

      Hope,you were looking for this sol!!!

      Amit

      Reply
  • Hi

    I want to copy a databse with table’s content,constraint(everything) to local machine without any wizard.
    Is there any SP or any other way,where i can copy one database and paste the same database with different name through script.

    Thanks
    Amit

    Reply
    • You can make use of backup

      Backup database your_db to disk=’File_path’

      You can restore it in different name using

      Backup database your_new_db to disk=’File_path’

      Reply
      • Thankx for the reply
        But i cant take backup and restore as the path would be different always.
        Also it would be time consuming too as mine is a huge database.
        If you know any other way,please let me know

        Thanks
        Amit

      • Read about SMO in SQL Server help file

  • hi
    thanks a lot this site helped me a lot bzc i was doing the work in the office but i am unable to co

    Reply
  • Bharat Bhushan
    May 11, 2010 5:53 pm

    I want to know that how we create a script with the backup of data that is store in the tables from server’, database????????

    Reply
  • VenkataRavi.CR
    May 11, 2010 6:19 pm

    Thanks Alot. It help’s me.


    VenkataRavi.CR

    Reply
  • Chandrashekar.M.S
    May 17, 2010 4:31 pm

    Hi, pls help me. I need to write a query to find where data is storing by default after taking a backup in SQL.. I need to run dis query in many systems.. pls help me…

    Reply
    • It is stored at the location that you speficify at the query

      backup database db_name to disk='file_path'

      Reply
  • can we generate a script for blank database in SQL Server 2008.

    Reply

Leave a Reply