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.
| Author |
Topic |
|
rockstar283
Yak Posting Veteran
96 Posts |
Posted - 2011-07-05 : 18:24:56
|
| Hey Guys..Is there any way to reset the identity key to 1 without using DBCC CHECKIDENT? I have a temp table which I use twice by deleting the data from it..so after deleting it for the first time and again reloading it, the identity column gives me weird values..and I am not allowed to use DBCC CHECKIDENT coz of the company rules..so is there any other way to reset it? |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-05 : 18:28:49
|
| A truncate will reset the identity but you will need to be the owner.Why do you want to reset to 1 anyway - you can just subtract the minimum - only problem is you would eventually run out of IDs, that would be the dba's problem to do a manual reset. Maybe then they would allow you to automate it using checkident.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-05 : 18:32:56
|
| Other options are to drop and recreate the tablechange the column to not be an identity, insert into a temp table to allocate the identity then into this table not have a column at all and use row_number() to allocate a value when accessedUse a trigger to allocate the value.Use an view to subtract the min identity value and add 1 so the calculated value always starts from 1.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-07-05 : 21:42:30
|
| Since it's a temp table, and you're deleting, I'll say go with Nigel's 1st suggestion -- truncate |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-05 : 22:01:53
|
| Oops - didn't notice that.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|