我正在尝试在 PHPMyAdmin 中运行此 sql 查询:
--create a mysql contact table
--delete contact table if already exists
DROP TABLE IF EXISTS contact;
--create new table named contact with fields as specified
CREATE TABLE contact(
contactID int PRIMARY KEY,
name VARCHAR(50),
company VARCHAR(30),
email VARCHAR(50)
);
--add these to the table
INSERT INTO contact VALUES (0, 'Bill Gates', 'Microsoft', '[email protected]');
INSERT INTO contact VALUES (1, 'Larry Page', 'Google', '[email protected]');
--displays whats in this
SELECT * FROM contact;
我认为在sql中这被认为是一条注释:
--I'm a comment
但是 PHPMyAdmin 不接受它。
我收到此错误:
SQL query:
--create a mysql contact table
--delete contact table if already exists DROP TABLE IF EXISTS contact;
MySQL said:
Documentation
1064 - You have an error in your SQL syntax;
Check the manual that corresponds to your MySQL server version for the right syntax to
use near '--create a mysql contact table --delete contact table if already exists
DROP T' at line 1
我在这些 sql 检查器上使用相同的代码也遇到了相同的错误:
http://www.piliapp.com/mysql-syntax-check/ http://sqlfiddle.com/
您需要在
--
之后有一个间隔/空格
否则它在 MySQL 中不被视为有效注释。
如果您按照手册使用“--”样式注释,则需要一个空格。还要加上一个“;”创建后。
-- create a mysql contact table
-- 删除联系人表(如果已存在) 如果存在则删除表联系人;
-- 创建名为 contact 的新表,并指定字段 创建表联系人( contactID int 主键, 名称 VARCHAR(50), 公司 VARCHAR(30), 电子邮件 VARCHAR(50) );
-- 将这些添加到表中 INSERT INTO 联系人值(0、“比尔·盖茨”、“微软”、“[电子邮件受保护]”); 插入联系人值(1、“Larry Page”、“Google”、“[电子邮件受保护]”);
-- 显示此内容 从联系人中选择 *;
您需要在两个破折号标记和您的评论之间添加一个空格。例如,这将不起作用--该程序将运行,但这将起作用 -- 该程序将运行。这只是因为我在两个破折号后面提供了一个空格