BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

SQL Server
SQL 2005+

Inserting Only Table Defaults in SQL Server

Some SQL Server database tables are designed with a default value or an identity specification for every column. If a row in such a table must only use the default values, a special syntax is required to allow an INSERT to be executed.

Using Default Values

Sometimes you will use SQL Server database tables that contain columns that all have default values or are identity columns. If you wish to insert a row using only default values, you cannot provide a column list, as each column in the list must be supplied with an explicit value. In these circumstances you can use the DEFAULT VALUES clause to allow the DBMS to provide the values:

INSERT INTO MyTable DEFAULT VALUES

If the table contains columns that do not have defaults, NULLs will be inserted. If there is a column with no default that has a NOT NULL constraint, the insertion will fail.

4 December 2010