Jump to content

Error creating table and inserting data


terryds

Recommended Posts

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 by terryds
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...