0% found this document useful (0 votes)
44 views5 pages

Strong and Weak Entities in DBMS

This document discusses implementing an entity relationship model for a bus reservation system using tables in a relational database. It describes creating tables for passengers, tickets, and buses, with primary and foreign keys to link the tables. The passenger and ticket tables are linked by a foreign key, and the passenger and bus tables are linked by another foreign key. The aim is represented all entities, keys, and relationships in a tabular format for the bus reservation system.

Uploaded by

Yash Tandon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views5 pages

Strong and Weak Entities in DBMS

This document discusses implementing an entity relationship model for a bus reservation system using tables in a relational database. It describes creating tables for passengers, tickets, and buses, with primary and foreign keys to link the tables. The passenger and ticket tables are linked by a foreign key, and the passenger and bus tables are linked by another foreign key. The aim is represented all entities, keys, and relationships in a tabular format for the bus reservation system.

Uploaded by

Yash Tandon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

Common questions

Powered by AI

Database models, such as the one used in the Bus Reservation System, are vital for organizing and managing complex data structures. They allow for the systematic representation of entities, relationships, and constraints, facilitating efficient data storage, retrieval, and updates. A well-structured database model ensures data integrity and consistency, reduces redundancy, and supports data normalization. By defining relationships through primary and foreign keys, relational data models enable complex queries and reporting, empowering data-driven decisions. This systematized approach simplifies database management by providing clear logical and physical data representations .

A composite key is a primary key composed of two or more attributes that together uniquely identify a record in a table. This type of key is necessary when no single attribute can uniquely identify records in a database. For instance, in a university database, a composite key consisting of 'Student_ID' and 'Course_ID' might be used in the 'Enrollment' table to uniquely identify a student's course registration records, considering that multiple students can enroll in the same course and a single student can enroll in multiple courses .

In an ER diagram, a strong entity is represented by a single rectangle and includes a primary key attribute indicated by an underline. Strong entities are capable of existing independently of other entities. Alternatively, a weak entity is illustrated using a double rectangle, as it lacks a primary key and relies on a 'partial key' from its relationship with a strong entity for identification. The relationship between a strong entity and a weak entity is depicted by a double diamond symbol, denoting an identifying relationship .

Foreign keys play a critical role in relational databases by establishing and enforcing relationships between tables. They are attributes in a table that refer to the primary key of another table, thus enabling the linkage between these tables. This setup avoids orphan records, maintains referential integrity, and ensures that relationships between data entries remain valid. For instance, in a Bus Reservation System, the 'P_id' in the 'Ticket' table serves as a foreign key referencing the 'P_id' in the 'Passenger' table, ensuring that each ticket must be associated with an existing passenger .

A bus reservation system is structured with multiple tables such as 'Passenger', 'Ticket', and 'Bus', where each table manages distinct yet interrelated data. The 'Ticket' table includes a 'P_id' foreign key referencing the 'P_id' primary key in the 'Passenger' table, linking tickets to passengers. Similarly, the 'Passenger' table includes a 'Bus_Alloted' foreign key referencing the 'B_Number' primary key in the 'Bus' table, indicating the passenger's bus allocation. Foreign keys establish these relational links, maintaining data integrity and facilitating queries across the different tables in the system .

Candidate keys are attributes or combinations of attributes that can uniquely identify tuples in a table. They differ from primary keys in that a table may have multiple candidate keys, but only one can be selected as the primary key. Once a primary key is chosen, remaining candidate keys can become alternate keys. An alternate key is any candidate key that is not designated as the primary key but still possesses the unique identification property. Thus, while all primary and alternate keys are candidate keys, not all candidate keys are primary or alternate keys .

When determining entity representation, consider if the entity has a unique attribute (primary key) that can independently identify it. Strong entities have their own primary keys and no dependency on other entities, while weak entities depend on primary keys from related strong entities for identification, implying a partial key and identifying relationship should be used. The context of the relationship, such as the essential nature of the entity's dependency for meaning and data integrity, affects its classification. Consideration should also include the entity's role within the business process, and how its representation affects data normalization and redundancy minimization .

Artificial keys are used when natural keys are unavailable, large, or complex, making them cumbersome for database operations. They provide a simple, unique identifier for each record, enhancing query performance and allowing anonymity in data representation. For example, in a system where privacy is crucial, artificial keys like student IDs in an educational database can ensure data is internally consistent without exposing real-world identifiers. However, they can add to the complexity of the database design and require the generation and maintenance of these keys, which can introduce additional overhead .

A primary key is crucial in a relational database as it uniquely identifies each record within a table, ensuring data integrity and enabling efficient data retrieval. It differs from other keys in that there can only be one primary key per table, while candidate keys can be any attribute(s) that could serve as a primary key. Super keys are superset of candidate keys, and foreign keys refer to primary keys in another table to establish relationships between tables. The primary key forms the basis for relationships among tables and enforces entity integrity, distinguishing it from other key types .

A primary key uniquely identifies each record in a table, such as 'P_id' in the 'Passenger' table, ensuring that each record is distinct. An alternate key is any candidate key not chosen as the primary key, for instance, if 'SSN' in a hypothetical 'Employee' table is not the primary key but uniquely identifies records, it is an alternate key. A super key encompasses sets of attributes that uniquely identify records, being a superset of candidate keys — like a combination of 'Name' and 'P_id' if it also uniquely identifies records in the 'Passenger' table, albeit not minimal .

You might also like