phpmyadmin SQL不接受我的评论

xxb16uws  于 2023-11-19  发布在  PHP
关注(0)|答案(3)|浏览(275)

我正在尝试在PHPMyAdmin中运行此SQL查询:

  1. --create a mysql contact table
  2. --delete contact table if already exists
  3. DROP TABLE IF EXISTS contact;
  4. --create new table named contact with fields as specified
  5. CREATE TABLE contact(
  6. contactID int PRIMARY KEY,
  7. name VARCHAR(50),
  8. company VARCHAR(30),
  9. email VARCHAR(50)
  10. );
  11. --add these to the table
  12. INSERT INTO contact VALUES (0, 'Bill Gates', 'Microsoft', '[email protected]');
  13. INSERT INTO contact VALUES (1, 'Larry Page', 'Google', 'larry@google.com');
  14. --displays whats in this
  15. SELECT * FROM contact;

字符串
我认为在SQL中这被认为是一个注解:--I'm a comment
但是PHPMyAdmin不接受它。
我得到这个错误:

  1. SQL query:
  2. --create a mysql contact table
  3. --delete contact table if already exists DROP TABLE IF EXISTS contact;
  4. MySQL said:
  5. Documentation
  6. 1064 - You have an error in your SQL syntax;
  7. Check the manual that corresponds to your MySQL server version for the right syntax to
  8. use near '--create a mysql contact table --delete contact table if already exists
  9. DROP T' at line 1


我在这些SQL检查器上也得到了相同的错误代码:
http://www.piliapp.com/mysql-syntax-check/http://sqlfiddle.com/的数据库

4xrmg8kj

4xrmg8kj1#

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

ggazkfy8

ggazkfy82#

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

  1. -- 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#

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

  1. --This program will run

字符串
但这会有用的

  1. -- this program will run


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

相关问题