terryds Posted July 8, 2013 Share Posted July 8, 2013 (edited) This is my code CREATE TABLE author IF NOT EXISTS(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30) NOT NULL ); CREATE TABLE post IF NOT EXISTS (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, text TEXT, date DATE, authorid INT, FOREIGN KEY(authorid) REFERENCES author (id) ON DELETE CASCADE ON UPDATE CASCADE ); INSERT INTO author ('name') VALUES ('Andi'), ('Budi'), ('Amir');INSERT INTO post ('text','date','authorid') VALUES('aaaa', CURDATE(), '1'),('bbbb', CURDATE(), '2'),('ccc', CURDATE(), '3'); Can you please help me fix the error ? Edited July 8, 2013 by terryds Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2013 Share Posted July 8, 2013 What does the error say? Link to comment Share on other sites More sharing options...
terryds Posted July 9, 2013 Author Share Posted July 9, 2013 This is what it says #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 'IF NOT EXISTS(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHA' at line 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted July 9, 2013 Share Posted July 9, 2013 "IF NOT EXISTS" goes before the table name, not after it. http://dev.mysql.com/doc/refman/5.1/en/create-table.html 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now