phpmyadmin SQL不接受我的评论

xxb16uws  于 6个月前  发布在  PHP
关注(0)|答案(3)|浏览(71)

我正在尝试在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', 'larry@google.com');

--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/的数据库

4xrmg8kj

4xrmg8kj1#

您需要在--之后添加一个间隔/空格
否则,它在MySQL中不被认为是有效的注解。

ggazkfy8

ggazkfy82#

如果你在manual中使用“--”样式的注解,你需要一个空格。在你的创建之后也要添加一个“;”。

-- create a mysql contact table

字符串
--删除联系人表,如果已经存在DROP TABLE IF EXISTS联系人;
--创建一个新的名为contact的表,其字段为指定的CREATE TABLE contact(contactID int PRIMARY KEY,name VARCHAR(50),company VARCHAR(30),email VARCHAR(50));
-- add these to the table INTO contact VALUES(0,'Bill Gates','Microsoft',' email protected(https://stackoverflow.com/cdn-cgi/l/email-protection) '); INTO contact VALUES(1,'Larry Page','Google',' email protected(https://stackoverflow.com/cdn-cgi/l/email-protection) ');
--显示此SELECT * FROM联系人中的内容;

ws51t4hk

ws51t4hk3#

您需要在两个破折号标记和您的评论之间放置一个空格。例如,这将不起作用

--This program will run

字符串
但这会有用的

-- this program will run


这只是因为我在两个破折号后提供了一个空格

相关问题