Posts Tagged generate script for insert script for tables
How to generate the data script for SQL server 2008 database tables
Right click on the database where your table exists > Tasks > Generate Scripts
On the below screen, click “Advanced” and then select “Data only” option from the “Types of data to script”.
By default “Schema only” option is selected. You can also select “Schema and data” option for both creating table and also for the insert scripts.
IMPORTANT NOTES –
A) If your table has large amount of data (like mine in this case having 5000K records, Use the “Save to file” option to save the script and It will generate the script file containing all the insert queries just fine. If you use “copy to clipboad” or a “New Query Window option”, the generation will fail with Out of Memory Exception.
B) ALWAYS enclose the insert scripts in transaction with TRY CATCH block before running them. You don’t want partial inserts on your table – do you?
How to generate the data script for SQL server 2005 database tables
Good thing is you can generate the data script of SQL server 2005 database objects from SQL server 2008 management studio. This is how you do it.
a) In the SQL Management studio, right click on the database and select “Task > Generate Scripts ”. A wizard will be launched.
b) Select the database you want to generate the script from.
c) In the “Choose Script option” step of the Wizard, select the “Script data” as true:-
d) Proceed on to generate the script and It will generate the data script as well.