使用C#从所有表中删除所有记录 [英] Delete All Records From All Table Using C#

查看:107
本文介绍了使用C#从所有表中删除所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过实用程序删除SQL或Access数据库中所有表中的所有记录

How to delete all records from all tables in SQL or Access database by utility

推荐答案

在sql server中运行此脚本



run this script in sql server

declare @tblname int 
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
	EXECUTE ('truncate table '+ @tblname) 
	fetch next from tbl_cursor into @tblname
end 
close tbl_cursor
deallocate tbl_cursor 









delete-all-rows-from-all-tables / [ ^ ]


查询删除所有记录来自所有表格



Query for Delete All records from All Tables

Exec sp_MSforeachtable 'Delete from ?'


检查以下链接

http://stackoverflow.com/questions/685112/how-to-delete-data -in-all-ms-access-tables-at-once [ ^ ]


这篇关于使用C#从所有表中删除所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆