一个简单的SQL语句

2024-11-18 14:52:19
推荐回答(4个)
回答(1):

spj数据表有指向S表的外键,需要先删除spj中的数据才能删除S表数据

回答(2):

在s表上建个触发器

create trigger trs
on s for delete
as
delete spj
from spj s,deleted d
where s.sno=d.sno

然后执行delete s where sno='s2'就可以了

回答(3):

s2 属于字段SNO吗?
DELETE SPJ WHERE SPI.SNO=S2
GO
DELETE S WEHERE S.SNO=S2
如果不属于假设属于字段NAME:
DELETE SPJ WHERE SPI.SNO=(SELECT SNO FROM S WHERE SNAME = S2)
GO
DELETE S WEHERE S.SNAME=S2

.GO前后的每个语句单独执行一次.如果失败就执行后面的再去执行前面的.

回答(4):

“s2的记录”是什么意思?