create database XS
create table 商店
(商店编号 char(7) not null,
商店名 nvarchar(20) not null unique,
地址 nvarchar(20),
联系电话 char(11),
)
create table 商品
(商品号 char(7) not null,
商品名 nvarchar(20) not null unique,
进货价格 nvarchar(20),
进货日期 nchar(11),
销售价格 nchar(11),
)
create table 购物
(商店名 nvarchar(20) not null,
商品名 nvarchar(20) not null,
购买数量 nvarchar(20) not null,
购买日期 nchar(11)
)
alter table 商店
add constraint PK_商店_商店编号 primary key(商店编号)
alter table 商品
add constraint PK_商品_商品名 primary key(商品名)
alter table 购物
add constraint PK_购物_商店名_商品名 primary key(商店名,商品名)
alter table 商店
add constraint FK_商店_购物_商店名 foreign key(商店名)
references 购物(商店名)
消息 1776,级别 16,状态 0,第 36 行
在被引用表 '购物' 中没有与外键 'FK_商店_购物_商店名' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 1,第 36 行
无法创建约束或索引。请参阅前面的错误。