我想在我的数据库上执行语句:
/*Disable Constraints & Triggers*/
exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'
/*Perform delete operation on all table for cleanup*/
exec sp_MSforeachtable 'SET QUOTED_IDENTIFIER ON; DELETE ?'
/*Enable Constraints & Triggers again*/
exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'
/*Reset Identity on tables with identity column*/
exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
我有我的 LINQ 数据上下文:
public static bool ClearDatabase()
{
GetContext().ExecuteCommand("");
}
MSDN 文档中不清楚的部分是......我应该将每个语句作为单独的命令运行还是制作一个很大的长字符串来执行?
我还应该保留 exec 语句吗?
另外,如果有人知道使用 LINQ 清除数据库的更好方法,请告诉我。
谢谢