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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Basic pSQL problem

  • 09-04-2005 6:20pm
    #1
    Registered Users, Registered Users 2 Posts: 6,423 ✭✭✭


    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: 41,647 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