unknown error and filling data in MySQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Norgy
    New Member
    • May 2013
    • 56

    unknown error and filling data in MySQL

    Code:
    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 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?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Your foreign key syntax is wrong. You didn't tell it which fields the foreign key is on.

    Comment

    • Norgy
      New Member
      • May 2013
      • 56

      #3
      could you explain more please :$

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

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

        The syntax is:
        Code:
        CREATE TABLE someTable
         (
         field definitions,
         FOREIGN KEY (field in this table) REFERENCES otherTable(field in other table)
         )

        Comment

        • Norgy
          New Member
          • May 2013
          • 56

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

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            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.

            Comment

            • Norgy
              New Member
              • May 2013
              • 56

              #7
              ok, thank you very much :)

              Comment

              Working...