读书人

一个表的外键的建立出现的有关问题

发布时间: 2012-01-13 22:43:30 作者: rapoo

一个表的外键的建立出现的问题
create table MyArticle
(
MA_ID int identity(1,1),
MA_Title varchar(300),
MA_Type tinyint,
MA_From varchar(100),
MA_Content text,
MA_PostTime smalldatetime default getDate(),
MA_Hits int default 0,
MA_Author varchar(40),
constraint PK_MA primary key nonclustered (MA_ID)
)
go
Create clustered index CI_ID_Title_PostTime on MyArticle(MA_ID,MA_Title,MA_PostTime)
go
--drop table MyFeedBack
create table MyFeedBack
(
MF_ID int identity(1,1) primary key nonclustered,
MF_TOID int,
MF_Title varchar(300),
MF_Content varchar(2000),
MF_PostTime smalldatetime default getDate(),
MF_Author varchar(40)
)
go
alter table MyFeedBack add constraint FK_F_A foreign key(MF_TOID) references MyArticle(MA_ID) on delete cascade

以上代码执行成功!!可是加上我想在给另外的一个表加一个外键的时候就出问题了

代码如下:

create table ArticleType
(
AT_ID tinyint primary key,
AT_Name varchar(100),
AT_Numbers int default 0
)
go
alter table MyArticle add constraint FK_A_T foreign key(MA_Type) references ArticleType(AT_ID) on delete no action

发生以下错误:

ALTER TABLE 语句与 COLUMN FOREIGN KEY 约束 'FK_A_T ' 冲突。该冲突发生于数据库 'myNet ',表 'ArticleType ', column 'AT_ID '。

如何解决??

[解决办法]
alter table a2 add constraint a2_con foreign key(produce)references a1(produce) on delete cascade on update cascade
少了cascade

读书人网 >SQL Server

热点推荐