all groups > sql server programming > march 2007 >
You're in the

sql server programming

group:

insert (transact-sql) into table with single identity column


insert (transact-sql) into table with single identity column pagerintas pritupimas
3/16/2007 11:25:03 PM
sql server programming:
there is a table with single identity column. how do i insert a new row?
INSERT INTO SomeTable (Id) VALUES (); - ???

Re: insert (transact-sql) into table with single identity column Mr Tea
3/16/2007 11:39:03 PM
Can I ask why you have a table with single identity column?

set identity_insert SomeTable on
insert SomeTable (id) select isnull(max(id),0)+1 from SomeTable
set identity_insert SomeTable off

Regards
Mr Tea



[quoted text, click to view]

Re: insert (transact-sql) into table with single identity column pagerintas pritupimas
3/17/2007 12:01:17 AM
thanks for quick response. i think i found a better solution:

INSERT SomeTable DEFAULT VALUES;

tried to cancel the message but for some reason it didn't work. thanks
anyway! :]


[quoted text, click to view]

Re: insert (transact-sql) into table with single identity column Mr Tea
3/17/2007 12:34:35 AM
Well, I appear to have overlooked that variant completely :)

[quoted text, click to view]

AddThis Social Bookmark Button