JayNaz
JayNaz

Reputation: 363

Composite Foreign key in ORACLE

I an trying to convert database schema into Database in ORACLE SQL

Books (BookID,PubID,Title,Author,Price,Availability)

Publisher (PubID,Name,Address,BookID)

Member (MemberID,Name,Address,MemberType,MemberDate,ExpiryDate)

Barrowings (MemberID,BookID,IssuedDate,ReturnDate,DueDate)

I have done first 3 tables. But i have a problem with the 4th table (Borrowings) (MemberID,BookID,IssueDate) I want to make first 2 columns (MemberID,BookID) as a composite foreign key (Should refere 2 different tables)

MemberID referes the MemberID colimn in Member table BookID referes the BookID table in Books table. IssiedDate column is the primary key of that table How to make a composite foreign key in ORACLE SQL

Upvotes: 0

Views: 1155

Answers (2)

Kashiling Kharat
Kashiling Kharat

Reputation: 1

Create table borrowings( MemberID varchar2(20) constraint fk_memid reference member(MemberID), BookID varchar2(20) constraint fk_bookid reference Books(BookID) )

For this purpose first you have to give primary key or Unique on patent tables columns. I.e BookID column from books and memberid column from members..

Upvotes: 0

Durga Viswanath Gadiraju
Durga Viswanath Gadiraju

Reputation: 3966

You cannot create one foreign key referring to 2 parent tables.

In this case you need to create 2 foreign key constraints, one to BOOKS and other to MEMBER.

Upvotes: 1

Related Questions