Thursday, March 29, 2012

Creation scripts from a database

I would like to know the sql command to generate all the scripts of a database so that I can replicate the same database for testing purpose. For instance, I need those scripts to help me re-create the database itself and indexes, triggers, and stored procedures of it if possible.

I remember there was a command to display all these scripts in Sql but I forgot it. If someone knows it, please help. Thanks in advance.

blumonde

Maybe you can use Enterprise Manager, select the database in EM, right click it, choose 'All tasks'->'Generate Script', click 'Show All'. Then you can choose objects to be scripted, and save the script to file system.|||

If you are in SQL Server 2000 in Query Analyzer in the Object browser with the database closed in Enterprise Manager right click on the database and click on create and you will get the create database statement. If you need the create statement for any object in the database make sure the database is open in Enterprise Manager and do the same per object and you will generate the create statement of all the objects.

In SQL Server 2005 do the same in Management Studio to generate the create statement.

Another way to move database is to use the Backup and Restore wizard and use the restore from device option to recreate the database. If your test SQL Server in not on the network remember to put the .BAK file in the Backup subfolder in Microsoft SQL Server folder in Programs. Hope this helps.

|||

Hi Iori_Jay and Caddre,

Thanks for your help. I have the scripts now. Thanks again. I appreciate it a lot.

blumonde

No comments:

Post a Comment