Quantcast
Channel: SQL Server Teacher
Viewing all articles
Browse latest Browse all 26

How to insert into a table which contains only one IDENTITY column

$
0
0

Hi,

Question:

I have a table with only one column. The column is of smallint datatype and is specified as identity. How to insert into that table?

Answer:

Let’s discuss this with a example.

Create a table with only one column, with identity.

CREATETABLE TEST(LogNo smallintidentity)

If you try to insert into the table using the normal insert command, you’ll get an error.

INSERTINTO TEST(LogNo)VALUES ()

Msg 102, Level 15, State 1, Line 1

Incorrect syntax near ')'.

 
Below is the insert command to achieve this

INSERTINTO TEST DEFAULTVALUES

Thanks,
Selvaraj M.
Follow me at @MSSQLDB


Viewing all articles
Browse latest Browse all 26

Trending Articles