简体   繁体   中英

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

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM