How to insert in this table

  • I have a table.

    Create table emp (id int IDENTITY(1,1))

    How to write INSERT statement for this table?

    Thanks in advance.

  • insert into emp default values

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • [Code]

    set identity_insert emp on

    insert into emp(id)

    values(1)

    set identity_insert emp off

    [/Code]

  • arup_kc (5/26/2009)


    I have a table.

    Create table emp (id int IDENTITY(1,1))

    How to write INSERT statement for this table?

    Thanks in advance.

    May I ask why you would want such a table?

    [font="Verdana"]Markus Bohse[/font]

  • Hi Adi,

    Your query workls perfectly.

    Hi mayank,

    This is not working. It only insetts 1 for every row but not incrementing.

    Hi markus,

    I should admit that still I have not faced any real time application of this query. This is simply my inquisitiveness. Thanks I have got the answer from Adi.

    Thanks to all.

  • arup_kc (5/26/2009)


    Hi markus,

    I should admit that still I have not faced any real time application of this query. This is simply my inquisitiveness.

    In case you ever need such a table, there are probably easier ways to fill it. Have a look at Jeff's article about implenting and using tally tables.

    http://www.sqlservercentral.com/articles/T-SQL/62867/

    [font="Verdana"]Markus Bohse[/font]

  • Hi Marcus,

    Again thanks for this beautiful link.

  • arup_kc (5/26/2009)


    Hi Adi,

    Your query workls perfectly.

    Hi mayank,

    This is not working. It only insetts 1 for every row but not incrementing.

    Hi markus,

    I should admit that still I have not faced any real time application of this query. This is simply my inquisitiveness. Thanks I have got the answer from Adi.

    Thanks to all.

    Hi Arup,

    You do have to change value for your insert(1 or 2 or 3 any value u want to insert) and it doesn't autoincrements. That method is used to insert rows in an identity table where u have a break in ur identity key sequence due to deletion of rows(1,2,3,4,6(like 5 missing here)) in your table. So if someone wants to insert a particular number, he can do that using that.

Viewing 8 posts - 1 through 7 (of 7 total)

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