giovedì 5 settembre 2013

How To Delete All Tables


  How To Delete All Tables

DECLARE
@sql VARCHAR(4000),
@int_counter INT,
@int_max INT

DECLARE @tables TABLE(
ident INT IDENTITY(1,1) PRIMARY KEY,
table VARCHAR(256))

INSERT @tables(table)
SELECT name FROM sysobjects WHERE xtype = 'U'

SELECT
@int_counter = 1,
@int_max = (SELECT MAX(ident) FROM @tables))

WHILE @int_counter <= @int_max
BEGIN

SELECT @sql = 'DELETE ' + table
FROM @tables WHERE ident = @int_counter

SELECT @int_counter = @int_counter + 1
END

REF :http://www.dbforums.com/microsoft-sql-server/992098-how-delete-all-tables.html

Nessun commento: