MST Rdbms Quespapers Answer
MST Rdbms Quespapers Answer
Q
Creating an ER (Entity-Relationship) diagram for an organization
involves identifying the entities, attributes, and relationships that
represent the structure and operations of that organization.
Steps to Create an ER Diagram for an Organization
1. Identify Key Entities
Entities are the main components in your system. For an organization,
common entities include:
1.Employee
2.Department
3.Project
4.Client
5.Manager
6.Attendance
7.Salary
2. Determine Attributes for Each Entity
Employee
1.EmpID (Primary Key)
2.Name
3.Address
4.Phone
5.Email
6.DeptID (Foreign Key)
7.SalaryID (Foreign Key)
Department
1.DeptID (Primary Key)
2.DeptName
3.Location
Project
1.ProjectID (Primary Key)
2.ProjectName
3.StartDate
4.DeptID (Foreign Key)
Client
1.ClientID (Primary Key)
2.Name
3.Contact
Salary
1.SalaryID (Primary Key)
2.Amount
3.Bonus
3. Define Relationships Between Entities
1.An employee belongs to one department, but a department can
have many employees →One-to-Many
2.An employee can work on multiple projects and a project can
have multiple employees →Many-to-Many
3.A manager is also an employee (recursive relationship) →
One-to-One or One-to-Many
4.A project is assigned to one department
5.A client can request multiple projects
4. Draw the ER Diagram
Use the following notation:
1.Rectangle = Entity
2.Oval = Attribute
3.Diamond = Relationship
4.Line = Link between them
5.PK = Primary Key
6.FK = Foreign Key
[Department]---------------------------<works
in>-----------------[Employee]
| DeptID (PK) | EmpID (PK)
| DeptName | Name
| Location | DeptID (FK)
|
________________________________|__________________
| |
| |
Assigned>
< <Gets
Paid>
| |
[Project] [Salary]
| ProjectID (PK) | SalaryID
(PK)
| ProjectName | Amount
| DeptID (FK) | Bonus
. LEFT JOIN (or LEFT OUTER JOIN):-Returns all records from the
2
left table and the matched records from the right table. If there's no
NULLis returned for right table columns.
🔸
match,
Syntax:
SELECT *
FROM table1
LEFT JOIN table2
ON table1.common_column = table2.common_column;
Example:
SELECT Students.Name, Departments.DeptName
FROM Students
LEFT JOIN Departments
ON Students.DeptID = Departments.DeptID;
. RIGHT JOIN (or RIGHT OUTER JOIN):- Returns all records from
3
the right table and the matched records from the left table.
Syntax:
SELECT *
FROM table1
RIGHT JOIN table2
N table1.common_column = table2.common_column;
O
Example:
SELECT Students.Name, Departments.DeptName
FROM Students
RIGHT JOIN Departments
ON Students.DeptID = Departments.DeptID;
🔸
carefully.
Syntax:
SELECT *
FROM table1
CROSS JOIN table2;
Example:
SELECT Students.Name, Courses.CourseName
FROM Students
CROSS JOIN Courses;
6. SELF JOIN:-A self join is when a table is joined with itself.
Syntax:
SELECT A.Name, B.Name
FROM Employees A, Employees B
WHERE A.ManagerID = B.EmployeeID;
Use Case:Finding employees who report to the same manager.
. Candidate Key
2
Ans:-A candidate key is a minimal set of attributes that can uniquely
identify a tuple (row) in a relation.
There can be multiple candidate keys in a table, but only one is
chosen as the primary key.
Example:
Studentstable, both
In a RollNumberandEmailcould be
candidate keys.
. Referential Integrity
3
Ans:-Referential Integrity ensures that a foreign key in one table must
match a primary key in another table (or be NULL).
It helps maintain consistency and prevents orphan records.
Example:
Employee.DeptIDreferences
If Department.DeptID , we can't
add an employee with a DeptIDthat doesn't exist in the Department
table.
. Relational Algebra – Set Operations
4
Ans:-Relational Algebra provides theoretical operations for querying
databases. Important set operations include:
1.UNION→ Combines rows from two relations, removing
duplicates
2.INTERSECTION→ Returns common rows from both relations
3.DIFFERENCE (MINUS)→ Returns rows present in the first
relation but not in the second
4.CARTESIAN PRODUCT (×)→ Pairs each row from the first
table with every row from the second table
Note:All set operations require the same number of columns with
compatible data types.
SELECT PROJECTION
QL command to
S elational algebra operation to
R
retrieve data from a select specific columns from a
efinition database.
D relation.
sed in SQL (Structured U
U sed in relational algebra
Context Query Language). (theoretical framework).
ELECT column1,
S
column2 FROM
Syntax table_name; π(column1, column2)(relation)
an include filtering,
C ocuses solely on selecting
F
Complexi sorting, grouping, and columns; does not include
ty joining. filtering or sorting.
etrieves data based on
R
Function specified criteria and can Simply extracts specified
lity
a manipulate the result set. columns from a dataset.
ELECT name, age
S
FROM users WHERE
xample age > 18;
E π(name, age)(users)
an return a result set
C
with various operations eturns a new relation with only
R
Output applied. the specified columns.