The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Insert into SQL Server table with only an identity column

Let's say that I have a SQL Server table with the following definition:

CREATE TABLE MyTable([ID] [int] IDENTITY(1,1) NOT NULL)

How do I insert a row into MyTable?
sock monkey
Thursday, August 28, 2008
 
 
I don't think you can, unless you mean inserting explicit values via SET IDENTITY_INSERT ON.
Scorpio Dragon Send private email
Thursday, August 28, 2008
 
 
"insert into [MyTable] DEFAULT VALUES"
n'
Thursday, August 28, 2008
 
 
Awesome - that's exactly what I needed.
Thanks n'
sock monkey
Thursday, August 28, 2008
 
 
INSERT INTO [MyTable] VALUES(default)
will work as well.  And the default keyword will work for any column.
Ted
Thursday, August 28, 2008
 
 
You can also cheat a bit by turning off the IDENTITY functionality, while still leaving the column an IDENTITY. It just turns off the "autoincrement" and allows you to insert your own values:


http://msdn.microsoft.com/en-us/library/aa259221(SQL.80).aspx
Sgt.Sausage
Thursday, August 28, 2008
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz