简体   繁体   English

为什么在尝试创建数据并将数据插入新表(在 phpMyAdmin 上)时会收到错误 1241?

[英]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'));

Error Code that Occurs发生的错误代码

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.

相关问题 尝试将存储过程结果插入表时,PHPmyadmin错误 - PHPmyadmin error when trying to insert stored procedure results to table 我在尝试在phpmyadmin中创建表时遇到错误 - I am getting an error trying to create table in phpmyadmin 当我尝试将数据插入表中时,为什么会出现错误? - Why do I get an error when I try to insert data into my table? phpMyAdmin在尝试将ID(使用SET IDENTITY_INSERT)插入表时给出错误#1064 - phpMyAdmin giving error #1064 when trying to insert ID(using SET IDENTITY_INSERT) into table 尝试在数据库中查找和替换javascript时为什么收到SQL错误 - Why do I receive an error in SQL when trying to find and replace javascript within a database 尝试在phpMyAdmin中创建事件时,在“END”处出错 - Error at 'END' when trying to create event in phpMyAdmin 尝试参数化表名时,为什么会收到不正确的语法错误? - Why do I receive an incorrect syntax error when try to parameterize a table name? 为什么在尝试向表中插入行时出现此错误? - Why am I getting this error when trying to insert rows into my table? 尝试将购物车中的数据插入新表时出错 - Error when trying to insert the data from the cart to the new tables 尝试将值插入表中时出错,但不确定原因 - Error when trying to insert values into a table and not sure why
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM