Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert when using IDENTITY(1,1)

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2007-06-11 : 09:44:30

If I have my table setup like so...

CREATE TABLE Customer
(SID integer IDENTITY(1,1) PRIMARY KEY,
Last_Name varchar(30),
First_Name varchar(30));

How would I do an insert statement so that it auto increments and creates a unique number?

I keep getting errors.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-11 : 09:49:32
By not providing value for Identity column.

Insert into Customer(Last_Name, First_Name)
values('xx', 'yy')


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-11 : 09:56:21
<<
I keep getting errors.
>>

What is the error?

As specified, you should omit it when adding data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-06-11 : 13:13:29
Post the insert statement.....

I never liked making the identity column a PK in the first place



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

crugerenator
Posting Yak Master

126 Posts

Posted - 2007-06-11 : 16:14:21
worked great. Thanks
Go to Top of Page
   

- Advertisement -