sql语法错误
答案:2 悬赏:0 手机版
解决时间 2021-11-12 07:08
- 提问者网友:夢醒日落
- 2021-11-11 17:17
sql语法错误
最佳答案
- 五星知识达人网友:骨子里都是戏
- 2021-11-11 18:32
你定义外键语法错误。
加外键约束,格式:FOREIGN KEY REFERENCES 关联的表名(字段名)
修改为:
CREATE TABLE slt_couse(
cs_id char(4) NOT NULL Foreign Key 课程表(课程id),
st_id char(9) NOT NULL Foreign Key 学生表(学生id),
score int,
sltdate datetime
)
或者 直接创建列,后在添加外键约束
CREATE TABLE slt_couse(
cs_id char(4) NOT NULL,
st_id char(9) NOT NULL ,
score int,
sltdate datetime
)
alter table slt_couse add constraint FK_B foreign key (cs_id ) references 课程表(课程id)
alter table slt_couse add constraint FK_C foreign key (st_id ) references 学生表(学生id)
加外键约束,格式:FOREIGN KEY REFERENCES 关联的表名(字段名)
修改为:
CREATE TABLE slt_couse(
cs_id char(4) NOT NULL Foreign Key 课程表(课程id),
st_id char(9) NOT NULL Foreign Key 学生表(学生id),
score int,
sltdate datetime
)
或者 直接创建列,后在添加外键约束
CREATE TABLE slt_couse(
cs_id char(4) NOT NULL,
st_id char(9) NOT NULL ,
score int,
sltdate datetime
)
alter table slt_couse add constraint FK_B foreign key (cs_id ) references 课程表(课程id)
alter table slt_couse add constraint FK_C foreign key (st_id ) references 学生表(学生id)
全部回答
- 1楼网友:野慌
- 2021-11-11 19:45
Foreign Key指定另一个表中的 PRIMARY KEY
你没有指定其他表的PRIMARY KEY。
CREATE TABLE slt_couse(
cs_id char(4) NOT NULL Foreign Key REFERENCES table1 (cs_id),
st_id char(9) NOT NULL Foreign Key REFERENCES table1 (st_id),
score int,
sltdate datetime
)
将他们指定到table1的csid和stid
你没有指定其他表的PRIMARY KEY。
CREATE TABLE slt_couse(
cs_id char(4) NOT NULL Foreign Key REFERENCES table1 (cs_id),
st_id char(9) NOT NULL Foreign Key REFERENCES table1 (st_id),
score int,
sltdate datetime
)
将他们指定到table1的csid和stid
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯