我是MsSql的新手,我不确定是否可以这样做,但我想我之前想问一下当前的流程.
我需要创建一个循环遍历数据库中所有表的脚本,并删除其中CorporationId ="xxx"的行.有几个表没有这个列,但在我的~50个表中,只有1个或2个表没有.
我可以单独删除表中的记录:
USE MyDatabase
DECLARE @CorporationId UniqueIdentifier
DECLARE @TokenId UniqueIdentifier
DECLARE @CompanyCode nChar(3)
SET @CorporationId = '52D3AEFE-8EBD-4669-8096-4596FE83BB36'
print 'Starting Web.GasOrder'
DELETE FROM Web.GasOrder
WHERE CorporationId = @CorporationId
print 'Starting Web.GasOrderNumber'
DELETE FROM Web.GasOrderNumber
WHERE CorporationId = @CorporationId
etc..
Run Code Online (Sandbox Code Playgroud)
但是为每张桌子制作一张桌子变得乏味.
当然,有些表与它们有关系.
有没有一种简单的方法可以做到这一点,还是我需要手动为每个表做?
UPDATE
我尝试过的大多数选项遇到了关系问题并给我一个错误.