Question

In: Computer Science

1a) i) Explain the candidate key, primary key and foreign key with suitable examples [6] ii)...

1a) i) Explain the candidate key, primary key and foreign key with suitable examples [6]

ii) Draw a suitable ER diagram to show the “IS-A” relationship between subtype and supertype [5]

iii) Briefly explain the recursive relationship with a suitable example. [2]

Solutions

Expert Solution

i)

A column or group of columns in a table which helps us to uniquely identifies every row in that table is called a primary key.

In the following example, StudID is a Primary Key.

StudID   Roll_No   First_Name   LastName   Email
1       11       Tom           Price       [email protected]
2       12       Nick       Wright       [email protected]
3       13       Dana       Natan       [email protected]

A superkey is a group of single or multiple keys which identifies rows in a table.
A super key with no repeated attribute is called candidate key.
The Primary key should be selected from the candidate keys. Every table must have at least a single candidate key.

In the given table Stud ID, Roll No, and email are candidate keys which help us to uniquely identify the student record in the table.

StudID   Roll_No   First_Name   LastName   Email

1       11       Tom           Price       [email protected]
2       12       Nick       Wright       [email protected]
3       13       Dana       Natan       [email protected]

A foreign key is a column which is added to create a relationship with another table. Foreign keys help us to maintain data
integrity and also allows navigation between two different instances of an entity.

Example
Table Department
DeptCode   DeptName
001           Science
002           English
005           Computer

Table teach
Teacher_ID   Fname   Lname
B002       David   Warner
B017       Sara   Joseph
B009       Mike   Brunton

In this table, adding the foreign key in Deptcode to the Teacher name, we can create a relationship between the two tables.

Teacher_ID   DeptCode   Fname   Lname
B002       002           David   Warner
B017       002           Sara   Joseph
B009       001           Mike   Brunton

ii)

Here Employee is supertype and Hourly_Emps and Contract_Emps

iii)

A relationship has always been between occurrences in two different entities. However, it is possible for the same entity to participate in
the relationship. This is termed a recursive relationship.


Let us take the example of an employee who is also a manager. But a manager is also an employee, whose details will be held in the employee entity. To implement this a foreign key of the employee's manager number would be held in each employee record.

Employee entity
Employee no
Employee surname
Employee forename
Employee DOB
Employee NI number

Manager no * (this is the employee no of the employee's manager)
Graphically, this can be shown as:

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

what is super key,  candidate key, and primary key, and foreign key in terms of database? and...
what is super key,  candidate key, and primary key, and foreign key in terms of database? and plz provide some examples, thanks.
Identify every possible primary key, candidate key, and foreign key for the following relations. Separate each...
Identify every possible primary key, candidate key, and foreign key for the following relations. Separate each key using a semicolon to avoid confusion. Assumptions: MIScompany has branches located in several states within the United States. A customer can be an individual or organization. driverId is the driving license number, ssno is the social security number and upc is the universal product code. Any equipment is rented and returned at the same branch. A customer can be a manufacturer and vice...
Database Problem description:1. What is the difference between a candidate key and the primary key for...
Database Problem description:1. What is the difference between a candidate key and the primary key for a given relation? What is a superkey? 2. What is a foreign key constraint? Why are such constraints important? What is referential integrity? 3. Answer teach of the following questions. The questions are based on the following relational schema:Emp(eid: integer, ename: string, age: integer, salary: real)Works(eid: integer, did: integer, pct_time: integer)Dept(did: integer, dname: string, budget: real, managerid: integer) (1) Write the SQL statements required...
Assuming Database is not providing Referential Integrity Constraints support i-e Primary key, foreign key and Unique...
Assuming Database is not providing Referential Integrity Constraints support i-e Primary key, foreign key and Unique key, your task is to design a database engine with your own built in Referential integrity rules implementation and you need that only one database connection is maintained which an application should access. Recommend proper design pattern used for the stated problem. Give reasons for selecting that pattern, create complete class diagram for the solution. The class diagram should also show the methods of...
(a)     With the aid of suitable diagrams and examples explain the following terms:          (i)           surface...
(a)     With the aid of suitable diagrams and examples explain the following terms:          (i)           surface tension          (ii)          surface free energy          (ii)          surface active agent (surfactant)          (iii)         Krafft point   
i) Explain the types of compensation with examples. ii) Explain the types of information needed by...
i) Explain the types of compensation with examples. ii) Explain the types of information needed by external users with examples.
1. Explain the primary difficulty with evaporation — the reason that it is not suitable for...
1. Explain the primary difficulty with evaporation — the reason that it is not suitable for use in modern CMOS process, which have very small features with etched patterns that have a high aspect ratios.? 2. Regarding the previous question — how does sputtering solve the problem that evaporation suffers from?? 3. Explain the purpose of standard clean that we used when processing the wafers in the lab. (You need an answer that is more detailed than “It cleaned the...
Explain briefly the driving procedure of the following system using suitable diagrams. i. Electrostatic system ii....
Explain briefly the driving procedure of the following system using suitable diagrams. i. Electrostatic system ii. Pneumatic system
For the following schema, provide the following unique/distinct values a) A suitable primary key b) An...
For the following schema, provide the following unique/distinct values a) A suitable primary key b) An example of a different candidate key c) An example of a superkey Accounts(account_id, account_type_code, customer_id, account_name, date_opened, date_closed, current_balance)
what does a primary key and foreign key relates to? Which drive does a magnet damage...
what does a primary key and foreign key relates to? Which drive does a magnet damage the most what the Raid differences ? what a NIC does what is NAS and what's it used for and how it can be used in a network setting which device has a built in antenna what RF is used for (Radio Frequency )
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT