Add a new check on the emp table to make sure that any new employee inserted has sex either
'M' or 'F'. Create a new table called highway, with columns: empid and salary, and insert only
those employees into this new table whose salary is greater than $40000. Write an SQL query
that would return the department name and the maximum salary of that department (of only Male
employees, i.e. Female employees should not be included). Using the IN operator, write a SQL
statement that would return the first name, last names and the department names of those in
'MEN CLOTHING' or 'WOMAN CLOTHING Display only those department names, and
average salaries (rounded to the nearest dollar) of only those departments whose average salaries
are greater than $33000. Create a view called ernp_manager_deptname with the employee last
name (upper cased), manager name (lowercased) and the department name (lowercased) of each
employee. Grant only view and change rights to the columns fname, lname and ssn to everyone.
Create an INDEX for the emp table called indSSN on the column ssn and salary. Drop the index
and revoke the grant Assume that there exists another column in the emp table called datejoined
(which contains the date when the employee joined the company). Write a SQL query that gives
the first name, last name and the number of days employed in the company.
Solution
1. ALTER TABLE emp ADD CHECK (sex='M' OR sex='F')
2.create table highpay(empid int,salary int)
insert into highpay select empid,salary from emp where salary>40000
3.select d.deptname,max(salary) from emp as e,dept as d where e.deptno=d.deptno and
e.sex='M' group by d.deptname
4.select e.fname,e.lname,d.deptname from emp as e,dept as d where e.deptno=d.deptno and
deptname IN ('MEN CLOTHING','WOMAN CLOTHING')
Add a new check on the emp table to make sure that any new employee in.docx

More Related Content

DOCX
Hands on Assignment for retrieving data using the SQL SELECT statement.docx
DOC
Sql task answers
PPT
Sub queries
DOC
Sql task
PDF
SQL Top 10 Interview QnA By Rishabh Mishra in Hindi.pdf
PDF
Sql queries
PPTX
Complex Queries using MYSQL00123211.pptx
DOCX
Top 40 sql queries for testers
Hands on Assignment for retrieving data using the SQL SELECT statement.docx
Sql task answers
Sub queries
Sql task
SQL Top 10 Interview QnA By Rishabh Mishra in Hindi.pdf
Sql queries
Complex Queries using MYSQL00123211.pptx
Top 40 sql queries for testers

Similar to Add a new check on the emp table to make sure that any new employee in.docx (20)

PPT
PPTX
SQL case study Analysis PPT by Radhika Kashidd
PDF
Using of Group By and Having Clause in MySQL
PDF
ppt 10 SQL.pptx.evvffhjgfssfghyytdfhhhpdf
DOC
21390228-SQL-Queries.doc
DOC
SQL practice questions - set 3
PPT
DOC
Dump Answers
PPT
Les02 (restricting and sorting data)
PPT
e computer notes - Manipulating data
PDF
23 Find employees whose salary SAL is higher than their m.pdf
DOC
Plsql task answers
DOC
SQL practice questions set - 2
PPT
PPTX
Commands
PPTX
Lecture 21 Insert Update Delete.pptx
DOCX
Ravi querys 425
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
PDF
SQL practice questions set
PPT
Aggregate Functions,Final
SQL case study Analysis PPT by Radhika Kashidd
Using of Group By and Having Clause in MySQL
ppt 10 SQL.pptx.evvffhjgfssfghyytdfhhhpdf
21390228-SQL-Queries.doc
SQL practice questions - set 3
Dump Answers
Les02 (restricting and sorting data)
e computer notes - Manipulating data
23 Find employees whose salary SAL is higher than their m.pdf
Plsql task answers
SQL practice questions set - 2
Commands
Lecture 21 Insert Update Delete.pptx
Ravi querys 425
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
SQL practice questions set
Aggregate Functions,Final
Ad

More from wviola (20)

DOCX
Alice intends to send a secure message to Bob- (1) What are the threat.docx
DOCX
Add a function prototype for the function sumNum- # include using nam.docx
DOCX
Adding elements to an Array- Given the following simple List class tha.docx
DOCX
Ad by DealsFactor - Close Menlo Company Contribution Income.docx
DOCX
Action Center activation Administrative Tools Aero applets Computer Co (2).docx
DOCX
Acids Bases Taste Taste pH greater than pH less tharn Acids effect ind.docx
DOCX
Action Center activation Administrative Tools Aero applets Computer Co.docx
DOCX
Action Center activation Administrative Tools Aero applets Computer Co (1).docx
DOCX
Acid lonization Constants (K-) for Some Monoprotic Weak Acids at 25 ec.docx
DOCX
AC 556 Accounting for Governmental & Nonprofit Entities Chapter 6Solut.docx
DOCX
Accounting Which of the following is true of a corporation- OA- The st.docx
DOCX
AC 556 Accounting for Governmental & Nonprofit Entities Chapter 7Solut.docx
DOCX
advantages and disadvantages of using centralized network management v.docx
DOCX
Advantages & Disadvantages of Server Applications in 150+ wordsSolutio.docx
DOCX
Does any one have a paper on human resource practices in countries bes.docx
DOCX
Do you think Facebook should operate in China even if it means complyi.docx
DOCX
Do you think contingent gains should be disclosed in the financial sta (1).docx
DOCX
Do you think contingent gains should be disclosed in the financial sta.docx
DOCX
Do you believe the double taxation of earnings which occurs at the cor.docx
DOCX
Do you believe that the Patriot Act was an appropriate risk response t.docx
Alice intends to send a secure message to Bob- (1) What are the threat.docx
Add a function prototype for the function sumNum- # include using nam.docx
Adding elements to an Array- Given the following simple List class tha.docx
Ad by DealsFactor - Close Menlo Company Contribution Income.docx
Action Center activation Administrative Tools Aero applets Computer Co (2).docx
Acids Bases Taste Taste pH greater than pH less tharn Acids effect ind.docx
Action Center activation Administrative Tools Aero applets Computer Co.docx
Action Center activation Administrative Tools Aero applets Computer Co (1).docx
Acid lonization Constants (K-) for Some Monoprotic Weak Acids at 25 ec.docx
AC 556 Accounting for Governmental & Nonprofit Entities Chapter 6Solut.docx
Accounting Which of the following is true of a corporation- OA- The st.docx
AC 556 Accounting for Governmental & Nonprofit Entities Chapter 7Solut.docx
advantages and disadvantages of using centralized network management v.docx
Advantages & Disadvantages of Server Applications in 150+ wordsSolutio.docx
Does any one have a paper on human resource practices in countries bes.docx
Do you think Facebook should operate in China even if it means complyi.docx
Do you think contingent gains should be disclosed in the financial sta (1).docx
Do you think contingent gains should be disclosed in the financial sta.docx
Do you believe the double taxation of earnings which occurs at the cor.docx
Do you believe that the Patriot Act was an appropriate risk response t.docx
Ad

Recently uploaded (20)

PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Complications of Minimal Access-Surgery.pdf
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Share_Module_2_Power_conflict_and_negotiation.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Introduction to pro and eukaryotes and differences.pptx
My India Quiz Book_20210205121199924.pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Unit 4 Computer Architecture Multicore Processor.pptx
What if we spent less time fighting change, and more time building what’s rig...
Paper A Mock Exam 9_ Attempt review.pdf.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Computer Architecture Input Output Memory.pptx
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Complications of Minimal Access-Surgery.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
LDMMIA Reiki Yoga Finals Review Spring Summer

Add a new check on the emp table to make sure that any new employee in.docx

  • 1. Add a new check on the emp table to make sure that any new employee inserted has sex either 'M' or 'F'. Create a new table called highway, with columns: empid and salary, and insert only those employees into this new table whose salary is greater than $40000. Write an SQL query that would return the department name and the maximum salary of that department (of only Male employees, i.e. Female employees should not be included). Using the IN operator, write a SQL statement that would return the first name, last names and the department names of those in 'MEN CLOTHING' or 'WOMAN CLOTHING Display only those department names, and average salaries (rounded to the nearest dollar) of only those departments whose average salaries are greater than $33000. Create a view called ernp_manager_deptname with the employee last name (upper cased), manager name (lowercased) and the department name (lowercased) of each employee. Grant only view and change rights to the columns fname, lname and ssn to everyone. Create an INDEX for the emp table called indSSN on the column ssn and salary. Drop the index and revoke the grant Assume that there exists another column in the emp table called datejoined (which contains the date when the employee joined the company). Write a SQL query that gives the first name, last name and the number of days employed in the company. Solution 1. ALTER TABLE emp ADD CHECK (sex='M' OR sex='F') 2.create table highpay(empid int,salary int) insert into highpay select empid,salary from emp where salary>40000 3.select d.deptname,max(salary) from emp as e,dept as d where e.deptno=d.deptno and e.sex='M' group by d.deptname 4.select e.fname,e.lname,d.deptname from emp as e,dept as d where e.deptno=d.deptno and deptname IN ('MEN CLOTHING','WOMAN CLOTHING')