thanks, it was quite helpful
though, i could not delete some of the table because of a certain foreign key constraint. but if i use delete though it works. why is it so?
Main Topics
Browse All Topicshi experts,
I wanted to make a stored procedure to clear contents of a table and reseed identity. something like
----------------
DELETE FROM myTable
DBCC CHECKIDENT(myTable,RESEED,
-----------------
But i wanted it to be generic (if thats the right term) wherein it accepts string table name for parameter and i didnt know how to put these things together. how do i do this?
I'm really new with SQL 2000, hope i could get some help on this.
thanks in advance
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
this is because truncate doesn't raise any triggers and constraints check, which is needed to ensure data integrity. the foreign key constraint to this table "disables" the truncate command for this purpose.
create procedure reset_table ( @tablename sysname )
as
declare @sql varchar(600)
set @sql = 'DELETE FROM [' + @tablename +'] '
exec (@sql)
set @sql = 'DBCC CHECKIDENT( [' + @tablename +'], RESEED, 1) '
exec (@sql)
GO
Business Accounts
Answer for Membership
by: angelIIIPosted on 2005-11-16 at 12:04:09ID: 15306208
first, rather than using DELETE FROM, use TRUNCATE TABLE
you might try this:
create procedure reset_table ( @tablename sysname )
as
declare @sql varchar(600)
set @sql = 'TRUNCATE TABLE [' + @tablename +'] '
exec (@sql)
set @sql = 'DBCC CHECKIDENT( [' + @tablename +'], RESEED, 1) '
exec (@sql)
GO
note that I would use 1 as reseed value, unless you want 0 to be the value for the first row.