Monday, June 30, 2014

Truncate all table from a database in sql server

declare @tblname VARCHAR(255)
declare tbl_cursor cursor for
select name from sys.tables
open tbl_cursor
fetch next from tbl_cursor into @tblname
while @@FETCH_STATUS = 0
begin
     print  @tblname
    --EXECUTE ('truncate table '+ @tblname)
    fetch next from tbl_cursor into @tblname
end
close tbl_cursor
deallocate tbl_cursor

No comments:

Post a Comment

Integrating OpenAI / ChatGPT in ASP.NET Core Web API

 This guide shows how to build a production-ready AI API using ASP.NET Core with: Clean Architecture, streaming responses, database storage,...