Generate Insert script

  • 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

  • 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

  • That doesnot matter... Ultimately , i need insert statement for each record in the table.

  • I'm lazy, I use ApexSQL Edit.... =)

  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • In case you miss is, article Generating Insert Statements[/url] is republished today.

    Also, there is my own article, Scripting INSERTs[/url], 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

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply