且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL:按特定顺序从自引用表中删除数据

更新时间:2023-02-02 23:03:00

尝试

ALTER TABLE [group] NOCHECK CONSTRAINT ALL
go
DELETE FROM [group] WHERE [groupId] <> '00000000-0000-0000-0000-000000000000'
go
ALTER TABLE [group] CHECK CONSTRAINT ALL
go

如果桌子很大,这可能是一个不错的选择.

If the table is large, this might be a good option.

select * into #temptable from [group] WHERE [groupId] = '00000000-0000-0000-0000-000000000000'
go
truncate table [group]
go
select * into [group] from #temptable
go
drop table #temptable
go