Insert into Table with no values using the identity column

Hello Everyone!

SQL Question: Can you insert a record into a table that has an identity column with no values (on condition that the other fields in the table allow null or have default values).

Such as: Insert into Table () values () //Auto increment record with no other values

Possible Let me know if you need additional information.




Answer this question

Insert into Table with no values using the identity column

  • Jose Luis Bellon

    Yes:
     
    INSERT Table
    DEFAULT VALUES

    --
    Adam Machanic
    Pro SQL Server 2005, available now
    http://www..apress.com/book/bookDisplay.html bID=457
    --
     
     

    Hello Everyone!

    SQL Question: Can you insert a record into a table that has an identity column with no values (on condition that the other fields in the table allow null or have default values).

    Such as: Insert into Table () values () //Auto increment record with no other values

    Possible Let me know if you need additional information.


  • Nilesh Trivedi

    Also, if you want to explicitly define the identity value, use

    SET IDENTITY INSERT tablename ON

    Then do the insert, then turn it off again.


  • Hallo2ooo

    Well that was fast. Thanks a lot. For the life of me I couldn't figure out the syntax.

    Again, huge thanks.



  • domukajoor

    Yes, you can do below:
    insert into table default values
    This will populate the table with only one identity column. If the table has multiple columns then NULLable will be set to NULL and columns with default will have the default value populated.


  • Insert into Table with no values using the identity column