0

Error SQL query:

CREATE TABLE Contacts(

Contact_ID INT NOT NULL ,
User VARCHAR NOT NULL ,
User_ID INT( 15 ) ,
PRIMARY KEY ( Contact_ID ) ,
FOREIGN KEY ( User_ID ) REFERENCES Users( User_ID )
)

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 'NOT NULL,
User_ID int(15),
PRIMARY KEY (Contact_ID),
FOREIGN KEY (User_ID) RE' at line 4 

1 Answer 1

4

You need to supply the length of the VARCHAR field, like VARCHAR(64).

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

6 Comments

Yes it worked thank but why ? look at this link here please w3schools.com/sql/sql_foreignkey.asp
The 64 means 64 characters can be stored in that field, you can freely change it.
Just what Erik said. Varchar fields require an explicit length, which becomes the maximum number of characters you can put in the field.
That link has nothing to do with VARCHAR.
The length of INT is optional since it is only about how many digits to display and not about storage length. VARCHAR is different though.
|

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.