How to copy everything except data from one database to another?

2.4k views Asked by At

In T-SQL (Microsoft SQL 2008), how can I make a new database which will have the same schemas, tables, table columns, indexes, constraints, and foreign keys, but will not contain any data from the original database?

Note: making a full copy, then removing all data is not a solution in my case, since the database is quite big, and such full copy will spend too much time.

3

There are 3 answers

3
SQLMenace On BEST ANSWER
1
StuartLC On

In SQL Management Studio, right click on the database and select "Script database as" http://msdn.microsoft.com/en-us/library/ms178078.aspx

You can then use the script to create an empty one. Edit : OP did say 2008

0
Matt Greer On

I use liquibase for this purpose. Just point liquibase to a different server and it will use your changelog to bring the second database up to date, schema wise. It has the added benefit that the changelog file gets stored in source control and so I can have tagged versions of it, allowing me to restore a database to what a specific version of my app is expecting.