| Author |
Topic |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-04-11 : 03:04:13
|
| hello everybody, why does the identity column start with zero even though i have identity property set to start with 1 at the time of table creation....thanks in advance |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2011-04-11 : 03:18:21
|
| Try this - DBCC CHECKIDENT ("<Your table name>", RESEED, 0);Vaibhav TIf I cant go back, I want to go fast... |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-04-11 : 16:51:11
|
| It shouldn't. Can you show us the code that is producing a zero on insert? |
 |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-04-11 : 23:52:36
|
quote: Originally posted by Lamprey It shouldn't. Can you show us the code that is producing a zero on insert?
what code shall i show you?These Inserts happen from the application side...should i truncate or delete for resetting the identity? |
 |
|
|
sagitariusmzi
Posting Yak Master
113 Posts |
Posted - 2011-04-12 : 01:35:50
|
| When you created the table, you just need to specify the IDENTITY SEED to your required value.Here is a simple script to create the tableCREATE TABLE [dbo].[Table_1]( [ID] [int] IDENTITY(3,1) NOT NULL, [NAME] [varchar](50) NULL) ON [PRIMARY]The first record inserted in the table would be of ID 3 |
 |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-04-12 : 01:54:38
|
quote: Originally posted by sagitariusmzi When you created the table, you just need to specify the IDENTITY SEED to your required value.Here is a simple script to create the tableCREATE TABLE [dbo].[Table_1]( [ID] [int] IDENTITY(3,1) NOT NULL, [NAME] [varchar](50) NULL) ON [PRIMARY]The first record inserted in the table would be of ID 3yes,i do it for every table when creating...
|
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-04-12 : 11:34:56
|
quote: Originally posted by ahmeds08
quote: Originally posted by Lamprey It shouldn't. Can you show us the code that is producing a zero on insert?
what code shall i show you?These Inserts happen from the application side...should i truncate or delete for resetting the identity?
Well lets start with the Table creation script. If you have that and you can show that you are setting it up correctly with an IDENTITY column not starting at zero, then you can eliminate that as a cause of the issue and look in another place. If the table is set up correctly, then it is possible that the application is inserting its own identity values. |
 |
|
|
sushil.thakur76
Starting Member
3 Posts |
Posted - 2011-04-13 : 02:43:25
|
| CREATE TABLE dbo.xyz(ID int IDENTITY(2,1) NOT NULL,NAME varchar(10) NULL) ON [PRIMARY]susheel |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-04-13 : 10:33:22
|
| That looks correct, works as it should on my machine and I'm not aware of any settings that would cause that to not work.Assuming the table wasn't reseeded as Vaibhav showed, then I'd look to the stored procedures the application uses or the application itself. |
 |
|
|
|