Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    1

    Composite primary key in ERwin

    Hello, I am fairly new to this field, and I have to learn ERwin for a college class I am taking. My question is, how do I create a composite primary key in ERwin? From what I described to a friend I did it right, however I am having trouble inserting information for example: In 2 tables I have a ProductID, and in one of the tables I "supposedly" have it set so ProductID is a primary key along with another primary key. There are duplicates of the ProductID and SQL wont let me insert multiple ProductID's.

    Here's some of the code I am trying:

    INSERT INTO Product_t (ProductID, ProductDescription)
    VALUES (100, 'Bottle')

    then

    INSERT INTO CREATED_PRODUCT_t (ProductID, ProductPartID)
    VALUES (100, '235')

    INSERT INTO CREATED_PRODUCT_t (ProductID, ProductPartID)
    VALUES (100, '495')

    and it gives me the error message that duplicate keys are not allowed.

    So there is essentially the same ID for the products, but it has different parts,

    Anything suggestions? Thanks in advance!

  2. #2
    Join Date
    Nov 2011
    Posts
    30
    Quote Originally Posted by csnoob View Post
    Hello, I am fairly new to this field, and I have to learn ERwin for a college class I am taking. My question is, how do I create a composite primary key in ERwin? From what I described to a friend I did it right, however I am having trouble inserting information for example: In 2 tables I have a ProductID, and in one of the tables I "supposedly" have it set so ProductID is a primary key along with another primary key. There are duplicates of the ProductID and SQL wont let me insert multiple ProductID's.

    Here's some of the code I am trying:

    INSERT INTO Product_t (ProductID, ProductDescription)
    VALUES (100, 'Bottle')

    then

    INSERT INTO CREATED_PRODUCT_t (ProductID, ProductPartID)
    VALUES (100, '235')

    INSERT INTO CREATED_PRODUCT_t (ProductID, ProductPartID)
    VALUES (100, '495')

    and it gives me the error message that duplicate keys are not allowed.

    So there is essentially the same ID for the products, but it has different parts,

    Anything suggestions? Thanks in advance!
    I've never used the program before, but I may be able to help.

    When doing relationships, there are three you will use: one-to-one, one-to-many, and many-to-many. To me, it sounds like you're trying to do a one-to-many relationship. In order to do that, refer to the following steps:

    1. Create two tables, each should have their own primary key. For example:

    Part (PartID (PK), PartName, Price)
    Distributor (DistributorID, PhoneNumber, Contact)

    2. Define which is the one side, and which is the many. In this case, it would be something like this:

    One distributor can supply many parts.

    3. Move the primary key from the ONE side to the MANY side, so then the tables would now look like this:


    Part (PartID (PK), PartName, Price, DistributorID)
    Distributor (DistributorID, PhoneNumber, Contact)

    I hope this helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •