How to insert in a table with only an IDENTITY column?
From the documentation:
DEFAULT VALUES
Forces the new row to contain the default values defined for each column.
So:
INSERT dbo.TABLE DEFAULT VALUES;
In addition:
- always use the schema prefix
- always terminate statements with semi-colons
Another way would be to use IDENTITY_INSERT
. That way you can manually define which values you want to put in. Like so:
SET IDENTITY_INSERT TABLE ON ;
INSERT INTO TABLE (ID) VALUES (1), (2) ;
SET IDENTITY_INSERT TABLE OFF ;