Insert into table with default values only


In this article you will find how to insert a row without any specified values in SQL Server table, if the columns have default values.

I recently had this issue. I had a table with only two columns one of which was auto-increment and the other had a GETDATE() default value. I needed to insert a record programmatically with default value. I didn’t knew how to insert a record without specifying any values. First I tried to insert it with GETDATE(), but since that column had it by default I wanted more elegant solution.

After some searching I found the best way to do it is this:

 INSERT INTO Your_Table DEFAULT VALUES

I hope it helps!

Advertisements
This entry was posted in SQL Server 2008, SQL Server 2012, SQL Server 2014, SQL Server Denali and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s