SlideShare a Scribd company logo
1 of 7
Question:
[A] Table Creation
Create a table according to the schema given below. Choose the appropriate data types while
creating the table. Insert the records given in Table 1 into the Employee table. And, write SQL
queries to satisfy the questions given below.
Employee (Emp_ID, Emp_Name, DoB, Department, Designation, DoJ, Salary)
Here, DoB means Date of Birth, DoJ means Date of Joining.
Emp_ID Emp_Name DoB Department Designation DoJ Salary
F110 Sam 15-JUN-
1970
Bio-
Technology
Professor 12-APR-
2001
45000
F111 Kumar 25-MAY-
1980
Mechanical Asst. Prof. 02-MAY-
2006
30000
F115 Raguvaran 10-AUG-
1982
CSE Asst. Prof. 05-MAY-
2007
27000
F114 Jennifer 10-SEP-
1975
CSE Asst. Prof. 03-JUN-
2004
35000
F117 Ismail 15-MAY-
1979
IT Asst. Prof. 10-MAY-
2005
33000
Table 1 – Employee
[B] Queries
1. Display all the records from table Employee.
2. Find all the employees who are working for CSE department.
3. Get the details about the employees who have joined after ’10-JUN-2005’.
4. Find all the employees who earn more than 30000.
5. Get the details of employees who are not ‘Professor’.
6. Find the name, date of birth, and designation of all the employees who work for ‘IT’ department.
7. Find all the departments which are offering salary above 25000.
8. Get the DoB of employee named ‘Kumar’.
9. Find the names and departments of employees who earn the salary in the range 20000 to 40000.
10. Find the employee details of any employee who work for ‘CSE’ and earn more than 30000.
Let us assume a table User_Personal as given below;
UserID U_email Fname Lname City State Zip
MA12 Mani@ymail.com MANISH JAIN BILASPUR CHATISGARH 458991
PO45 Pooja.g@gmail.co POOJA MAGG KACCH GUJRAT 832212
LA33 Lavle98@jj.com LAVLEEN DHALLA RAIPUR CHATISGARH 853578
CH99 Cheki9j@ih.com CHIMAL BEDI TRICHY TAMIL NADU 632011
DA74 Danu58@g.com DANY JAMES TRICHY TAMIL NADU 645018
A. Is this table in First Normal Form?
Yes. All the attributes contain only atomic values.
 Is this table in Second Normal Form?
To verify this property, we need to find all the functional dependencies which are holding
in User_Personal table, and have to identify a Primary key.
Let us do that by using the sample data. This leads to the following set of FDs;
F = { UserID → U_email Fname Lname City State Zip,
Zip → City State }
As UserID attribute can uniquely determine all the other attributes, we can have UserID
as the Primary key for User_Personal table.
The next step is to check for the 2NF properties;
Property 1 – The table should be in 1NF.
Property 2 – There should not be any partial key dependencies.
Our table is in 1NF, hence property 1 is holding.
Primary key of our table is UserID and UserID is single simple attribute. As the key is
not composite, there is no chance for partial key dependency to hold. Hence property
2 is also holding.
User_Personal table is in 2NF.
 Is User_Personal in 3NF?
To verify this we need to check the 3NF properties;
Property 1 – Table should be in 2NF.
Property 2 – There should not be any Transitive Dependencies in the table.
Table User_Personal is in 2NF, hence property 1 is satisfied.
User_Personal table holds the following Transitive dependency;
UserID → Zip, Zip → City State
Hence, property 2 is not satisfied and the table is not in 3NF.
Solution:
Decompose User_Personal. For this, we can use the functional dependencies Zip → City
State and UserID → U_email Fname Lname City State Zip.
As a result, we can have the following tables (primary keys are underlined);
User_Personal (UserID, U_email, Fname, Lname, Zip)
City (Zip, City, State)
UserID U_email Fname Lname Zip
MA12 Mani@ymail.com MANISH JAIN 458991
PO45 Pooja.g@gmail.co POOJA MAGG 832212
LA33 Lavle98@jj.com LAVLEEN DHALLA 853578
CH99 Cheki9j@ih.com CHIMAL BEDI 632011
DA74 Danu58@g.com DANY JAMES 645018
Table - User_Personal
Zip City State
458991 BILASPUR CHATISGARH
832212 KACCH GUJRAT
853578 RAIPUR CHATISGARH
632011 TRICHY TAMIL NADU
645018 TRICHY TAMIL NADU
Table – City
Both tables are in 3NF.
Hence, tables are normalized to Third Normal Form.
S Q L P r a c t i c e Q u e s t i o n s - S o l u t i o n
1.For the following relation schema:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)
Give an expression in SQL for each of the following queries:
B. Find the names, street address, and cities of residence for all employees who work
for 'First Bank Corporation' and earn more than $10,000.
select employee.employee-name, employee.street, employee.city fromemployee,
workswhere employee.employee-name=works.employee-name and company-
name = 'First Bank Corporation' and salary > 10000)
b)
Find the names of all employees in the database who live in the same cities as thecompaniesfor
whichtheywork.
select e.employee-namefrom employee e, works w, company cwhere e.employee-name =
w.employee-name and e.city = c.city and w.company-name = c.company-name
c)
Find the names of all employees in the database who live in the same cities and on thesame
streets as do their managers.
select p.employee-namefrom employee p, employee r, manages mwhere p.employee-name =
m.employee-name and m.manager-name =r.employee-
name and p.street = r.street and p.city = r.city
d)
Find the names of all employees in the database who do not work for 'First
Bank Corporation'. Assume that all people work for exactly one company.
select employee-namefrom workswhere company-name <> 'First Bank Corporation'
e)
Find the names of all employees in the database who earn more than every employeeof 'Small
Bank Corporation'. Assume that all people work for at most one company.
select employee-namefrom workswhere salary > all (select salary from works where company-
name = 'Small Bank Corporation')
f)
Assume that the companies may be located in several cities. Find all companieslocated in every
city in which 'Small Bank Corporation' is located.
select s.company-namefrom company swhere not exists((select city from company where
company-name = 'Small BankCorporation')except(select city from company t where s.company-
name = t.company-name))
g)
Find the names of all employees who earn more than the average salary of allemployees of their
company. Assume that all people work for at most one company.
select employee-namefrom works twhere salary >(select avg(salary) from works
s where t.company-name = s.company-name)
h)
Find the name of the company that has the smallest payroll.
select company-namefrom worksgroup by company-namehaving sum(salary) <= all (select
sum(salary) from works group by company-name)
Exercise 1.docx
Exercise 1.docx

More Related Content

Similar to Exercise 1.docx

assigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docx
assigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docxassigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docx
assigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docx
fredharris32
 
Please accept this assignment if youre good in SQL!Task.docx
Please accept this assignment if youre good in SQL!Task.docxPlease accept this assignment if youre good in SQL!Task.docx
Please accept this assignment if youre good in SQL!Task.docx
needhamserena
 
template ltclass Tgt struct nodeType T data n.pdf
template ltclass Tgt struct nodeType      T data     n.pdftemplate ltclass Tgt struct nodeType      T data     n.pdf
template ltclass Tgt struct nodeType T data n.pdf
aceautomate
 

Similar to Exercise 1.docx (20)

Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
newsql
newsqlnewsql
newsql
 
assigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docx
assigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docxassigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docx
assigAssignment 2.docxAssignment 2 LASA 1 Designing a Human.docx
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
FD.pdf
FD.pdfFD.pdf
FD.pdf
 
Dbms question
Dbms questionDbms question
Dbms question
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
 
CSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL QuestionCSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL Question
 
Advanced functions visual Basic .net
Advanced functions visual Basic .netAdvanced functions visual Basic .net
Advanced functions visual Basic .net
 
5. R basics
5. R basics5. R basics
5. R basics
 
Iowa_Report_2
Iowa_Report_2Iowa_Report_2
Iowa_Report_2
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
Please accept this assignment if youre good in SQL!Task.docx
Please accept this assignment if youre good in SQL!Task.docxPlease accept this assignment if youre good in SQL!Task.docx
Please accept this assignment if youre good in SQL!Task.docx
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Spufi
SpufiSpufi
Spufi
 
Relational database intro for marketers
Relational database intro for marketersRelational database intro for marketers
Relational database intro for marketers
 
Internal tables in sap
Internal tables in sapInternal tables in sap
Internal tables in sap
 
Mca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsMca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql concepts
 
template ltclass Tgt struct nodeType T data n.pdf
template ltclass Tgt struct nodeType      T data     n.pdftemplate ltclass Tgt struct nodeType      T data     n.pdf
template ltclass Tgt struct nodeType T data n.pdf
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Exercise 1.docx

  • 1. Question: [A] Table Creation Create a table according to the schema given below. Choose the appropriate data types while creating the table. Insert the records given in Table 1 into the Employee table. And, write SQL queries to satisfy the questions given below. Employee (Emp_ID, Emp_Name, DoB, Department, Designation, DoJ, Salary) Here, DoB means Date of Birth, DoJ means Date of Joining. Emp_ID Emp_Name DoB Department Designation DoJ Salary F110 Sam 15-JUN- 1970 Bio- Technology Professor 12-APR- 2001 45000 F111 Kumar 25-MAY- 1980 Mechanical Asst. Prof. 02-MAY- 2006 30000 F115 Raguvaran 10-AUG- 1982 CSE Asst. Prof. 05-MAY- 2007 27000 F114 Jennifer 10-SEP- 1975 CSE Asst. Prof. 03-JUN- 2004 35000 F117 Ismail 15-MAY- 1979 IT Asst. Prof. 10-MAY- 2005 33000 Table 1 – Employee [B] Queries 1. Display all the records from table Employee. 2. Find all the employees who are working for CSE department. 3. Get the details about the employees who have joined after ’10-JUN-2005’. 4. Find all the employees who earn more than 30000. 5. Get the details of employees who are not ‘Professor’. 6. Find the name, date of birth, and designation of all the employees who work for ‘IT’ department. 7. Find all the departments which are offering salary above 25000. 8. Get the DoB of employee named ‘Kumar’. 9. Find the names and departments of employees who earn the salary in the range 20000 to 40000. 10. Find the employee details of any employee who work for ‘CSE’ and earn more than 30000.
  • 2. Let us assume a table User_Personal as given below; UserID U_email Fname Lname City State Zip MA12 Mani@ymail.com MANISH JAIN BILASPUR CHATISGARH 458991 PO45 Pooja.g@gmail.co POOJA MAGG KACCH GUJRAT 832212 LA33 Lavle98@jj.com LAVLEEN DHALLA RAIPUR CHATISGARH 853578 CH99 Cheki9j@ih.com CHIMAL BEDI TRICHY TAMIL NADU 632011 DA74 Danu58@g.com DANY JAMES TRICHY TAMIL NADU 645018 A. Is this table in First Normal Form? Yes. All the attributes contain only atomic values.  Is this table in Second Normal Form? To verify this property, we need to find all the functional dependencies which are holding in User_Personal table, and have to identify a Primary key. Let us do that by using the sample data. This leads to the following set of FDs; F = { UserID → U_email Fname Lname City State Zip, Zip → City State } As UserID attribute can uniquely determine all the other attributes, we can have UserID as the Primary key for User_Personal table. The next step is to check for the 2NF properties; Property 1 – The table should be in 1NF. Property 2 – There should not be any partial key dependencies. Our table is in 1NF, hence property 1 is holding. Primary key of our table is UserID and UserID is single simple attribute. As the key is not composite, there is no chance for partial key dependency to hold. Hence property 2 is also holding. User_Personal table is in 2NF.
  • 3.  Is User_Personal in 3NF? To verify this we need to check the 3NF properties; Property 1 – Table should be in 2NF. Property 2 – There should not be any Transitive Dependencies in the table. Table User_Personal is in 2NF, hence property 1 is satisfied. User_Personal table holds the following Transitive dependency; UserID → Zip, Zip → City State Hence, property 2 is not satisfied and the table is not in 3NF. Solution: Decompose User_Personal. For this, we can use the functional dependencies Zip → City State and UserID → U_email Fname Lname City State Zip. As a result, we can have the following tables (primary keys are underlined); User_Personal (UserID, U_email, Fname, Lname, Zip) City (Zip, City, State) UserID U_email Fname Lname Zip MA12 Mani@ymail.com MANISH JAIN 458991 PO45 Pooja.g@gmail.co POOJA MAGG 832212 LA33 Lavle98@jj.com LAVLEEN DHALLA 853578 CH99 Cheki9j@ih.com CHIMAL BEDI 632011 DA74 Danu58@g.com DANY JAMES 645018 Table - User_Personal Zip City State 458991 BILASPUR CHATISGARH 832212 KACCH GUJRAT 853578 RAIPUR CHATISGARH 632011 TRICHY TAMIL NADU 645018 TRICHY TAMIL NADU Table – City Both tables are in 3NF. Hence, tables are normalized to Third Normal Form.
  • 4. S Q L P r a c t i c e Q u e s t i o n s - S o l u t i o n 1.For the following relation schema: employee(employee-name, street, city) works(employee-name, company-name, salary) company(company-name, city) manages(employee-name, manager-name) Give an expression in SQL for each of the following queries: B. Find the names, street address, and cities of residence for all employees who work for 'First Bank Corporation' and earn more than $10,000. select employee.employee-name, employee.street, employee.city fromemployee, workswhere employee.employee-name=works.employee-name and company- name = 'First Bank Corporation' and salary > 10000) b) Find the names of all employees in the database who live in the same cities as thecompaniesfor whichtheywork. select e.employee-namefrom employee e, works w, company cwhere e.employee-name = w.employee-name and e.city = c.city and w.company-name = c.company-name c) Find the names of all employees in the database who live in the same cities and on thesame streets as do their managers. select p.employee-namefrom employee p, employee r, manages mwhere p.employee-name = m.employee-name and m.manager-name =r.employee- name and p.street = r.street and p.city = r.city d) Find the names of all employees in the database who do not work for 'First Bank Corporation'. Assume that all people work for exactly one company. select employee-namefrom workswhere company-name <> 'First Bank Corporation' e) Find the names of all employees in the database who earn more than every employeeof 'Small Bank Corporation'. Assume that all people work for at most one company. select employee-namefrom workswhere salary > all (select salary from works where company- name = 'Small Bank Corporation') f) Assume that the companies may be located in several cities. Find all companieslocated in every city in which 'Small Bank Corporation' is located.
  • 5. select s.company-namefrom company swhere not exists((select city from company where company-name = 'Small BankCorporation')except(select city from company t where s.company- name = t.company-name)) g) Find the names of all employees who earn more than the average salary of allemployees of their company. Assume that all people work for at most one company. select employee-namefrom works twhere salary >(select avg(salary) from works s where t.company-name = s.company-name) h) Find the name of the company that has the smallest payroll. select company-namefrom worksgroup by company-namehaving sum(salary) <= all (select sum(salary) from works group by company-name)