这是一个创建和插入数据到 MySQL 数据库中的语句,但是有一个小问题。 在表的 CONSTRAINT 中,sex 字段的 CHECK 约束条件应该是 `CHECK (sex = '男' OR sex = '女')`,而不是 `CHECK (((sex = '男') or (sex = '女'))) `。 正确的语句如下: “` CREATE TABLE employees ( EmployeeID int NOT NULL AUTO_INCREMENT COMMENT '工号', Name varchar(20) NOT NULL COMMENT '姓名', sex char(2) DEFAULT NULL COMMENT '性别', BirthDate date DEFAULT NULL COMMENT '出生日期', Phone varchar(24) DEFAULT NULL COMMENT '电话', HireDate date DEFAULT NULL COMMENT '入职日期', Address varchar(15) DEFAULT NULL COMMENT '工作地点', Title varchar(30) DEFAULT NULL COMMENT '职位', ReportsTo int(11) DEFAULT NULL COMMENT '上级工号', PRIMARY KEY (EmployeeID), KEY FK_Employees_Employees (ReportsTo), KEY Name (Name), CONSTRAINT FK_Employees_Employees FOREIGN KEY (ReportsTo) REFERENCES employees (EmployeeID), CONSTRAINT employees_chk_1 CHECK (sex = '男' OR sex = '女') ) ENGINE=InnoDB AUTO_INCREMENT=11; INSERT INTO employees ( EmployeeID, Name, sex, BirthDate, Phone, HireDate, Address, Title, ReportsTo ) VALUES ( 1, '蔡小叶', '女', '1983-11-10', '15651718131', '2014-01-02', '海南省三亚市', '销售员', NULL ), ( 2, '陈会玲', '女', '1983-12-24', '15651792676', '2011-09-10', '河南省焦作市', '总经理', NULL ), ( 3, '陈荣', '女', '1984-03-14', '18052098320', '2014-09-26', '江苏省南京市', '销售员', NULL ), ( 4, '江小利', '女', '1983-12-10', '15651793136', '2012-09-07', '四川省蒲江市', '销售员', NULL ), ( 5, '吕倩', '女', '1980-10-28', '15651036060', '2014-08-27', '浙江省宁波市', '销售经理', NULL ), ( 6, '于小飞', '男', '1984-02-19', '15605167963', '2013-12-16', '湖北省宜昌市', '销售员', NULL ), ( 7, '袁卫华', '男', '1983-09-23', '18761666129', '2014-01-09', '江苏省溧阳县', '销售员', NULL ), ( 8, '张家瑞', '男', '1983-05-26', '18652204573', '2012-09-05', '四川省宜宾市', '销售经理', NULL ), ( 9, '张玉', '男', '1984-02-15', '18914785173', '2013-04-21', '安徽省安庆市', '销售员', NULL ), ( 10, '赵恒', '男', '1983-03-10', '18761662284', '2012-10-30', '深圳', NULL, NULL ); “`
原文链接:https://blog.csdn.net/weixin_39917894/article/details/117901322?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171949603516800225579158%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171949603516800225579158&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-15-117901322-null-null.nonecase&utm_term=2024%E9%AB%98%E8%80%83%E5%88%86%E6%95%B0%E7%BA%BF