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', '[email protected]');
INSERT INTO contact VALUES (1, 'Larry Page', 'Google', '[email protected]');
--displays whats in this
SELECT * FROM contact;
I thought that in sql this is considered a comment: --I'm a comment
However PHPMyAdmin isn't accepting it.
I get 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 get the same error with the same code on these sql checkers also:
http://www.piliapp.com/mysql-syntax-check/ http://sqlfiddle.com/
MySQL Server supports three comment styles: From a # character to the end of the line. From a -- sequence to the end of the line. In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on).
You can view the comments on a particular table or column by querying the data dictionary views USER_TAB_COMMENTS , DBA_TAB_COMMENTS , or ALL_TAB_COMMENTS or USER_COL_COMMENTS , DBA_COL_COMMENTS , or ALL_COL_COMMENTS . Specify the name of the operator to be commented.
You need an interval/space after the --
Otherwise it's not considered a valid comment in MySQL.
You need a space if you use "--" style comments per the manual. Also add a ";" after your create.
-- 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With