在线等待,马上给分!关于alter的简单问题! 急!

liyin_first 2004-04-28 10:54:02
A,B表, A的主键PA与B的一个列CB有关系,如果用alter sql语句删除这个关系?
谢谢!
...全文
70 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2004-04-28
  • 打赏
  • 举报
回复
1楼的那个constraint误写成constraing了.
internetcsdn 2004-04-28
  • 打赏
  • 举报
回复
zjcxc 元老 2004-04-28
  • 打赏
  • 举报
回复
--如果你不知道约束名,可以这样处理
declare tb cursor local for
select sql='alter table ['+c.name+'] drop constraint ['+b.name+']'
from sysforeignkeys a
join sysobjects b on b.id=a.constid
join sysobjects c on c.id=a.fkeyid
join syscolumns d on c.id=d.id and a.fkey=d.colid
join sysobjects e on e.id=a.rkeyid
join syscolumns f on e.id=f.id and a.rkey=f.colid
where b.name='B' and d.name='A'
and c.name='PA' and e.name='CB'
group by a.name

declare @s varchar(8000)
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
progress99 2004-04-28
  • 打赏
  • 举报
回复

constraing 寫錯了吧
alter table B drop CONSTRAINT 约束名
zjcxc 元老 2004-04-28
  • 打赏
  • 举报
回复
alter table b drop constraing 约束名

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧