0

I am creating a table where it has a foreign key so that it would be linked to another table, but it kept me giving this error, I already checked the syntax on w3schools, but I still keep getting errors any idea why? here's my SQL script

CREATE TABLE user_profile
(
user_Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
accnt_id INT,
first_name varchar(255),
last_name varchar(255),
biography TEXT,
date_joined DATETIME,
date_of_birth DATE,
email varchar(255),
gender varchar(255),
screenname varchar(255)
country varchar(255),
FOREIGN KEY (accnt_Id) REFERENCES accounts(accnt_Id)
)

Here's the error

#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 'country varchar(255), FOREIGN KEY (accnt_Id) REFERENCES accounts(accnt_Id) )' at line 13
4
  • 1
    a. does the accounts table have accnts_Id field. b. both the tables have InnoDB engine? Commented Jun 23, 2012 at 9:21
  • I am using the one in PHPmyadmin, with the latest build Commented Jun 23, 2012 at 9:21
  • @T-ShirtDude the accounts table has an innoDB engine, this table I don't know since I am creating it manually through my script Commented Jun 23, 2012 at 9:25
  • 3
    The syntax error is before the constraint, right before "country" Commented Jun 23, 2012 at 9:29

2 Answers 2

3

You are missing , behind screenname varchar(255) change it to

screenname varchar(255),

and it should works.

Sign up to request clarification or add additional context in comments.

2 Comments

wouldn't it be in front of screename?
no man, it must be how i wrote. screenname is not last column so then behind declaration of column must be comma.
0

You are missing a comma after the 'screenname' column

CREATE TABLE user_profile
(
    user_Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    accnt_id INT,
    first_name varchar(255),
    last_name varchar(255),
    biography TEXT,
    date_joined DATETIME,
    date_of_birth DATE,
    email varchar(255),
    gender varchar(255),
    screenname varchar(255),
    country varchar(255),
    FOREIGN KEY (accnt_Id) REFERENCES accounts(accnt_Id)
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.