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 |
|
anandc
Starting Member
20 Posts |
Posted - 2006-05-09 : 08:52:42
|
HiI want to Reset the identity column of a Table Variable in my SP. Whenever I am iterating through a loop, for every iteration I am creating a table variable which contains an identity column. I want to reset this column and it should start with value "1" for each iteration.Below is a sample piece of code...WHILE i < 5BEGIN DECLARE @mytbl AS TABLE(id INT IDENTITY(1,1), MyName VARCHAR(50)) -- perform some operations on table variable SET i = i + 1END Initially the same code was working, and we found out this problem has suddenly started appearing.Any help in this regard would be appreciated.....ThanksAnand- Anand |
|
|
sshelper
Posting Yak Master
216 Posts |
Posted - 2006-05-09 : 09:48:16
|
| Try truncating the table even after it is declare:WHILE i < 5BEGIN DECLARE @mytbl AS TABLE(id INT IDENTITY(1,1), MyName VARCHAR(50)) TRUNCATE TABLE @mytbl -- perform some operations on table variable SET i = i + 1ENDSQL Server Helperhttp://www.sql-server-helper.com |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-09 : 09:56:32
|
| >>TRUNCATE TABLE @mytblNot supportedMadhivananFailing to plan is Planning to fail |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-05-09 : 11:47:10
|
| Hi all,Anand - I don't think you can 'reseed' a table variable, sadly. You might have to use a temporary table instead. The 'truncate' syntax sshelper gave you should then work.Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|