Saturday, September 14, 2013

Generate Insert Statements

http://blog.sqlauthority.com/2009/07/29/sql-server-2008-copy-database-with-data-generate-t-sql-for-inserting-data-from-one-table-to-another-table/

1.DATABASE NAME: Right Click
2.TASKS: GENERATE SCRIPTS
3.Under Table/View Options: Set SCRIPT DATA = TRUE   --It is on SQL 2008



Right click on the database name in the object explorer.
Select Tasks
Select Generate Scripts...
Then select source database
In the Chose Script Options database screen,  scroll down for Table/View Options
Set Script Data option to True
Then in the following screen select Tables
Select tables you wish to script
Select output type



The really low cost solution though is to use this stored procedure:
http://vyaskn.tripod.com/code.htm#inserts


http://noprobs.wordpress.com/2008/07/20/generating-insert-statements-for-a-table-in-sql-server/



http://agilebi.com/mcole/2011/04/04/how-to-generate-insert-scripts-for-existing-data/


SELECT 'INSERT INTO dbo.MyTable (Eid,First_Name) VALUES (' + Eid + ',' + First_Name + ')' AS InsertStatement from [DB_NAME].[dbo].[Table_Name]

SELECT 'INSERT INTO dbo.MyTable (Eid,First_Name)
  VALUES (' + CAST(Eid as int) + ',' + First_Name + ')' AS InsertStatement from Test

SELECT 'INSERT INTO dbo.MyTable (id,Name)
  VALUES ('+ CAST(id as varchar(20)) + ',' + Name + ')' AS InsertStatement from Test;

No comments:

Post a Comment