Technical Article

Delete All

,

Delete all rows from all user tables. Create stored procedure and execute the procedure to get rid of all rows from all tables. This will not drop your tables. Be very careful what you wish for!

CREATE PROCEDURE [dbo].[deletefromall] AS
begin
DECLARE @VarTableName varchar(100)

DECLARE alltables_cursor CURSOR FOR
select name from sysobjects where xtype = 'U'

OPEN alltables_cursor

Fetch Next from alltables_cursor into @VarTableName

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN

EXEC('delete FROM ' + @VarTableName) ;
Fetch Next from alltables_cursor into @VarTableName
END


CLOSE alltables_cursor
DEALLOCATE alltables_cursor

end
GO

Rate

2 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

2 (1)

You rated this post out of 5. Change rating