G
Guest
I have a stored procedure that deletes the contents of my table
[tblTableName]. In this table I have a variable named [sysDoNotDelete] that
if set to TRUE then the record is not to be deleted. The code below deletes
all records, except thouse records indicated. The code below is not 100%
correct because I cannot create the stored procedure as I need it. The intent
is to show what I'm trying to accomplish.
In this example, records 1 to 4 are marked as [sysDoNotDelete] = TRUE, and
thus will not be deleted. Once the other records have been deleted I want to
reseed the table, so the next RecordID will be 5.
Here is my code (will not compile because its not valid, but I don't
understand what's wrong).
DECLARE @intTableCount int
DELETE tblTableName WHERE [sysDoNotDelete] = FALSE
SET @intTableCount = SELECT COUNT(*)
FROM tblTableName.RecordID;
DBCC CHECKIDENT ('tblTableName',RESEED, @intTableCount);
I'm assuming the SET statement is what's wrong, because if I manually set it
to "SET @intTableCount = 5" the procedure runs fine. But, I need the value of
@intTableCount to equal the number of records in the table.
Also, I want to verify what the maximum RecordID already is, to make sure
its not greater than the number of records in the table. For example, if the
table had 100 records and 30 were deleted, but the maximum RecordID = 81,
thus the count of the table would result in a reseed that is too low.
Somehow, I need to be able to evaluate for this condition so that I reseed
the table properly.
Can anyone help me with getting this Stored Procedure to achive the results
I'm looking for.
Thanksin advance.
[tblTableName]. In this table I have a variable named [sysDoNotDelete] that
if set to TRUE then the record is not to be deleted. The code below deletes
all records, except thouse records indicated. The code below is not 100%
correct because I cannot create the stored procedure as I need it. The intent
is to show what I'm trying to accomplish.
In this example, records 1 to 4 are marked as [sysDoNotDelete] = TRUE, and
thus will not be deleted. Once the other records have been deleted I want to
reseed the table, so the next RecordID will be 5.
Here is my code (will not compile because its not valid, but I don't
understand what's wrong).
DECLARE @intTableCount int
DELETE tblTableName WHERE [sysDoNotDelete] = FALSE
SET @intTableCount = SELECT COUNT(*)
FROM tblTableName.RecordID;
DBCC CHECKIDENT ('tblTableName',RESEED, @intTableCount);
I'm assuming the SET statement is what's wrong, because if I manually set it
to "SET @intTableCount = 5" the procedure runs fine. But, I need the value of
@intTableCount to equal the number of records in the table.
Also, I want to verify what the maximum RecordID already is, to make sure
its not greater than the number of records in the table. For example, if the
table had 100 records and 30 were deleted, but the maximum RecordID = 81,
thus the count of the table would result in a reseed that is too low.
Somehow, I need to be able to evaluate for this condition so that I reseed
the table properly.
Can anyone help me with getting this Stored Procedure to achive the results
I'm looking for.
Thanksin advance.