第一次sql数据库创建表名称区域显示为红色

时间:2014-02-06 11:51:58

标签: mysql sql phpmyadmin

您好我是第一次手写代码创建一个sql数据库,我使用phpMyAdmin来创建数据库。我正在创建名为主题,级别,区域和原则的表格;它们都将使用外键相互链接但我注意到在输入表名时,它以红色显示任何想法或简单的解释。

到目前为止我的代码是:

   CREATE TABLE subject (
subject_id VARCHAR (50) PRIMARY KEY,
description VARCHAR (200),
FOREIGN KEY (level_id) REFERENCES level(level_id),
FOREIGN KEY (area_id) REFERENCES area(area_id),
FOREIGN KEY (principle_id) REFERENCES principle(principle_id)
) Engine = InnoDB;

INSERT INTO subject (subject_id, description)VALUES 
('Mathematics', 'this is the maths description'),
('English', 'this is the  description'),
('Science', 'this is the science description'),
('Computing', 'this is the computing description'),
('Design and Technology', 'this is the Design and technology description'),
('Art', 'this is the Art description');

CREATE TABLE level (
level_id VARCHAR (50) PRIMARY KEY,
description VARCHAR (200),
FOREIGN KEY (subject_id) REFERENCES subject(subject_id),
FOREIGN KEY (area_id) REFERENCES area(area_id),
FOREIGN KEY (principle_id) REFERENCES principle(principle_id)
) Engine = InnoDB;

INSERT INTO level (level_id, description)VALUES 
('Key Stage 1', 'this is year 1 - 2 in school'),
('Key Stage 2', 'this is year 3 - 6 in school'),
('Key Stage 3', 'this is year 7 - 9 in school'),
('Key Stage 4', 'this is year 10 - 11 in school'),
('Key Stage 5', 'this is year 12 - 13 in school');

CREATE TABLE area (
area_id VARCHAR (50) PRIMARY KEY,
description VARCHAR (200),
FOREIGN KEY (subject_id) REFERENCES subject(subject_id),
FOREIGN KEY (level_id) REFERENCES level(level_id),
FOREIGN KEY (principle_id) REFERENCES principle(principle_id)
) Engine = InnoDB;

这发生的代码行是

     FOREIGN KEY (area_id) REFERENCES area(area_id),

是因为这个词代表了别的东西,你不能创建一个名为area的表或者它会没事吗?

1 个答案:

答案 0 :(得分:1)

MySQL认为你正在尝试引用Polygon Area Function - 你最好的是引用'area',详见@Rag的第一条评论。