0% found this document useful (0 votes)
195 views

Dbms Questions 2

This document contains 7 sections that provide SQL queries and commands to create tables, insert data, and retrieve data from employee and department tables. Some key points: - Section I creates an employee table and inserts sample data. Queries display employee names and details. - Section II creates employee and department tables and inserts values. Queries change data and display employee names and departments. - Sections III-VII provide additional SQL queries and commands to retrieve data from the employee and department tables based on various conditions such as age, department, salary comparisons, and job roles.

Uploaded by

Gayathri Soman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views

Dbms Questions 2

This document contains 7 sections that provide SQL queries and commands to create tables, insert data, and retrieve data from employee and department tables. Some key points: - Section I creates an employee table and inserts sample data. Queries display employee names and details. - Section II creates employee and department tables and inserts values. Queries change data and display employee names and departments. - Sections III-VII provide additional SQL queries and commands to retrieve data from the employee and department tables based on various conditions such as age, department, salary comparisons, and job roles.

Uploaded by

Gayathri Soman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

I.

1. Create a table employee with attributes Employee_id, First_name, last_name,


email,phone number, hire_date,job_id, salary,manager_id,department_id.
2. Insert five rows to employee table.
3. Change the phone number of employee whose employee_id is 3.
4. Write a query to display the name ( first name and last name ) for those employees
who gets more salary than the employee whose ID is 163.
5. Write a query to display the name ( first name and last name ), salary, department id,
job id for those employees who works in the same designation as the employee works
whose id is 169.
II.
1. Create table employee with attributes employee_id, first_name,last_name,phone
number,job_id, salary,department_id,manager_id
2. Create table departments with attributes
department_id,department_name,manager_id,location_id.
3. Insert values into the two tables.
4. Change the last_name of employee whose first name is Ram.
5. Display the first name, last name, and department number for all employees who
work in Sales department.
III. Create the following tables

Table - I ( EMPLY )
Data for Client_Master
Empcode Empname Address Age Dept_Code
E101 Anjaly Anjaly Nivas, Thiruvalla 25 D301
E102 Bobby Alapuzha 28 D305
E103 Aravind Chennai 31 D305
E104 Lakshmi Mannar 55 D707
E105 Daisy Chaithram, Angamaly 35 D707
E106 Esha Mumbai 23 D707
E107 Georgy Pala 45 D909
E108 Prakash Vennikulam 36 D110
E109 Madhavan Mynakum, Kottayam 46 D202
E110 Anugraha Aparna, Angamaly 47 D301
E111 Deva Trichy 38 D301
E112 Saju Dhanya, Ernakulam 27 D202
E113 Priyesh Priya Nivas, Kottayam 26 D302
Table - II ( DEPT )
Data for Department
DEPTCODE DEPTNAME
D301 Sales
D302 Account
D707 Research
D909 Advertising
D202 Stock
D110 Computer
D305 Marketing

Write SQL commands for the following:

1. Display records from EMPY1 table for employees whose age is between 25 and 45.
2. Retrieve the Deptcode and total no of employees in each department.
3. Retrieve empcode, empname, address, deptcode for all employees in "account" and "stock"
departments.

IV. Consider the following relations that contains information about Trains:
Train (Train-id, T-name, from, to, distance, depart-time, arrival-time)
Driver (D-id, D-name, job, salary)
Swifts (D-id, Train-id)

Write SQL Query for

i. Display train names that run between Hyderabad and Mumbai.

iii . List the train ids of trains which contain ‘EXPRESS’ in the train name or is
swift by a driver whose name doesn’t end with ‘ank’.

V. Create a table employee and insert the following data:

Employee First- Last-name email Hire date Jod- salary Mang- Dept-
id name id id id
100 Steven king sking 1987-06- IT 5000 0 30
17
101 Neena Kochhar nkochhar 1987-06- IT 7000 100 40
18
102 Lex Dehann Ldehann 1987-06- CLE 3000 100 50
20 RK
103 Alexander Hunold Ahunold 1987-06- EEE 12000 101 40
21
104 Bruce Ernst Bernst 1987-06- CLE 3000 102 30
22 RK
105 David Austin Daustin 1987-06- EC 10000 101 50
23
106 Nancy Greenberg Ngreenber 1987-06- ME 13000 102 30
g 24

1. Write a query to find the name (first_name, last_name) of all employees who works
in the IT department
2. Write a query to find the name (first_name, last_name) and the salary of the
employees who have a higher salary than the employee whose last_name='Austin'
3. Write a query to find the name (first_name, last_name), and salary of the employees
whose salary is greater than the average salary.
VI.
 Create a table employee and insert the following data:

Employee First- Last-name email Hire date Jod- salaryMang- Dept-


id name id id id
100 Steven king sking 1987-06- IT 15000 0 40
17
101 Neena Kochhar nkochhar 1987-06- IT 17000 100 40
18
102 Lex Dehann Ldehann 1987-06- CLE 3000 100 50
20 RK
103 Alexander Hunold Ahunold 1987-06- Acc 12000 101 80
21 ount
104 Bruce Ernst Bernst 1987-06- SA- 3000 105 30
22 REP
105 David Austin Daustin 1987-06- HR 10000 0 60
23
106 Nancy Greenberg Ngreenber 1987-06- ASS 13000 100 70
g 24 T

1. Write a query to find the name (first_name, last_name) of the employees who are not
clerks
2. Write a query to find the name (first_name, last_name) and the salary of the
employees who have a higher salary than the employee whose last_name='Austin'.
3. Write a query to find the name (first_name, last_name) and hire date of the
employees who was hired after 'Alexander'.
VII.

 Create a table employee and department and insert the following data:

Employee First- Last-name email Hire date Jod- salaryMang- Dept-


id name id id id
100 Steven king sking 1987-06- IT 15000 0 40
17
101 Neena Kochhar nkochhar 1987-06- IT 17000 100 40
18
102 Lex Dehann Ldehann 1987-06- CLE 3000 100 50
20 RK
103 Alexander Hunold Ahunold 1987-06- Acc 12000 101 80
21 ount
104 Bruce Ernst Bernst 1987-06- SA- 3000 105 30
22 REP
105 David Austin Daustin 1987-06- HR 10000 0 60
23
106 Nancy Greenberg Ngreenber 1987-06- ASS 13000 100 70
g 24 T

DEPT-id Dept -name Manager-id Loaction-id


30 Public relations 102 1700
40 IT 100 1800
50 Shipping 100 2000
60 Human Resources 101 1900
70 Administration 102 1200
80 Accounting 101 1700

1. Write a query to display the department ID and name and first name of clerk.
2. Write a query to display the job title and average salary of employees
3. Write a query to display department name, name (first_name, last_name), hire date,
salary of the manager for all managers whose experience is more than 15 years.

VIII.

 Create a table employee and department and insert the following data:

Employee First- Last-name email Hire date Jod- salaryMang- Dept-


id name id id id
100 Steven king sking 1987-06- IT 15000 0 40
17
101 Neena Kochhar nkochhar 1987-06- IT 17000 100 40
18
102 Lex Dehann Ldehann 1987-06- CLE 3000 100 50
20 RK
103 Alexander Hunold Ahunold 1987-06- Acc 12000 101 80
21 ount
104 Bruce Ernst Bernst 1987-06- SA- 3000 105 30
22 REP
105 David Austin Daustin 1987-06- HR 10000 0 60
23
106 Nancy Greenberg Ngreenber 1987-06- ASS 13000 100 70
g 24 T

DEPT-id Dept -name Manager-id Loaction-id


30 Public relations 102 1700
40 IT 100 1800
50 Shipping 100 2000
60 Human Resources 101 1900
70 Administration 102 1200
80 Accounting 101 1700
90 Finance 106 1900

1. Write a query to find the name (first_name, last_name), and salary of the employees
who earns more than the earning of Bruce.
2. Write a query to display the employee ID, first name, last name, and department
names of all employees.
3. Write a query to list the department ID and name of all the departments where no
employee is working.
IX.

 Create a table employee and department and insert the following data:

Employee First- Last-name email Hire date Jod- salaryMang- Dept-


id name id id id
100 Steven king sking 1987-06- IT 15000 0 40
17
101 Neena Kochhar nkochhar 1987-06- IT 17000 100 40
18
102 Lex Dehann Ldehann 1987-06- CLE 3000 100 50
20 RK
103 Alexander Hunold Ahunold 1987-06- Acc 12000 101 80
21 ount
104 Bruce Ernst Bernst 1987-06- SA- 3000 105 30
22 REP
105 David Austin Daustin 1987-06- HR 10000 0 60
23
106 Nancy Greenberg Ngreenber 1987-06- ASS 13000 100 70
g 24 T

DEPT-id Dept -name Manager-id Loaction-id


30 Public relations 102 1700
40 IT 100 1800
50 Shipping 100 2000
60 Human Resources 101 1900
70 Administration 102 1200
80 Accounting 101 1700
90 Finance 106 1900

1. Write a query to find the name (first_name, last_name) and hire date of the
employees who was hired after 'Neena'.
2. Write a query to find the name (first_name, last_name), and salary of the employees
who earns more than the average salary and works in any of the IT departments.
3. Write a query to display the department ID and name and first name of clerk.
X. Write a program to find the reverse of a number using the concept of stored procedure in
MySQL.

XI. Write a program to check whether a given number is Armstrong or not using the
concept of stored procedure in MySQL.

XII. Write a program to find the reverse of a number using the concept of Functions in
MySQL.

XIII. Write a program to check whether a given number is Armstrong or not using the concept
of functions in MySQL.

XIV. Procedure for mark calculation:


 Create a table student with rno, mark1, mark 2, mark3 and total
 Insert 5 values into table.
 Write a program using procedure and find out the total mark of each student and
insert into new table total-marks with attributes rno and total-marks.

XV. Function for mark calculation:


 Create a table student with rno, mark1, mark2 , mark 3, and total
 Insert 5 values into table
o Write a program to find out total mark of each student using function and
insert into new table total-marks with attributes rno and total-marks.
XVI.
 Create a table student with roll no, name, m1, m2, m3 and grade
 Insert values into table except for field ‘grade’
 Write a program using cursor to find grade of each student, if totmarks>80
‘distinction’,between 60 and 80 grade is ‘first class’, tot mark<60 ‘second
cls’ and below 40 grade ‘failed’.
XVII.
 Create a table supply with attributes supplierrname , quantity and Day .
 Set trigger to check insertion is not done in Wednesday.

You might also like