[英]Why do I receive error 1241 when trying to Create and Insert data into a new table (on phpMyAdmin)?
I am trying to create a new table and insert values into it however I keep receiving "#1241 - Operand should contain 1 column(s)".我正在尝试创建一个新表并向其中插入值,但是我一直收到“#1241 - 操作数应包含 1 列”。 Please could someone help to identify what is wrong with my code as I am unsure what this error is referencing?
请有人帮助确定我的代码有什么问题,因为我不确定这个错误是指什么?
The code I am inserting into the phpMyAdmin database under the SQL tab.我在 SQL 选项卡下插入到 phpMyAdmin 数据库中的代码。 I have tried to remove the auto increment attributes and have tried looking at other examples to check my syntax, but I can't spot the issue.
我尝试删除自动增量属性并尝试查看其他示例来检查我的语法,但我无法发现问题。 Some guidance on this would be greatly appreciated.
对此的一些指导将不胜感激。
The code I entered begins like this:我输入的代码是这样开始的:
# AppSoft Project - Greg Roberts
DROP table if exists Department;
DROP table if exists Role;
DROP table if exists User;
DROP table if exists Appraisal;
DROP table if exists Question;
DROP table if exists Answer;
CREATE table Department(
DeptID int NOT NULL AUTO_INCREMENT,
DeptName varchar(30) NOT NULL,
primary key (DeptID));
INSERT into Department values(
(00, 'SuperAdmin'),
(01, 'Support Staff'),
(02, 'Teaching Staff'),
(03, 'SLT'));
CREATE table Role(
RoleID int NOT NULL AUTO_INCREMENT,
RoleTitle varchar(30) NOT NULL,
primary key (RoleID));
INSERT into Role values(
(00, 'SuperAdmin'),
(01, 'Office Administrator'),
(02, 'Teaching Partner'),
(03, 'Mid Day Supervisor'),
(04, 'Cooks'),
(05, 'Cleaners'),
(06, 'Maintenance'),
(07, 'Teacher'),
(08, 'Department Head'),
(09, 'SENCO'),
(10, 'Head Teacher'),
(11, 'Executive Head'));
You dont need to insert primary keys, if they are set to auto_increment.您不需要插入主键,如果它们设置为 auto_increment。
DeptID int NOT NULL AUTO_INCREMENT
Just insert the department name, there are no additional braces required for Values.只需插入部门名称,值不需要额外的大括号。
INSERT into Department( DeptName) values
('SuperAdmin'),
('Support Staff'),
('Teaching Staff'),
('SLT');
You would need to do the same for Role table as well.您也需要对 Role 表执行相同的操作。
Also if you try to insert 0
into the primary key, it will actually insert 1
you can read about it in the Standard Docs此外,如果您尝试将
0
插入主键,它实际上会插入1
您可以在标准文档中阅读它
you seem to be getting the error because your first record inserts 1
into the table and then your second record tries to insert 1
again in the primary key column您似乎收到错误消息,因为您的第一条记录将
1
插入表中,然后您的第二条记录尝试在主键列中再次插入1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.