If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Composite primary key in ERwin

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-22-11, 21:13
csnoob csnoob is offline
Registered User
 
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!
Reply With Quote
  #2 (permalink)  
Old 11-23-11, 23:50
Martin22 Martin22 is offline
Registered User
 
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!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On