gpt4 book ai didi

mysql - InnoDB 文档 支持事务、行级锁定和外键

转载 作者:行者123 更新时间:2023-11-30 00:30:12 26 4
gpt4 key购买 nike

我尝试在 phpmyadmin 中创建下表,但收到上述错误

-- ----------------------------------------------------- Create County Table-- ---------------------------------------------------CREATE  TABLE IF NOT EXISTS SecretGarden.County (        co_id varchar (8) NOT NULL UNIQUE ,        co_desc VARCHAR(50),        st_date DATE,        end_date DATE,        PRIMARY KEY (co_id) );-- ----------------------------------------------------- Create Login Table-- ---------------------------------------------------CREATE  TABLE IF NOT EXISTS SecretGarden.login (        email_id varchar (100) NOT NULL UNIQUE,        password VARCHAR(50),        st_date DATE,        end_date DATE,        PRIMARY KEY (email_id) );-- ----------------------------------------------------- Create Address Table-- ---------------------------------------------------CREATE  TABLE IF NOT EXISTS SecretGarden.address (        add_id int (8) NOT NULL AUTO_INCREMENT ,         address1 VARCHAR(50),                 address2 VARCHAR(50),                 town VARCHAR(50),                 co_id varchar (8),         st_date DATE,        end_date DATE,        PRIMARY KEY (add_id),                CONSTRAINT fk_coid    FOREIGN KEY (co_id)    REFERENCES county(co_id)); -- ----------------------------------------------------- Create StaffRole Table-- ---------------------------------------------------CREATE  TABLE IF NOT EXISTS SecretGarden.staffrole (        staffrole_id int (8) NOT NULL AUTO_INCREMENT ,         staffrole_desc VARCHAR(50),                 st_date DATE,         end_date DATE,        PRIMARY KEY (staffrole_id));

以上所有内容都运行完美,但是当我尝试创建下一个表时,出现上述错误

-- ----------------------------------------------------- Create Staff Table-- ---------------------------------------------------CREATE  TABLE IF NOT EXISTS SecretGarden.staff (        staff_id int (8) NOT NULL AUTO_INCREMENT ,         fname VARCHAR(50),                 lname VARCHAR(50),                 email_id varchar (100),                 home_no INT (20),                 mobile_no INT (20),                 add_id INT (8),                 staffrole_id INT (8),         st_date DATE,         end_date DATE,        PRIMARY KEY (staff_id),                CONSTRAINT fk_emailid        FOREIGN KEY (email_id)            REFERENCES SecretGarden.login(email_id),            CONSTRAINT fk_addid                FOREIGN KEY (add_id)                REFERENCES SecretGarden.address(add_id),            CONSTRAINT fk_staffrole                FOREIGN KEY (staffrole_id)                REFERENCES SecretGarden.staffrole(staffrole_id)); 


任何帮助将非常感激瑞秋

最佳答案

问题是我没有给每个约束一个单独的名称
我没有意识到它们对于整个数据库来说是唯一的

关于mysql - InnoDB 文档 支持事务、行级锁定和外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22570558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com