SQL Ct Question
SQL Ct Question
Generalization is a bottom-up approach in which two lower level entities combine to form
a higher level entity. In generalization, the higher level entity can also combine with other
lower level entities to make further higher level entity. It's more like Superclass and
Subclass system, but the only difference is the approach, which is bottom-up. Hence,
entities are combined to form a more generalised entity, in other words, sub-classes are
combined to form a super-class.
generalization in ER model
For example, Saving and Current account types entities can be generalised and an entity
with name Account can be created, which covers both.
Specialization
Specialization is opposite to Generalization. It is a top-down approach in which one higher
level entity can be broken down into two lower level entity. In specialization, a higher
level entity may not have any lower-level entity sets, it's possible.
Specialization in ER Model
Q. Explain Keys.
Keys are attributes or sets of attributes that help in uniquely identifying a record in a
table. Types of keys include:
• Primary Key: Uniquely identifies each record in a table.
• Foreign Key: A field in one table that uniquely identifies a row of another table.
• Candidate Key: A set of attributes that uniquely identify a record.
• Composite Key: A key that consists of two or more attributes.
SQL query
Q. Write a SQL query to fetch employee I'd, full name, of all employees working under the
manager I'd 986.
SELECT EmployeeID, FullName
FROM EmployeeDetails
WHERE ManagerID = 986;
Q. To fetch the different projects available from the employee salary table.
SELECT DISTINCT ProjectName
FROM EmployeeSalary;
Q. To find the employee I'd whose salary lies in the range of 9k and 15k.
SELECT EmployeeID
FROM EmployeeSalary
WHERE Salary BETWEEN 9000 AND 15000;
Q. To fetch those employees who live in toranto and work under the manager and manager
I'd 321.
SELECT EmployeeID, FullName
FROM EmployeeDetails
WHERE City = 'Toronto' AND ManagerID = 321;
Q. To fetch all the employee who either live in California and who work under the work and
work manager 321.
SELECT EmployeeID, FullName
FROM EmployeeDetails
WHERE City = 'California' OR ManagerID = 321;