0

I have created table like this

   CREATE TABLE profile_contact
(
profile_id     INT UNSIGNED NOT NULL, 
service        CHAR(20) NOT NULL, 
contact_name   CHAR(25) NOT NULL, 
);

Then latter I want to insert the rows from mysql

mysql> INSERT INTO profile_contact
    -> (profile_id,service,contact_name)
    -> VALUES
    -> (1,AIM,user1-aimid),
    -> (1,MSN,user1-msnid),
    -> (2,AIM,user2-aimid),
    -> (2,MSN,user2-msnid),
    -> (2,Yahoo,user2-yahooid)
    -> (4,Yahoo,user4-yahooid);

But I got error

ERROR 1064 (42000): 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 '(4,Yahoo,user4-yahooid)' at line 9

I have followed standard INSERT INTO VALUES syntax.What is wrong?

MishaVacic
  • 1,812
  • 8
  • 25
  • 29
  • Possible duplicate of [How can I fix MySQL error #1064?](https://stackoverflow.com/questions/23515347/how-can-i-fix-mysql-error-1064) – axiac Jul 29 '17 at 08:17

1 Answers1

3

Your script is missing a comma after the second last value (2,Yahoo,user2-yahooid) and hence, the error. Below should work:

CREATE TABLE profile_contact(
profile_id     INT UNSIGNED NOT NULL, 
service        CHAR(20) NOT NULL, 
contact_name   CHAR(25) NOT NULL
);

INSERT INTO profile_contact
-> (profile_id,service,contact_name)
-> VALUES
-> (1,'AIM','user1-aimid'),
-> (1,'MSN','user1-msnid'),
-> (2,'AIM','user2-aimid'),
-> (2,'MSN','user2-msnid'),
-> (2,'Yahoo','user2-yahooid'),
-> (4,'Yahoo','user4-yahooid');

P.S. last column in CREATE statement should not have comma after it, however, I believe it's not the full CREATE script. Also, values like AIM etc should be enclosed in quotes.

Here's the SQL Fiddle.

Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102