您好,我现在正在使用php我的管理员学习SQL。我在使用INSERT INTO时遇到了一些麻烦。我查看了如何创建INSERT INTO的语法,但我总是得到一个错误,我的版本错误。有谁知道我做错了什么?
CREATE TABLE patient1(
patient_id INT (3) NOT NULL AUTO_INCREMENT,
place VARCHAR (20) NOT NULL,
profession VARCHAR (30)NOT NULL,
age INT (11),
PRIMARY KEY (patient_id)
)
INSERT INTO patient (patient_id, place, profession, age) VALUES (101, 'Indiana','Software', 23);
INSERT INTO patient (patient_id, place, profession, age) VALUES(102, 'Ohio', 'Teacher',45);
INSERT INTO patient (patient_id, place, profession, age) VALUES(103, 'Ohio', 'Doctor', 65);
INSERT INTO patient (patient_id, place, profession, age) VALUES(104, 'Indiana', 'Software', 34);
INSERT INTO patient (patient_id, place, profession, age) VALUES(105, 'Wisconsin', 'Pharmacist', 69);
答案 0 :(得分:0)
因为patient_id
具有自动递增,所以您不需要在声明中包含它。
INSERT INTO patient (place, profession, age)
VALUES ('Indiana','Software', 23);
修改强>
仔细检查代码后,问题是您为表patient1
命名,但是插入patient
检查 demo 以查看是否有效
答案 1 :(得分:-1)
请正确检查您的表名。这就是问题所在。
INSERT INTO patient1 (patient_id, place, profession, age) VALUES (101, 'Indiana','Software', 23);
INSERT INTO patient1 (patient_id, place, profession, age) VALUES(102, 'Ohio', 'Teacher',45);
INSERT INTO patient1 (patient_id, place, profession, age) VALUES(103, 'Ohio', 'Doctor', 65);
INSERT INTO patient1 (patient_id, place, profession, age) VALUES(104, 'Indiana', 'Software', 34);
INSERT INTO patient1 (patient_id, place, profession, age) VALUES(105, 'Wisconsin', 'Pharmacist', 69);