相关疑难解决方法(0)

如何在SQL Server中创建外键?

我从来没有为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
);
Run Code Online (Sandbox Code Playgroud)

当我运行查询时,我收到此错误:

消息8139,级别16,状态0,行9外键中的引用列数与引用列的数量不同,表'question_bank'.

你能发现错误吗?

sql t-sql sql-server

240
推荐指数
9
解决办法
44万
查看次数

标签 统计

sql ×1

sql-server ×1

t-sql ×1