Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Basic pSQL problem

Options
  • 09-04-2005 7:20pm
    #1
    Registered Users Posts: 6,420 ✭✭✭


    I'm trying to populate the final 2 tables in a database of 8.

    The problem im running into happens with both the foreign keys and the primary keys.

    I believe its got something to do with not sequencing the numbers (3 options and selection by 1,2,3) but im having difficulty figuring it out.
    CREATE TABLE Stocks (
    branchnumber VARCHAR(255) REFERENCES Branch,
    productcode VARCHAR(255) REFERENCES Product,
    qtyonhand VARCHAR(255),
    shrinkage VARCHAR(255),

    PRIMARY KEY (branchnumber),

    FOREIGN KEY (productcode)
    REFERENCES Product (barcode)
    );

    Thats how th table is created. The error from the compiler is as follows
    jvaughan3_toystorey=> INSERT INTO Stocks VALUES ('x003', '1034567804003', '11',
    '0');
    INSERT 33718 1
    jvaughan3_toystorey=> INSERT INTO Stocks VALUES ('x003', '1034567804006', '21',
    '1');
    ERROR: duplicate key violates unique constraint "stocks_pkey"

    As you can see, it will accept the first entry but not the second or third or fourth etc. Having never done sequencing im at a loss.
    Any help would be appreciated.

    [Edit] the data types aren't too important. Its just required to display the items within the database when a Query is run[/Edit]


Comments

  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    Your setting branchnumber up to be both primary & foreign key. As a PK it will be unique and your insertion of 'x003' violates the PK's unique property


Advertisement