Category: Database Systems

Database Relationships Explained

Question I was asked this question in an interview. How do you implement one-to-one, one-to-many, and many-to-many relationships while designing tables Answer one-one relationship is most likely forced by business rules but it does not flow naturally from the data. One can combine both tables into one table without breaking normalization rules. To implement this

SQL All Keyword

All Keyword in SQL Given the following database table: employee(emp_name, emp_salary) write an SQL statement to print the employee name with the highest salary Solution Using the max aggregate function will give us the maximum salary but it does not give us the name of the employee who has the maximum salary. The solution is

SQL Having Clause

Problem You have the following database table: employee (emp_name, emp_age, emp_department) Write an SQL statement to calculate the average age of employees who are older than 30 years old for each department. Do not display the average if the number of employees used in the calculation is less than 3. Solution You need to use

Dependencies in database

Database functional dependencies example Given the relation LDS (L, D, S) with the following functional dependencies definitions: L ->D and (S, D) -> L LDS is decomposed into two relations: LD (L, D) and SL (S, L) which are populated as follows: LD: L1   D1 L2   D2 L3   D1 SL: S1   L1 S2   L2 Inserting the

Sql relational division example

Problem Given the following database tables Employee (SSN, name, location) Assigned (SSN, project_name, duration) Project (project_name, category, budget, location) Write SQL statements to find the following: Project names with a budget smaller than the average budget of projects in a given category let us say "Test Category" Employees who are assigned to all projects with