如何创建外键和删除外键约束

我心依旧2014 2010-08-27 03:04:16
如何创建外键和删除外键约束
先提供个简表
1、CREATE TABLE author (  ID bigint NOT NULL ,  AuthorName char(10) NULL ,  address char(480) NULL , introduction ntext NULL   )  
2、cREATE TABLE myBBS ( ID bigint IDENTITY (1, 1) NOT NULL , authorId bigint NOT NULL , Title char (40) NULL , Date_of_Created datetime NULL , Abstract char(480) NULL , Content ntext NULL )



谢谢!!!
...全文
223 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
哥子谭 2010-08-28
  • 打赏
  • 举报
回复

--外键
Alter Table MyBBS Add Constraint FK_MyBBS_AuthorID Foreign Key(AuthorID) References Author(ID)
--删除约束
Alter Table MyBBS Drop Constraint FK_MyBBS_AuthorID
csuxp2008 2010-08-27
  • 打赏
  • 举报
回复
alter table author add constraint pk_1 primary key(id)
alter table myBBS add constraint fk_1 foreign key(authorId) references author(id)
alter table myBBS drop constraint fk_1

11,848

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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