By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,337 Members | 2,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,337 IT Pros & Developers. It's quick & easy.

unknown error and filling data in MySQL

P: 56
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `norm`.`sphone` (
  2.   `sid` INT NOT NULL,
  3.   `phone` VARCHAR(45) NOT NULL,
  4.   PRIMARY KEY (`sid`, `phone`),
  5.   CONSTRAINT `sid`
  6.     FOREIGN KEY ()
  7.     REFERENCES `norm`.`staff` ()
  8.     ON DELETE RESTRICT
  9.     ON UPDATE RESTRICT);
i am new with MySQL , and when this code is executed, it gives me this error
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 ')

REFERENCES `norm`.`staff` ()

ON DELETE RESTRICT

ON UPDATE RESTRICT' at line 6

SQL Statement:

CREATE TABLE `norm`.`sphone` (

`sid` INT NOT NULL,

`phone` VARCHAR(45) NOT NULL,

PRIMARY KEY (`sid`, `phone`),

CONSTRAINT `sid`

FOREIGN KEY ()

REFERENCES `norm`.`staff` ()

ON DELETE RESTRICT

ON UPDATE RESTRICT)

i can not understand the error and don't know how to solve it?
also, would anyone tell me how to fill the tables with data?
Jan 24 '14 #1

✓ answered by Rabbit

A foreign key links a field in one table to another field in another table. You didn't specify those fields.

The syntax is:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE someTable
  2.  (
  3.  field definitions,
  4.  FOREIGN KEY (field in this table) REFERENCES otherTable(field in other table)
  5.  )

Share this Question
Share on Google+
6 Replies


Rabbit
Expert Mod 10K+
P: 12,366
Your foreign key syntax is wrong. You didn't tell it which fields the foreign key is on.
Jan 24 '14 #2

P: 56
could you explain more please :$
Jan 24 '14 #3

Rabbit
Expert Mod 10K+
P: 12,366
A foreign key links a field in one table to another field in another table. You didn't specify those fields.

The syntax is:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE someTable
  2.  (
  3.  field definitions,
  4.  FOREIGN KEY (field in this table) REFERENCES otherTable(field in other table)
  5.  )
Jan 24 '14 #4

P: 56
solved, thanks a lot :)
now, i don't know how to fill the tables with data?
Jan 24 '14 #5

Rabbit
Expert Mod 10K+
P: 12,366
We limit the threads to one question per. Please create a new thread for your new question.

As a side note, inserting data is one of the basic SQL tasks, you should probably read a tutorial.
Jan 24 '14 #6

P: 56
ok, thank you very much :)
Jan 24 '14 #7

Post your reply

Sign in to post your reply or Sign up for a free account.