Many of us knew about the primary key importance. A Primary key is unique identifier for the rows in the table, so by using primary key we can easily find the unique row from a table. but when we have more than one column having the property to be mark as primary key then we go for composite primary key.
Syntax :
create table <Table_name>(column1 Datatype(size), column2 Datatype(size)....column_n Datatype(size) primary key(column1,column2));
Lets have a scenario when we have to go for a composite key. We have to design a database for Library.
So, for a Library database we will have following tables.
Author_detailsSyntax :
create table <Table_name>(column1 Datatype(size), column2 Datatype(size)....column_n Datatype(size) primary key(column1,column2));
Lets have a scenario when we have to go for a composite key. We have to design a database for Library.
So, for a Library database we will have following tables.
- Book_Master
- Author_details
- Publisher_details
- Staff-details
- Student_details
- Book_details
- Book_issue_details
COLUMN_NAME
|
DATA TYPE
|
CONSTRAINTS
|
ISBN
|
NUMBER
|
PRIMARY KEY
|
BOOK_ID
|
NUMBER
|
PRIMARY KEY
|
PRICE
|
NUMBER
|
|
PURCHACE_DATE
|
DATE
|
COLUMN_NAME
|
DATA TYPE
|
CONSTRAINTS
|
AUTHOR_ID
|
NUMBER
|
PRIMARY KEY
|
AUTHOR_NAME
|
VARCHAR
|
Publisher_details
COLUMN_NAME
|
DATA TYPE
|
CONSTRAINTS
|
PUB_ID
|
NUMBER
|
PRIMARY KEY
|
PUB_NAME
|
VARCHAR
|
Staff_details
COLUMN_NAME
|
DATA TYPE
|
CONSTRAINTS
|
STAFF_ID
|
NUMBER
|
PRIMARY KEY
|
STAFF_NAME
|
VARCHAR
|
|
DESIGNATION
|
VARCHAR
|
|
DEPARTMENT
|
Book_details
COLUMN_NAME
|
DATA TYPE
|
CONSTRAINTS
|
ISBN
|
NUMBER
|
FOREIGN KEY
|
BOOK_NAME
|
VARCHAR
|
|
AUTHOR_ID
|
NUMBER
|
FOREIGN KEY
|
PUB_ID
|
NUMBER
|
FOREIGN KEY
|
COPIES
|
NUMBER
|
Book_issue_details
COLUMN_NAME
|
DATA TYPE
|
CONSTRAINTS
|
ISBN
|
NUMBER
|
FOREIGN KEY
|
BOOK_ID
|
NUMBER
|
|
STUDENT_ID
|
NUMBER
|
FOREIGN KEY
|
ISSUE_DATE
|
DATE
|
|
ISSUDED_BY
|
VARCHAR
|
FOREIGN KEY
|