--- crete by talantlee --- Use for delete all Table Results Except 5 results --- 4/12/05 ---- delete_dbtable 'a'
Create Procedure delete_dbtable @db nvarchar (50)
ASEXEC ('use' @ db) Declare @s nvarchar (1000) set @S = '' select @ s = @ s name ',' from sysobjects where xtype = 'u'
While (Len (@S)> 0) Begin
Declare @tb nvarchar (50) set @ TB = left (@ s, charindex (', @ s) -1)
Exec ('Declare @a int declare @B int declare @ss nvarchar (50) SELECT @ a = count (*) from' @ TB 'set @ b = @ a-5 if (@B> 0) beginset rowcount @ B
Delete from ' @ TB ' end ') set @ s = stuff (@ s, 1, charindex (', ', @ s),' ') endGO