1

我想从 SQL Server 2005 数据库中删除所有行。

任何人都可以定义一个过程来轻松地从数据库中删除所有行吗?

4

3 回答 3

1

在这种情况下,这将起作用:

EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'DELETE FROM ?'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO

感谢你所做的一切。

于 2012-05-31T10:43:16.157 回答
1

使用这个命令:

    --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 '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'
于 2017-02-20T21:03:38.777 回答
0

也许这会有所帮助:

http://vadivel.blogspot.se/2006/07/easyest-fastest-way-to-delete-all.html

于 2012-05-31T09:59:21.893 回答