一最安 2021-02-05 01:42 采纳率: 84.4%
浏览 913
已结题

mysql数据库创建表格出现问题,望赐教!

Operation failed: There was an error while applying the SQL script to the database.
Executing:
CREATE TABLE `managesystem`.`department_manager` (
  `dm_id` INT NOT NULL,
  `user_id` VARCHAR(20) NOT NULL,
  `dm_name` VARCHAR(20) NOT NULL,
  `dp_id` INT NOT NULL,
  `is_onjob` TINYINT NOT NULL,
  `co_id` INT NOT NULL,
  PRIMARY KEY (`dm_id`),
  CONSTRAINT `user_id`
    FOREIGN KEY ()
    REFERENCES `managesystem`.`user` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_bin;

ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
    REFERENCES `managesystem`.`user` ()
    ON DELETE NO ACTION
    ON UPDATE ' at line 10
SQL Statement:
CREATE TABLE `managesystem`.`department_manager` (
  `dm_id` INT NOT NULL,
  `user_id` VARCHAR(20) NOT NULL,
  `dm_name` VARCHAR(20) NOT NULL,
  `dp_id` INT NOT NULL,
  `is_onjob` TINYINT NOT NULL,
  `co_id` INT NOT NULL,
  PRIMARY KEY (`dm_id`),
  CONSTRAINT `user_id`
    FOREIGN KEY ()
    REFERENCES `managesystem`.`user` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_bin


以上为错误报告信息,以下为本人在表格输入属性和数据类型后自动生成的sql语句

CREATE TABLE `managesystem`.`department_manager` (
  `dm_id` INT NOT NULL,
  `user_id` VARCHAR(20) NOT NULL,
  `dm_name` VARCHAR(20) NOT NULL,
  `dp_id` INT NOT NULL,
  `is_onjob` TINYINT NOT NULL,
  `co_id` INT NOT NULL,
  PRIMARY KEY (`dm_id`),
  CONSTRAINT `user_id`
    FOREIGN KEY ()
    REFERENCES `managesystem`.`user` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_bin;

本人是直接往表格里输属性和数据类型,没有手敲sql语句,想问现问题出在哪,该如何解决?不胜感激!

  • 写回答

2条回答 默认 最新

  • damoneric_guo 2021-02-05 09:06
    关注

    你创建外键有问题,先创建表,在添加外键,这种方式也可以

    添加外键 ,alter table B

    语法bai:dualter table 表名zhidao add constraint 外键约束zhuan名 foreign key(列名) references 引用外键表(列名)

    如:

    alter table Stu_PkFk_Sc
    add constraint Fk_s
    foreign key (sno)
    references Stu_PkFk_S(sno)

    --cc是外键约束名,不能重复,也shu不能是int类型(如1,2,3)

    add constraint cc

    --B表里的需要约束的字段(id)

    foreign key (id)

    --A表后的(id)可省略

    references A (id)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月29日
  • 已采纳回答 8月21日

悬赏问题

  • ¥15 请教一个关于镜头标定,棋盘格格子大小的问题(畸变测试)
  • ¥15 el-table输入多维数组怎么实现
  • ¥15 安装GroudingDINO RuntimeError: Error compiling objects for extension
  • ¥15 关于推送项目到github的问题
  • ¥15 急!C++指针编写相关的问题
  • ¥15 kerberos身份认证配置问题
  • ¥30 用python写一个多签情况下波场的代理资源和回收资源
  • ¥15 怎么在matlab中输出显示泵的流量-扬程和管路损失与流量均在一个表格里
  • ¥15 matlab学期例题代码答疑
  • ¥15 在线手电筒追加按钮JS