清数据脚本
假设在数据库中,存在A,B,C三张表,表与表之间通过外键互相关联。如果想要清楚这3张表的数据需要先清楚约束关系,再清空表数据。
在实际应用中需要注意,
有些表是基础数据表,不能清除。

脚本:
1 --USE master 2 --BACKUP DATABASE [YourDB] 3 -- TO DISK = 'H:\YourDB_datetime.bak' 4 --GO 5 6 USE [YourDB] 7 GO 8 9 ALTER TABLE [YourDB].[Table A] NOCHECK constraint all; 10 ALTER TABLE [YourDB].[Table B] NOCHECK constraint all; 11 ALTER TABLE [YourDB].[Table C] NOCHECK constraint all; 12 GO 13 14 DELETE [YourDB].[Table A]; 15 DELETE [YourDB].[Table B]; 16 DELETE [YourDB].[Table C]; 17 GO 18 19 ALTER TABLE [YourDB].[Table A] CHECK constraint all; 20 ALTER TABLE [YourDB].[Table B] CHECK constraint all; 21 ALTER TABLE [YourDB].[Table C] CHECK constraint all; 22 GO
浙公网安备 33010602011771号