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
 AUTO-INCREMENT issue

Author  Topic 

Rigoberto
Starting Member

7 Posts

Posted - 2011-08-17 : 14:20:19
Hi there,

I have written a sql statement to Insert record to a table, the table has the RECORD_id FIELD like Key, also this field was created with AUTO-INCREMENT atribute, well my problem is when I am inserting data to that table the AUTO-INCREMENT doesn't work and a erreor message is showing up,"Duplicated Records", just I take the key out and after that ran my sql statemen, this time the table was populated but the the Field with AUTO-INCREMENT is equal to Zero, why the AUTO-INCREMENT doesn't work?
anyboby can help me with this issue
Rigo

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-08-17 : 14:26:52
Can you give us more detail? This link might help:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Here is a quick example to show how to insert into a table with an identity column:
DECLARE @Foo TABLE (ID INT IDENTITY(1,1), Val INT)

INSERT @Foo (Val)
VALUES
(1),
(4),
(6)

SELECT *
FROM @Foo
Go to Top of Page
   

- Advertisement -