views:

34

answers:

5

I have a table having a single auto Auto Incremented column. How Can i insert the value. Using

Insert into table or some other way

Thanks Waiting for your replay..

+1  A: 
CREATE TABLE products
(
   Id int IDENTITY(1,1) PRIMARY KEY
)
GO    


SET IDENTITY INSERT ON

INSERT INTO MyTable (Id) VALUES (2)

SET IDENTITY INSERT OFF
Mitch Wheat
A: 

Without knowing your table schema it's not going to be possible to give you a good answer, but you could do something like:

insert into tableName (column2, column3, column4) values (value2, value3, value4)

Since you're using an autoincrement column you don't need to specify it when inserting data.

Michael Todd
A: 
INSERT INTO tableName (columnName1, ...) VALUES (value1, ...);
Delan Azabani
+3  A: 

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=90116

provided some insight here.

INSERT INTO TableName DEFAULT VALUES
Gabriel
A: 

you can either

insert into tableName ()

either "insert into tableName VALUES (NULL)" where NULL is the first and only column value of the row (the syntax is

insert into tableName(column2, column3) VALUES (value2, value3)

as provided by Michael. )

Luka Ramishvili