1

I have been given an ERD of a database that I need to create in PostgreSQL. Shown below.

Daterbase ERD

As you can see on the table Enroll, there are two primary keys that are also foreign keys as well that need to be in that table, how would I go about creating this table this is what I have so far,

create table enroll( 
 class_code varchar(15) primary key references class(class_code), 
 trn_num int primary key references TRAINEE(trn_num), 
 enroll_date date, 
 enroll_grade int
);

Many thanks in advance for any help!

3
  • 2
    This sounds like homework, but here's a hint - there's not two primary keys, there's one primary key consisting of two columns. Commented Jan 24, 2019 at 14:39
  • University work, brilliant, I think I know what you are talking about! Cheers for the help! @EricPetroelje Commented Jan 24, 2019 at 14:41
  • Unique Constraint does not work? Commented Jan 24, 2019 at 14:49

1 Answer 1

5

Answer: Create a composite primary key.

create table enroll( 
   class_code varchar(15) references class(class_code), 
   trn_num int  references TRAINEE(trn_num),
   enroll_date date, 
   enroll_grade int,
   primary key(class_code, trn_num)

);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.