“'字段列表中的未知列'与现有数据

时间:2017-05-09 22:17:05

标签: mysql sql

| enrollment | CREATE TABLE `enrollment` (
  `SSN` varchar(9) NOT NULL,
  `CourseNumber` varchar(4) NOT NULL,
  `Quarter` varchar(10) NOT NULL,
  `Grade` varchar(1) DEFAULT NULL,
  PRIMARY KEY (`SSN`,`CourseNumber`,`Quarter`),
  KEY `CourseNumber` (`CourseNumber`),
  KEY `Quarter` (`Quarter`),
  CONSTRAINT `enrollment_ibfk_1` FOREIGN KEY (`SSN`) REFERENCES `Student` (`SSN`),
  CONSTRAINT `enrollment_ibfk_2` FOREIGN KEY (`CourseNumber`) REFERENCES `Course` (`CourseNumber`),
  CONSTRAINT `enrollment_ibfk_3` FOREIGN KEY (`Quarter`) REFERENCES `section` (`Quarter`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |


| student | CREATE TABLE `student` (
  `SSN` varchar(9) NOT NULL,
  `Name` varchar(15) DEFAULT NULL,
  `Major` varchar(15) DEFAULT NULL,
  PRIMARY KEY (`SSN`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

mysql> select * from student;
+-----------+----------------+-----------+
| SSN       | Name           | Major     |
+-----------+----------------+-----------+
| 111111111 | Danny James    | History   |
| 123123123 | John White     | Chemistry |


mysql> INSERT INTO ENROLLMENT (SSN, CourseNumber, Quarter, Grade) 
values (‘111111111’, '220','Winter2014', 'A');
  

ERROR 1054(42S22):未知栏''111111111''在'字段列表'

我是SQL的初学者。 我显然有一个学生有#111111111'作为他们的SSN。但它仍然说它是未知的专栏。请帮忙。

1 个答案:

答案 0 :(得分:2)

您的问题在这里:

 mysql> INSERT INTO ENROLLMENT (SSN, CourseNumber, Quarter, Grade) 
 values (‘111111111’, '220','Winter2014', 'A');
        ^^^^^^^^^^^^^^^

您使用了引号 而非标准单引号'来定义第一个值。

修复:

  mysql> INSERT INTO ENROLLMENT (SSN, CourseNumber, Quarter, Grade) 
  values ('111111111', '220','Winter2014', 'A');