(ISHITA) Call Girls Service Hyderabad Call Now 8617697112 Hyderabad Escorts
SQL Practice Question set
1. SQLAssignment – 2
Written and Compiled by : Mohd Tousif
1. Display the highest,lowest,sum and average salaries of all employees. Label the columns as
Maximum, Minimum, Sum, Average respectively. Round your results to the nearest whole
number.
2. Determine the number of managers without listing them. Label the column Number of
Managers.
3. Write a query to display the difference between the highest and lowest salaries. Label the
column DIFFERENCE.
4. Display the manager number and the salary of the lowest paid employee for that manager.
Exclude any one whose manager is not known. Exclude any groups whose where the maximum
salary is 6,000 or less.
5. Write a query to extract the year from hire_date column of the EMPLOYEES table for those
employees who work in department 80.
6. Display the highest,lowest,sum and average salaries of all employees for each job type. Label
the columns as Maximum, Minimum, Sum, Average respectively. Round your results to the
nearest whole number.
7. Write a query to display the number of people with the same job.
8. Write a query to display each department name, location number, number of employees and the
average salary of all employees in that department. Label the columns Name, Location, Number
of People and Salary respectively. Round the average to two decimal places.
9. Create an Emp table with the following criteria:
Eno number(6)
Ename varchar2(30)
Sal number(8,2)
deptno number(4)
10. Add a table – level primary key constraint to the EMP table on the ID column. The constraint
should be named at creation. Name the constraint my_emp_id_pk.
11. Create a primary key constraint to the DEPT table using the ID column. The constraint should
be named at the time of creation. Name the constraint my_dept_id_pk.
12. Add a column dept_id to the EMP table. Add a foreign key reference on the EMP table that
ensures that the employee is not assigned to a non-existent department. Name the constraint
my_emp_dept_id_fk.
13. Modify the EMP table. Add a commission column of number datatype, precision 2, scale 2. Add
a constraint to the commission column that ensures that a commission value is greater than zero.
14. Remove the table Emp from the database
15. Clear the recyclebin
16. Display the highest,lowest,sum and average salaries of all employees for each job type. Label
the columns as Maximum, Minimum, Sum, Average respectively.
17. Write a query to display the number of people with the same job.
18. Write a query to display each department name, location number, number of employees and the
average salary of all employees in that department. Label the columns Name, Location, Number
of People and Salary respectively. Round the average to two decimal places.
19. Create a table student_marks with the following conditions
(a) Roll number with the data type number of size 3 and should not have null values
(b) Year with the data type number of size 1 and should not have null values
2. (c) Marks with the data type number of size 5,2 and should not have null values
(d) Remarks with the data type varchar2 of size 20
The roll number should be between 1 and 250 , year should be between 1 and 3 , marks should
be between 0 and 100. Give appropriate constraint names.
20. Create a table student with the following conditions
(a) Roll number with the data type number of size 3
(b) City with the data type varchar2 of size 20
(c) Name with the data type varchar2 of size 30
None of the column should have a null value. The roll number should be with the range of 1 to
250. The length of the city should be 3 and all the characters should be in uppercase. First
character of the name should be in capital letters. Give appropriate constraint names.
21. Create a table stud with the following conditions
(a) Roll number with the data type number of size 3
(b) Name with the data type varchar2 of size 30
(c) Year with the data type date
(d) Branch with the data type varchar2 of size 20
(e) EN with the data type number of size 4
Define an unique on the column EN. Define a composite primary key on the columns Roll
number,year and branch. Give appropriate constraint names.
22. Create a table supplier with the following conditions
(a) Supplier_Id with the data type number of size 10
(b) Supplier_name with the data type varchar2 of size 30
(c) Contact_name with the data type varchar2 of size 30
Define a primary key on Supplier_Id. Supplier_Name should not contain null values.
23. Create a table products with the following conditions:
(a) Product_Id with the data type number of size 10
(b) Sup_Id with the data type number of size 10
Refer Supplier_Id of supplier table to Sup_Id of products table.
Give appropriate constraint names.
24. Create a table product with the following conditions
(a) Product_Id with the data type number of size 5
(b) Product_name with the data type varchar2 of size 20
(c) Supplier_name with the data type varchar2 of size 20
(d) Unit_Price with the data type number of size 10
Define priamry key on Product_Id. Product name and Supplier name should not be null. Unit
Price should be more than 5000.
25. Create a table order_items with the following conditions
(a) Order_Id with the data type number of size 5
(b) Product_Id with the data type number of size 5
Define priamry key on Order Id and foreign key on Product_Id reference product table
product_id. Give appropriate constraint names.
26. Enter 5 records into each of the tables student_marks, student, stud, supplier, products, product,
order_items and produce one error if violating the rules.
27. Remove all the constraints created above from the database.
28. Remove the tables student_marks,student,stud,supplier,products,product,order_items from the
database.
29. Clear the recycle bin.
30. Create a table with the name stud_marks(sid,sname,city).
31. Insert the values into the above table for sid column, using sequence created in Q23 and rest
other column values must be user defined. Enter 10 records.
32. Write a query to display the last name,department number and department name for all
3. employees.
33. Write a query to display the employee last name , department name, location id, and city of all
employees who earn a commission.
34. Create a unique listing of all jobs that are in department 80. Include the location of the
department in the output.
35. Write a query to display the employee last name , department name, location id, and city of all
employees who earn a commission.
36. Write a query that displays the last name, job, department name, salary and grade for all
employees.
37. Write a query to display the name and hire date of any employee hired after employee Davies.
38. Display the employee's last name and department name for all employees who have an 'a'.
39. Create a query that displays the employee last names, department numbers, and all the
employees who work in the same department as a given employee.
40. Create a query that displays the last name, job, department name, salary and grade for all
employees.
41. Write a query to display Employee id , name , salary , department id , department name ,
manager id though there are employees existing in a department or not.
42. Write a query to display the details of employees whose designation is same as designation of
the employee of "Shipping" department.