被引用表 'good_publisher' 中没有与外键 'FK__goods__g_name_' 的引用列的列表匹配的主键或候选键。

create table good_publisher(g_pub_name char(10) not null,g_pub_num char(10) primary key,g_pub_password char(9) not null,g_pub_goods char(10),g_pub_good_num char(10),g_pub_phone char(20));create table goods(g_name char(10),g_num char(10)not null,publisher_name char(10),publisher_num char(10),publisher_phone char(20),foreign key(g_name)references good_publisher(g_pub_goods),foreign key (g_num)references good_publisher(g_pub_good_num), foreign key(publisher_name)references good_publisher(g_pub_name),foreign key(publisher_num)references good_publisher(g_pub_num),foreign key(publisher_phone)references good_publisher(g_pub_phone));

第1个回答  2013-12-26
create table good_publisher
(
g_pub_name char(10) not null,
g_pub_num char(10) primary key
,g_pub_password char(9) not null,
g_pub_goods char(10),
g_pub_good_num char(10),
g_pub_phone char(20)
);
create table goods(
g_name char(10),
g_num char(10)not null,
publisher_name char(10),
publisher_num char(10),
publisher_phone char(20),
foreign key(g_name)references good_publisher(g_pub_goods),--这里有问题,主键只是在g_pub_num字段上
foreign key (g_num)references good_publisher(g_pub_good_num), --这里有问题,主键只是在g_pub_num字段上
foreign key(publisher_name)references good_publisher(g_pub_name),--这里有问题,主键只是在g_pub_num字段上
foreign key(publisher_num)references good_publisher(g_pub_num),--这个关系是没得问题的
foreign key(publisher_phone)references good_publisher(g_pub_phone)--这里有问题,主键只是在g_pub_num字段上
);

追问

实在不知怎么改,劳烦大哥给小弟改改行不?

追答create table good_publisher
(
    g_pub_name char(10) not null,
    g_pub_num char(10) primary key
    ,g_pub_password char(9) not null,
    g_pub_goods char(10),
    g_pub_good_num char(10),
    g_pub_phone char(20)
);
create table goods(
    g_name char(10),
    g_num char(10)not null,
    publisher_name char(10),
    publisher_num char(10),
    publisher_phone char(20),
    foreign key(publisher_num)references good_publisher(g_pub_num),--这个关系是没得问题的
);

相似回答