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

Step 2 : Welcome Screen

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)

Step 4 : Select database options

Step 5 : Select output option

Step 6 : Review Summary

Step 7 : Observe script generation process

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

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





673 Comments. Leave new
hi , i have one question ..
i want to set password to one database in sql server 2005
but i dont know how ..
can u help me plz ??
i used this script to collation setting of all databases(server)…
will it work fine ???
i did it but i want to know
i used this script to change collation setting of all databases(server)…
i changed collation of all databases n i want all views, arelations betn databases…
so
will it work fine ???
i did it but i want to know
hello..
as i wrote i changed the collate setting of a database but now im getting log in error of administrator..
i resoved that problem by updating database engine…
but i want proper technique to change it so
please send or tell me the proper setting of STEP 4 (shown above in print screens) to get proper scripting to just change collate setting.. and i want all the properties, statistics, constraints ,etc related to that database
Hi,
What if I wanted to script all the views of a database, taking into account dependencies (I have some views that are based on other views). SQL Server 2000 did this, but alas 2005 doesn’t seem to.
Thanks. Any ideas welcome.
hi. i have done this for one of my database. i used ” generate scripts but at the end when it creates the query it will show an error like this :
Msg 2714, Level 16, State 6, Line 1
There is already an object named ‘Table_1’ in the database.
i test it with several databases but they produce the same error . what should i do? please help me.
thanks.
and i run it for one of my database. i used “tasks->generate scripts” but at the end when it creates the query it will show an error like this :
Msg 2714, Level 16, State 6, Line 1
There is already an object named ‘Table_1′ in the database.
i test it with several databases but they produce the same error . what should i do? please help me.
thanks
Hi Pinal
What if I want to create a MS-DOS/SQL job to export this text as txt/sql file?
Thanks.
Hi,
how to copy existing database tables without records to new database in sql server 2005
Hi Pinal,
In my project requirement is like, I have one master datbase when I went in one form where i sholud create new database copy same as master by simply clicking on create database button it should be same db has been created on given location. and attached with my server……
Thanks in Advance..
Hi,
how to get script tables with records
Hi. Following up my post from Feb 26…
When I used the Wizard of SSMS to script all my views, the views did not come out in the order expected, i.e. the views that were referenced by other views were not created first in the script.
I have today discovered the joys of sp_refreshview. After running sp_refreshview on all my views, my view script generated from the SSMS Wizard now has the views in the correct order.
I obtained this genius script to run sp_refreshview on all my views from here…
Cheers.
dear Friends,
How can copy one table from oldTable include Data, indexes, constraints, or triggers?
if SQLSERVER 2005 have SP to solve this problem please tell me.
thx
I’d like to know how to do the same thing programmingly in C# code.
Hi pinal .
Hear my requiremet is , in my production server just i want run one stored procedure on all databases. I have around 60 databases in that server but I don’t want to run individually and i want run at a time on all databases . Is there any script to run the SP on all databases plz let me know . If its yes then its great helpfull for me .
Thanks in Advance
Regards,
Santu
we are all used to using the ssms, but what if we did not have the interface, how would you pull the schema of all objects using t-sql?
Sir,
I Know the Process of Generating the Script file but i don’t now how to Secure the Data in the Table…..
Could you please help me regarding this……..
Thank “U”
……………………………………………………………………………………..
How to create a dymnamic script to select field for a report from a list.
1. We generate view by running scripts from application. This creates the main view for the report. The problem is that the fields for this view can change when customer adds fields to report from application.
2. So we need to create a stored procedure that will dynamic select the fields from the view (rather than creating a series of pivot tables that will have to be changed each time the customer added another field to their report).
3. The database does have a table that stores all the table names and fields but how would I need to code the stored procedure to pick fields that meet certain criteria. For instance, if the field has PL in it than this field goes into the planning bucket. But this same field will also have CY or CY1 for different cycle years.
Hi Pinal
I want to know, how to restrict the mssql server 2005 only for one IP Address.
Access denied for particular Machine Please Help me Out…
Thank U
hello,
thanx alot ,i was really need it,
but after i create the scrip , what should i do?plz help me
regards