Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Time: 1 Hour
Total Marks: 35
PART - 1
constraints are used to limit the type of date go into the table
Primary key
Fireign key
Unique key
Not null
Check
Create table
(empno int not null)
Create table (p_id int ,ename varchar2(10), primary key(p_id)
on delete cascade=Use the ON DELETE CASCADE option to specify whether you want rows
deleted in a child table when corresponding rows are deleted in the parent table
On delete null =it used to set the child records to null
3. What are the constraints which can be enabled and disabled? How do u enable and
disable them? Example
yes
7. How many primary, foreign, unique, check constraints we can have on a table?
SQL Test – 7
Time: 1 Hour
Total Marks: 35
many
8. Display the total Salary of emps belongs to Grade 3.in descending order
9. List the emp name, sal and deptno for each emp who earns a sal greater than the avg
for their dept order by deptno
select * from emp e
where sal > (select avg(sal) from emp where e.deptno = deptno );
10.Find out all the emps who earn highest sal in each job type. Sort in des order of sal
select * from emp where sal in (select max(sal) from emp group by job)
Order by sal desc
11. List out the name, job, sal of the emps in the department with the highest avg sal.
select * from emp where deptno in
(select deptno from emp e
having avg(sal) =(select max(avg(sal)) from emp group by deptno)
group by deptno);
12. Find all the emps who earn minimum sal for each job wise in asc order of sal
select * from emp where sal in(select min(sal) from emp group by job)order by sal
13.List the dept in asc order of job and the desc order of emps print empno, ename
Total Marks: 35
PART -2
1) List the managers name who is having max no of emps working under him.
select empno,ename,sal,job,
case
when sal = 1500 then 'ON TARGET'
when sal < 1500 then 'BELOW 1500'
when sal > 1500 then 'JUST SALARY'
else 'nothing'
end "REVISED SALARY"
from emp;
4) Write a query to return the day of the week for any date entered in format ‘DD-MM-YY’
5) Print the details of all the emps who are sub-ordinates to BLAKE.
select * from emp where mgr in (select empno from emp where ename = 'BLAKE');
select * from emp where empno in (select mgr from emp );
select count(*) from emp where empno in (select mgr from emp);
Total Marks: 35
UPDATE employees
SET lastname = ’Drexler’
WHERE id = 3;
8) Change the salary to 1000 for all employees with a salary less than 900.
UPDATE employees
SET salary = 1000
WHERE salary < 900
9) Empty the entire table.
commit;
Select * from emp
SELECT table_name
FROM user_tables
WHERE table_name IN ('DEPT', 'EMP');
16)Drop the FIRST_NAME column from the EMP table. Confirm your modification by checking
the description of the table.
SQL Test – 7
Time: 1 Hour
Total Marks: 35
ALTER TABLE emp
DROP COLUMN first_name
Desc emp
17) In the EMP table, mark the DEPT_ID column in the EMP table as UNUSED. Confirm your
modification by checking the description of the table.
ALTER TABLE emp
SET UNUSED (dept_id);
18) Drop all the UNUSED columns from the EMP table. Confirm your modification by checking
the description of the table.
ALTER TABLE emp
DROP UNUSED COLUMNS
19. 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.
Hint: The constraint is enabled as soon as the ALTER TABLE command executes
successfully.
20. Create a PRIMARY KEY constraint to the DEPT table using the ID column. The constraint
should be named at creation. Name the constraint my_dept_id_pk.
Hint: The constraint is enabled as soon as the ALTER TABLE command executes
successfully.
21. 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 nonexistent department. Name the constraint
my_emp_dept_id_fk.