sql检查数据是否被引用

select object_name(ref.fkeyid), col_name(ref.fkeyid, fk.fkey),
object_name(ref.rkeyid), col_name(ref.rkeyid, fk.rkey)
from sysreferences ref
join sysobjects obj on ref.constid=obj.id
join sysforeignkeys fk on obj.id=fk.constid
where object_name(ref.rkeyid)='表名'
and col_name(ref.rkeyid, fk.rkey)='表主键'
select * from 表名 where 表主键=cast(id(值) as varchar(10))

posted @ 2021-12-15 11:20  丶Ronnie  阅读(266)  评论(0)    收藏  举报