我从来没有为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,16级,状态0,第9行

你能发现错误吗?

推荐答案

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 fk_questionbank_exams foreign key (question_exam_id) references exams (exam_id)
);

Sql相关问答推荐

SQL更新,在2个额外的表上使用内部连接

不可能在SQL MERGE子句中引发异常

为什么在postgres中,横向连接比相关子查询快?

LEFT JOIN不显示计数0我期望的方式

PostgreSQL基于2个COLS的任意组合 Select 唯一行

DBeaver将过程中的属性列表转换为字符串

在MS Access Modern图表的X轴上显示时间值时遇到问题

SQL到Snowflake-转换嵌套的SELECT(值

在UNION查询中查找MIN

使用递归CTE在BigQuery中获取文件路径

当active=1时,是否可以创建id为的唯一索引?

使用CTE在SNOWFLAKE中创建临时表

在 PostgreSQL 中使用 ltree 列进行累积

从另一个没有公共键的表中获取值来加入

具有分组条件的不同计数 (DAX)

特殊条件计算小计

SQL:考虑合并分支计算分支的增长百分比

获取记录的上一个值,并将其与当前值一起显示

如何在 DAX 中通过 Window 函数应用订单

多列上的 SQL UNIQUE 约束 - 它们的组合必须是唯一的还是至少其中之一?