SQL doesn't accept my comments

I am trying to run this sql query in PHPMyAdmin:

--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', 'bill@micro.com');
INSERT INTO contact VALUES (1, 'Larry Page', 'Google', 'larry@google.com');

--displays whats in this
SELECT * FROM contact;

      

I thought that in sql this counts as a comment: --I'm a comment

However PHPMyAdmin doesn't accept it.

I am getting this error:

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

      

I am getting the same error with the same code in these sql steps also:

http://www.piliapp.com/mysql-syntax-check/ http://sqlfiddle.com/

+3


source to share


2 answers


You need a spacing / space after --



Otherwise, it is not considered a valid comment in MySQL.

+5


source


You need space if you use "-" style comments in the manual. Also add ";" after creation.

-- create a mysql contact table

      

- delete the contact table, if it already exists DROP TABLE, if EXISTS contact;



- create a new table named contact with the fields specified by CREATE TABLE contact (contactID int PRIMARY KEY, name VARCHAR (50), company VARCHAR (30), email VARCHAR (50));

- add them to the table INSERT INTO contact VALUES (0, "Bill Gates", "Microsoft", " bill@micro.com "); INSERT INTO contact VALUES (1, "Larry Page", "Google", " larry@google.com ");

- shows what is in this SELECT * FROM contact;

+1


source







All Articles