2012年2月2日 星期四

Truncate資料庫裡全部資料表


USE db_name

SELECT table_name into #a01 FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
declare @name nvarchar(1000)
declare ID1 cursor for
SELECT * FROM #a01
OPEN ID1
FETCH NEXT FROM ID1 into @name

WHILE(@@FETCH_STATUS=0)
BEGIN
IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME=@name)
EXEC('truncate table [' + @name + ']')
FETCH NEXT FROM ID1
INTO @name
END



沒有留言: