Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement and insert value SQL specialization/generalization

Tags:

I have my table with these 3 entities: student, lecturer and person. Person will be the parent that holds common attributes of student and lecturer. This is my database design, is this a correct way of implementing specialization?

Person

personID int Primary key,
Role varchar(10) ,
Name varchar(50),
email varchar(255)

Student

studentID int,
intake varchar(50),
major varchar( 50) ,
personID int reference person(personID)

Lecturer

LecturerID int ,
Skill varchar(50),
Qualification varchar(50) ,
personID int reference person(personID)

The above of the table, is this the correct way to implement generalization/specialization ? If it is, How do I insert a new value to the database when a new student enrolls?

like image 527
hiboss Avatar asked May 15 '16 09:05

hiboss


People also ask

What is SQL Generalization?

Generalization is the process of extracting common properties from a set of entities and create a generalized entity from it. It is a bottom-up approach in which two or more entities can be generalized to a higher level entity if they have some attributes in common.

What is Generalization specialization?

Number: Generalization involves multiple entities and combines them into a generalized entity. Specialization involves a single entity broken down into multiple sub-entities. Size: Generalization reduces the schema of the data by unifying components. Specialization expands the schema by multiplying the components.

How do you represent Generalization in an ER diagram?

A diamond notation is a common representation of specialization/generalization relationships in ER diagrams.

What are the four possible constraints on specialization and Generalization?

Hence, we have four types of specialization/generalization: Disjoint, total. Disjoint, partial. Overlapping, total.


1 Answers

You generally have the right idea (or, at least, one of the common idioms to implement such a database schema). If your rdbms supports it, I'd use an enum for the role column (MySQL, e.g., does. MS SQL Server does not). If it doesn't I'd add a check constraint to achieve a similar effect and make sure you don't get any junk inserted there.

Insertion should be done to the base table (person) first and only then to the specialization tables (student or lecturer). E.g.:

INSERT INTO person 
VALUES (1, 'student', 'hiboss', '[email protected]');

INSERT INTO student
VALUES (100, 'intake', 'computer science', 1);
like image 189
Mureinik Avatar answered Sep 28 '22 03:09

Mureinik