Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS SQL 2008 - Create a copy of the database without the data

In MS SQL Server 2008 R2, how do I create a new database based on the schema of the old one, but without copying any of the data along with it? I am using SQL Server management studio.

like image 692
user380527 Avatar asked Oct 12 '10 06:10

user380527


People also ask

How can we create a table with same structure without data?

CREATE TABLE new_table AS (SELECT * FROM old_table WHERE 1=2); For example: CREATE TABLE suppliers AS (SELECT * FROM companies WHERE 1=2); This would create a new table called suppliers that included all columns from the companies table, but no data from the companies table.


1 Answers

Right click the Database and select Tasks -> Generate Scripts.

You can you then select all the objects you require or only certain objects.

There are some Script Options that you should look at:

  • Script USE DATABASE - You should set this to false if you are creating a new database with a different name.
  • Indexes & Triggers are not scripted as default
  • Logins & Object Level Permissions are not scripted as default
  • Generate Script for Dependent objects - this is set to false as default but you may want to change it to true to ensure that all objects are scripted.

You can either create these to a new Query Window or save them to SQL Files.

like image 162
codingbadger Avatar answered Sep 17 '22 17:09

codingbadger