SQL Server: Copying a Database, including Constraints, Keys, Indexes...
In SQL Server, if you wish to copy the structure of an entire database, including the Constraints, Keys, Indexes, etc., don't use the Import option, as it does not include the constraints, keys, indexes, etc. Instead, within SQL Server Management Studio, right click a database, select Tasks, then "Generate Scripts."
Now you may go through the wizard to create a script to copy your entire database. On the "Select Database" page, check the box at the bottom to "Script all objects in the selected database."
On the "Choose Script Options" page, review the True/False settings. Scroll down to the "Table/View Options." If you wish to have a blank set of tables, leave the "Script Data" option False, otherwise, change it to True.
If you wish to have the script create your database, set "Script Database Create" to True, then when the script is created, change the name of the database to the desired new database. Otherwise, create your new database manually, then change the first line of the created script to USE [databasename].
On the Output Option page, I select to "Script to New Query Window," but you could easily save it to a file in order to use the file on another server.
Make sure to change the database name you are creating to your new database, whether you are creating a new database or not. Right click the script window, and select to Execute the script.
Although the server roles will be in the new database, the db_datareader and db_datawriter permissions will not be there, so be sure to add these to the anonymous IISUser role used by your websites.
For further scripting information, please see my previous post on How to Deploy a local MDF Database to a Remote SQL Server Database.
May your dreams be in ASP.NET!
Nannette