我晕!这样建表也错误??? sqlserver
来源:百度知道 编辑:UC知道 时间:2024/07/06 23:11:38
create table library
(
自动编号 int not null identity(1,1),
图书分类 char(8),
图书属性 tinyint,
primary key (自动编号,图书属性)
)
create table book
(
自动编号 int not null identity(1,1),
图书属性 tinyint constraint my_fk foreign key(图书属性) references library(图书属性) on delete cascade ,
图书作者 char(8),
发布日期 datetime,
)
第一个成功,第二个提示:
消息 1776,级别 16,状态 0,第 1 行
在被引用表 'library' 中没有与外键 'my_fk' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。
(
自动编号 int not null identity(1,1),
图书分类 char(8),
图书属性 tinyint,
primary key (自动编号,图书属性)
)
create table book
(
自动编号 int not null identity(1,1),
图书属性 tinyint constraint my_fk foreign key(图书属性) references library(图书属性) on delete cascade ,
图书作者 char(8),
发布日期 datetime,
)
第一个成功,第二个提示:
消息 1776,级别 16,状态 0,第 1 行
在被引用表 'library' 中没有与外键 'my_fk' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。
create table book
(
自动编号 int not null identity(1,1),
图书属性 tinyint primary key,
图书作者 char(8),
发布日期 datetime,
)
这样不就可以了吗
说实话我没用过sqlserver,但是我很奇怪呢字段名为什么要用中文呢?
是不是你前面没有标明是要在同一个数据库中创建啊?比如,是不是应该在“create table book ”前面加上这么一句“USE 数据库名”