0

This is my SQL Script

CREATE TABLE account_profile
(
accnt_id int NOT NULL ,
first_name varchar(255),
last_name varchar(255),
biography varchar(255),
date_joined DATE,
country varchar(255),
gender varchar(255),
screename varchar(255),
path varchar(255),
FOREIGN KEY (accnt_id) REFERENCES accounts(id)
)

it kept giving me this error SQL query:

CREATE TABLE ac

MySQL said:

#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 '' at line 1 

What does this specifically mean? what should I do? from my point of view the script is quite okay,I just can't pin point where's the error

2
  • you code is correct may be your accounts table is not exist. Commented Jun 28, 2012 at 7:51
  • Do you run this code alone or with other stuff (before this one)? I guess you are probably missing something in the previous line, like a ; Commented Jun 28, 2012 at 7:58

3 Answers 3

3

Make sure you're using the InnoDB engine. The other engines do not support foreign keys.

CREATE TABLE account_profile
(
...
) ENGINE = INNODB;

Also check if the column account_profile.accnt_id matches the data type of accounts.id exactly. The second column should have an index defined on it (a primary key will do.)

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

1 Comment

This is marked with phpMyAdmin, if you are using that tool it helps to run the show errors command:dev.mysql.com/doc/refman/5.0/en/show-errors.html
3

I have tested your query and it works with me too. Do you have a query before creating the table account_profile? because if you do, try to check if the query before has been terminated by a semi-colon. like this:

Create table TableName
(
    -- fields list
);  -- <== don't forget this before creating another table again.

CREATE TABLE account_profile
(
    accnt_id int NOT NULL ,
    first_name varchar(255),
    last_name varchar(255),
    biography varchar(255),
    date_joined DATE,
    country varchar(255),
    gender varchar(255),
    screename varchar(255),
    path varchar(255),
    FOREIGN KEY (accnt_id) REFERENCES accounts(id)
);  -- <== and also this.

the error says near line 1.

Comments

2

Probably your table account does not exists :

FOREIGN KEY (accnt_id) REFERENCES accounts(id)

That's why you've got an error, the request is correct otherwise.

1 Comment

I have checked the query, its working fine and me also not have accounts table.

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.