:::: MENU ::::

Do you know T-SQL insert statement?

dbDigger, Identity Columns, T-SQL Interview Questions

Do you know T-SQL insert statement?

Question: Consider the following table.

 
CREATE TABLE Test  
 (  
 Col1 int IDENTITY(1,1)  
 )  

Write the INSERT statement to populate the above table with sample values. Note: You are not allowed to use ‘set identity_insert’

Answer: INSERT dbo.Test DEFAULT VALUES

Explanation: The table contains only one column and it is an IDENTITY column. You cannot explicitly insert values to an IDENTITY column. Either you have to SET IDENTITY_INSERT ON before inserting the value or use the default values clause. DEFAULT VALUE is not allowed.

Note: The question of day is taken from SqlServerCentral.com. I want to compile selected QOD to share.

Consult us to explore the Databases. Contact us