Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Generate Insert script Expand / Collapse
Author
Message
Posted Wednesday, August 6, 2008 2:37 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, September 16, 2008 3:11 AM
Points: 5, Visits: 13
Hi...

I need a script which can generate insert statements for all the records in a table.

for eg: if a table abc has 2 records, then on executing this script, it should generate 2 insert statements with column names and values.

thx
raj
Post #547323
Posted Wednesday, August 6, 2008 2:42 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, June 23, 2014 6:03 AM
Points: 920, Visits: 702
There may be the possibilities that table either contains Primary / Identity Field or may not contains any ke, so in that case how do you insert the record ?

Abhijit - http://abhijitmore.wordpress.com
Post #547325
Posted Wednesday, August 6, 2008 2:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, September 16, 2008 3:11 AM
Points: 5, Visits: 13
That doesnot matter... Ultimately , i need insert statement for each record in the table.
Post #547334
Posted Wednesday, August 6, 2008 8:23 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, September 11, 2014 7:58 AM
Points: 1,298, Visits: 769
I'm lazy, I use ApexSQL Edit.... =)
Post #547553
Posted Wednesday, August 6, 2008 8:34 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:34 PM
Points: 37,098, Visits: 31,648
toprprasad (8/6/2008)
Hi...

I need a script which can generate insert statements for all the records in a table.

for eg: if a table abc has 2 records, then on executing this script, it should generate 2 insert statements with column names and values.

thx
raj


See the method in the link in my signature below.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #547563
Posted Friday, May 14, 2010 2:41 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 11, 2014 6:08 AM
Points: 115, Visits: 313
In case you miss is, article Generating Insert Statements is republished today.

Also, there is my own article, Scripting INSERTs, which is intended to do address a slight different issue - where you want to script individual bits of tables, perhaps subject to conditions on the records - and also you can edit the script more easily if you aren't just looking for a straight copy. It doesn't support some of the more exotic datatypes though.

I think both are subject to the provisos about IDENTITY fields etc, although I guess if you can just turn IDENTITY_INSERT on for the table in that particular case.

Tony
Post #921832
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse