Sathya Sambath

Sathya Sambath

  • NA
  • 284
  • 117.5k

how to write the delete and reseed for stored procedure?

May 3 2018 5:50 AM
hi,
 
I have one database for eg 300 table ,i have delete specify the  200 table data only and then reseed identity the delete  table .
 
but error withshown .
  1. DECLARE @DeleteTableStatement nvarchar(max)  
  2. DECLARE C2 CURSOR READ_ONLY  
  3. FOR  
  4. SELECT 'Delete From [dbo].[' + TABLE_NAME + ']' from INFORMATION_SCHEMA.TABLES   
  5. WHERE TABLE_SCHEMA = 'dbo' and TABLE_NAME NOT IN ('xxx',  
  6. 'aaa',  
  7. 'bbb',  
  8. etc  
  9. -- Change your schema appropriately.  
  10. OPEN C2  
  11. FETCH NEXT FROM C2 INTO @DeleteTableStatement  
  12. WHILE @@FETCH_STATUS = 0  
  13. BEGIN  
  14.   
  15. PRINT 'Executing ' + @DeleteTableStatement  
  16. execute sp_executesql @DeleteTableStatement  
  17. DBCC CHECKIDENT (@DeleteTableStatement, RESEED,1);  
  18. FETCH NEXT FROM C2 INTO @DeleteTableStatement  
  19.   
  20. END  
  21. CLOSE C2  
  22. DEALLOCATE C2

Answers (3)