Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Co202 Dbms Lab Assignment - 04: Strong Entity

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

CO202 DBMS LAB

Assignment - 04

AIM: To represent all the entities (Strong & Weak), keys (Primary & Foreign) and
relationships in a tabular fashion for a Bus Reservation System.

THEORY:

Strong entity
● Simply strong entity is nothing but an entity set having a primary key attribute
or a table which consists of a primary key column
● The primary key of the strong entity is represented by underlining it

Representation
○ The strong entity is represented by a single rectangle.
○ Relationship between two strong entities is represented by a single
diamond.

Weak entity
● A weak entity is an entity set that does not have sufficient attributes for Unique
Identification of its records
● Simply a weak entity is nothing but an entity which does not have a primary key
attribute

Representation
○ A double rectangle is used for representing a weak entity set
○ The double diamond symbol is used for representing the relationship
between a strong entity and weak entity which is known as identifying
relationship.

Keys

● Keys play an important role in the relational database.


● It is used to uniquely identify any record or row of data from the table. It is also
used to establish and identify relationships between tables.

Types of keys:

1. Primary key

● It is the first key used to identify one and only one instance of an entity uniquely.
An entity can contain multiple keys, as we saw in the PERSON table. The key
which is most suitable from those lists becomes a primary key.

● In the EMPLOYEE table, ID can be the primary key since it is unique for each
employee.

2. Candidate key
● A candidate key is an attribute or set of attributes that can uniquely identify a
tuple.

● Except for the primary key, the remaining attributes are considered a candidate
key. The candidate keys are as strong as the primary key.
For example: In the EMPLOYEE table, id is best suited for the primary key. The rest of
the attributes, like SSN, Passport_Number, License_Number, etc., are considered a
candidate key.

3. Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a
superset of a candidate key.

4. Foreign key

● Foreign keys are the column of the table used to point to the primary key of
another table.

● We add the primary key of the DEPARTMENT table, Department_Id, as a new


attribute in the EMPLOYEE table.

● In the EMPLOYEE table, Department_Id is the foreign key, and both the tables
are related.
5. Alternate key

Out of all candidate keys, one key is chosen as the primary key, and the remaining
candidate key, if it exists, is termed the alternate key. In other words, the total number
of the alternate keys is the total number of candidate keys minus the primary key. The
alternate key may or may not exist.

6. Composite key

Whenever a primary key consists of more than one attribute, it is known as a


composite key. This key is also known as the Concatenated Key.

7. Artificial key

The key created using arbitrarily assigned data are known as artificial keys. These keys
are created when a primary key is large and complex and has no relationship with
many other relations.

IMPLEMENTATION OF BUS RESERVATION SYSTEM :


Creation of Passenger Table
Create table Passenger(
P_id int(5) Primary key, Name varchar(100) not null, Address varchar(200),
Contact_no varchar(100) not null, DOB date, Age int(3));
Creation of Ticket Table
Create table Ticket(
T_Number char(10), T_Id char(10) primary key, T_Date date not null, T_Price int(10)
not null, Source varchar(100) not null, Destination varchar(100) not null);

Creation of Bus Table


Create table Bus(
B_Number varchar(10) primary key, Arrival_time time not null, Total_Seats int(3) not
null, Seats_left int(3) not null, Bus_Route varchar(200), Has_AC tinyint(1));
Creation of Foreign key in Ticket Table
Then I added a new column in the table ticket and declared it as foreign key.
Alter table ticket add column P_id int(5);
Alter table ticket add foreign key(P_id) references passenger(P_id);

Creation of Foreign key in Passenger Table


Then I added a new column in the table Passenger and declared it as foreign key.
Alter table Passenger add column Bus_Alloted varchar(10);
Alter table Passenger add foreign key(Bus_Alloted) references bus(B_Number);

RESULT:
We have successfully implemented the ER Model for Bus Reservation System.

You might also like