CREATE TABLE HeroInfo ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, gender VARCHAR(2) CHECK (gender IN ('男', '女')), price DECIMAL(8,2) CHECK (price > 2000), words VARCHAR(50) DEFAULT '为正义而战', type_id INT NOT NULL, FOREIGN KEY (type_id) REFERENCES HeroInfo_types(id) ); INSERT INTO HeroInfo (name, gender, price, words, type_id) VALUES ("阿尔萨斯", "男", "5800", "我是巫妖王", 1); INSERT INTO HeroInfo (name, gender, price, words, type_id) VALUES ("萨尔", "男", "5500", "兽人永不为奴", 2); INSERT INTO HeroInfo (name, gender, price, words, type_id) VALUES ("阿尔萨斯", "男", "5800", "我们是被遗忘者", 3); INSERT INTO HeroInfo (name, gender, price, words, type_id) VALUES ("凯恩", "男", "4000", "大地母亲在护佑着你", 1); INSERT INTO HeroInfo (name, gender, price, words, type_id) VALUES ("吉安", "男", "7000", null, 2); SELECT * FROM HeroInfo; 哪里错了
时间: 2023-07-19 11:07:17 浏览: 100
在INSERT语句中,数值类型的字段不需要使用引号。所以在price字段的插入中,应该使用数字而不是字符串。正确的SQL语句如下:
```
CREATE TABLE HeroInfo (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20) NOT NULL,
gender VARCHAR(2) CHECK (gender IN ('男', '女')),
price DECIMAL(8,2) CHECK (price > 2000),
words VARCHAR(50) DEFAULT '为正义而战',
type_id INT NOT NULL,
FOREIGN KEY (type_id) REFERENCES HeroInfo_types(id)
);
INSERT INTO HeroInfo (name, gender, price, words, type_id)
VALUES ('阿尔萨斯', '男', 5800, '我是巫妖王', 1);
INSERT INTO HeroInfo (name, gender, price, words, type_id)
VALUES ('萨尔', '男', 5500, '兽人永不为奴', 2);
INSERT INTO HeroInfo (name, gender, price, words, type_id)
VALUES ('阿尔萨斯', '男', 5800, '我们是被遗忘者', 3);
INSERT INTO HeroInfo (name, gender, price, words, type_id)
VALUES ('凯恩', '男', 4000, '大地母亲在护佑着你', 1);
INSERT INTO HeroInfo (name, gender, price, words, type_id)
VALUES ('吉安', '男', 7000, null, 2);
SELECT * FROM HeroInfo;
```
阅读全文