SQL 外键方面的 在线等答案

来源:百度知道 编辑:UC知道 时间:2024/09/28 11:37:12
我创建了两个表b和c
b表的列 id int 主键
name varchar(20)
price int
class int

c表的列
oprice int 主键
name varchar(20)
number int

我在b表中设 关系

主键表 外键表
c b
oprice price

这样设不成


'c' 表成功保存
'b' 表
- 不能创建关系 'FK_b_c'。
ODBC 错误: [Microsoft][ODBC SQL Server Driver][SQL Server]ALTER TABLE 语句与 COLUMN FOREIGN KEY 约束 'FK_b_c' 冲突。该冲突发生于数据库 'shujuku',表 'c', column 'oPrice'

这是为什麽阿??

相反 设
主键表 外键表
b c
price oprice

也设不成
郁闷 哪位高手知道啊
指点一下

create table b (
name varchar(20) not null,
price int not null,
class int null,
constraint PK_B primary key (price)
)
go

/*==============================================================*/
/* Table: c */
/*==============================================================*/
create table c (
oprice int not null,
name varchar(10) null,
number int null,
constraint PK_C primary key (oprice)
)
go

alter table c
add constraint FK_C_REFERENCE_B foreign key (oprice)
references b (price)
go

我也碰到了这样的问题~
我是因为主键和外键int字节类型不同所以产生了冲突
和主键表 外键表 的前后循序没有关系