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

Blog at WordPress.com.

Up ↑