Monday, February 1, 2010

Insert value in identity column when identity column is only column in table

I came across a question that how to insert value in identity column when identity column is only column in the table. And to set identity insert on is not allowed. It is interesting scenario. So answer is to use DEFAULT VALUES. Consider following code for demo that how to insert value in identity column when identity column is only column in table.

USE AdventureWorks
GO

CREATE TABLE #TestInsert(onlyColum TINYINT IDENTITY (1,1))
GO

INSERT INTO #TestInsert DEFAULT VALUES
GO

SELECT * FROM #TestInsert
GO


And you would get inserted value from this temporary table.

0 comments:

Post a Comment

Express your views about this post