我从未手写过用于 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
);
运行查询时出现以下错误:
Msg 8139, Level 16, State 0, Line 9 外键中引用列数量与被引用表“question_bank”的列数量不一致。
您能发现错误吗?