【发布时间】:2010-09-08 02:32:25
【问题描述】:
我从来没有为 SQL Server“手工编码”过对象创建代码,而且 SQL Server 和 Postgres 之间的外键解密似乎不同。到目前为止,这是我的 sql:
drop table exams;
drop table question_bank;
drop table anwser_bank;
create table exams
(
exam_id uniqueidentifier primary key,
exam_name varchar(50),
);
create table question_bank
(
question_id uniqueidentifier primary key,
question_exam_id uniqueidentifier not null,
question_text varchar(1024) not null,
question_point_value decimal,
constraint question_exam_id foreign key references exams(exam_id)
);
create table anwser_bank
(
anwser_id uniqueidentifier primary key,
anwser_question_id uniqueidentifier,
anwser_text varchar(1024),
anwser_is_correct bit
);
当我运行查询时,我得到了这个错误:
消息 8139,第 16 级,状态 0,第 9 行 中的引用列数 外键与数量不同 引用的列、表 'question_bank'。
你能发现错误吗?
【问题讨论】:
-
仅供参考,总是最好为您的约束命名,尤其是在使用 ORM 时。
标签: sql sql-server tsql