Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Worksheet SQL and Connectivity

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

WORKSHEET 1- SQL and Connectivity

Q1) Given the details for the table EMPLOYEE , write the queries for the following problems: -

Column Name EmpID EmpName EmpAddress EmpPhone Sal DeptID

Key Type PRIMARY

Nulls/Unique NOT NULL Unique

Fk Table Department

Fk column DeptId

Datatype NUMBER VARCHAR VARCHAR VARCHAR NUMBER VARCHAR

length 6 20 30 10 9,2 2

a) Create the table EMPLOYEE on the basis of the above information with all constraints.
b) Add a new column Gender to the table EMPLOYEE with datatype as Varchar and size
c) Delete the entire table EMPLOYEE from the database
d) To open the database named MYDB

Q2) Rahul, working in ABC Infotech Pvt. Ltd. needs to store, retrieve and delete the records of its employees,
developed an interface that provides front-end interaction through Python, and stores and updates records in
EMPLOYEE table. Help Rahul to write code for performing following functionality in his program.
user=root host=localhost Datadase=MYDB password=1234
(a) to read all the records from EMP table having salary more than 70000.
(b) to update the records of employees by increasing salary by 1000 of all those employees who are getting
less than 80000.
(c) Program to delete the record on the basis of inputted empno.

Q3. A) Rahul working on table employee given in Q no. 4, added age and city of all employees in table. Then
after two employees AMIR and SCOTT resigned their jobs. Now, help Rahul to find out the degree and
cardinality of the employee table.

B) Identify candidate key(s) from the table employee.


Q4) Consider the tables and Write SQL query :

EMPNO ENAME JOB MGR HIREDATE SALARY COMM DEPTNO

8369 SMITH CLERK 8902 1990-12-18 8000 NULL 20

8499 ANYA SALESMAN 8698 1991-02-20 16000 300 30

8521 SETH SALESMAN 8698 1991-02-20 10500 500 30

8566 MAHADEVAN MANAGER 8839 1991-04-02 29850 NULL 20

8654 MOMIN SALESMAN 8698 1991-09-28 12500 1400 30

8698 BINA MANAGER 8839 1991-05-01 28500 NULL 30

8882 SHIAVNSH MANAGER 8839 1991-06-09 24500 NULL 10

8888 SCOTT ANALYST 8566 1992-12-09 30000 NULL 20

8839 AMIR PRESIDEN NULL 1991-11-18 50000 NULL 10


T

8844 KULDEEP SALESMAN 8698 1991-09-08 15000 0 30

8886 ANOOP CLERK 8888 1993-01-12 11000 NULL 20

8900 JATIN CLERK 8698 1991-12-03 9500 NULL 30

8902 FAKIR ANALYST 8566 1991-12-03 30000 NULL 20

8934 MITA CLERK 8882 1992-01-23 13000 NULL 10

DEPARTMENT

DEPTNO DEPTNAME LOC


10 Personal Delhi
20 Admin Bangalore
30 Sales Delhi
40 Research Mumbai

QUERY
i) Insert a new record to the table EMPLOYEE with the details :-
(101,”MANAV”,”KOLKATA”,912345678, 50000, 10)
ii) To increase the Salary by 5% for all CLERKS
iii) Display Ename,sal,deptno who are not getting commission from table emp.
iv) List the details of employees who earn more commission than their salaries.
v) Display employee number, name, Salary, 5% Increased Salary of all employees
vi) How many job types are offered to employees.
vii) List the details of all employees whose salary is between 2500 and 3500.
viii)Write a query to delete all those records whose hiredate is after ‘01-01-1992’.
ix) To display the name of the employees whose name contains ‘A’ as third letter.
x) Display a report of employee table with all records sorted in descending order.
xi) To display Name of employee with respective Department name of employee who are getting salary
more than 20000.
xii) Write the UPDATE command to increase the commission by 500 of all the employees working in sales
department getting salary less than 10000.
xiii)Write a query to find job wise average salary.
xiv)Display the name of employees working in the department having more than 3 employees.
xv) Find the minimum, maximum salary for every job with number of employees in that job.

You might also like