Vous êtes sur la page 1sur 4

AUTHOR : SHRADDHA RAI

DATE : 8 NOVEMBER,2010

employee dept.
sal_grade

empno:primary key deptno.:primary key


lower limit
name:not null deptname:
upperlimit
sal:not null (by default account)
grade:a to f
<50000
desig:sr.manager,manager,clerk,supervisor
dept.no:10-50
dob:not null
<1/1/1970
gender:m or f

q1.) Write a query to create above 3 tables with given constriants.

CREATE TABLE employ


(
empno integer PRIMARY KEY,
name char(20) NOT NULL,
sal integer NOT NULL
CHECK(sal<50000),
desig char(20) CHECK(desig IN ('sr.mgr','mgr','clerk','supervisor')),
deptno integer CHECK(deptno BETWEEN 10 and 50),
dob date NOT NULL
CHECK(dob<'1-jan-1970'),
gender char(1) CHECK(gender IN ('M','F')),
);

CREATE TABLE dept


(
deptno integer PRIMARY KEY,
deptnm char(20) DEFAULT='acc',
);

CREATE TABLE sal_grade


(
ll integer PRIMARY KEY,
ul integer PRIMARY KEY,
grade char(1) CHECK(grade BETWEEN 'a' and 'f'),
);

q2.)Write a query to insert atleast 2 record each in 3 table.

INSERT INTO employ


VALUES (2,'chiku',4000,'sr.mgr',20,’2-jan-
1969’,'F'); &
nbs p;

INSERT INTO employ


VALUES (5,'vicky',700,'clerk',30,’2-jan-
1968’,'F');

INSERT INTO dept


VALUES
(45,'fin');
& nbsp;

INSERT INTO dept


VALUES (52);

INSERT INTO sal_grade


VALUES
(2000,4000,'a');
&n bsp;

INSERT INTO sal_grade


VALUES (2500,4570,'c');

q3.)WAQ to display all information of female senior manager.

SELECT * FROM employ WHERE gender='F' and desig='sr.mgr';

//OUTPUT:
empno 2
name chiku
sal 4000
desig sr.mgr
deptno 20
dob 2-jan-1969
gender F

q4.)WAQ to display all distinct designation .

SELECT DISTINCT desig


FROM employ;

//OUTPUT:
sr.manager
manager
clerk
supervisor

q5.)WAQ to display employ no, name of all managers from dept no 40 whose salary is<10000

SELECT empno,name FROM employ WHERE deptno=40 and salary<1000;


Q6.)WAQ to display details of all male employs whose date of birth is after 1 Jan 1980 and salary is
between 30000-40000.

SELECT * FROM employ WHERE gender=’M’ and dob>’1-jan-1980’ and salary BETWEEN 30000
AND 40000;

Q7.)WAQ to display employ no., name and designation of all employs from dept no. 10,30 and 50.

SELECT empno,name,desig FROM employ WHERE deptno IN (10,30,50);

Q8.)WAQ to display employ no. and name of those employs who have not been given designation.

SELECT empno,name FROM employ WHERE desig= NULL;

Q9.)WAQ to create a new table containing employ no. , name and department name.

CREATE TABLE chiku AS (SELECT empno,name,deptnm FROM employ,dept);

Q10.)WAQ to display total number of male in department no. 10.

SELECT COUNT(empno) FROM employ WHERE gender=’M’ and deptno=10;

Q11.)WAQ to delete all male employs of department 50.

DELETE FROM employ WHERE gender=’M’ and deptno=50;

Q12.)WAQ to display structure of employ table.

DESCRIBE employ;

//ye query mam ne karai hai book me nahi hai………………

Q13.)WAQ to increase salary of all sr. managers by 25% who belong to department no. 20 or 40.

UPDATE employ SET sal=0.25*sal+sal WHERE desig=’sr.mgr’ and deptno IN (20,40);

Q14.)WAQ to change designation of managers to senior managers whose date of birth is before 15 Sep
1975.

UPDATE employ SET desig=’sr.mgr’ WHERE desig=’mgr’ and dob<’15-sep-1975’;

Q15.)WAQ to create a view containing employ no.,name,salary department name.

CREATE VIEW chiku (empno,name,sal,deptnm) AS SELECT empno,name,sal,deptnm FROM employ;

Q16.)WAQ to add a new column to table department called location constraints being not null.

ALITER TABLE dept ADD (location char(20) NOT NULL);

Q17.)WAQ to display employ no.,name,salary,department name and grade of all employs.


SELECT empno,name,sal,deptnm,grade FROM employ, sal_grade;

Q18.)WAQ to display department name and number and total number of employs in each department of
only those department where number of employs <10..

SELECT deptnm,deptno,COUNT(empno) FROM employ,dept WHERE count(empno)<10;

Q19.)WAQ to display number of departments in employ table.

SELECT count(DISTINCT depno) FROM employ;

Q20.)WAQ to display names of those employs whose name has F.

SELECT * FROM employ WHERE name like’%f%’;

Q21.)WAQ to display complete detail in descending order of salary and ascending order of name.

SELECT * FROM employ ORDER BY sal DESC,name ASC;

Q22.)WAQ to display department wise number of employs ,sum of their salary,maximum,minimum and
average salary.

SELECT count(empno),sum(sal),avg(sal),min(sal),max(sal) FROM employ GROUP BY deptno;

Q23.)WAQ to drop the department table.

DROP TABLE dept;

Q24.)WAQ to drop the view you created.

DROP VIEW chiku;

Q25.)WAQ to display employ number and name of all employ whose date of birth is after 1 Jan 1985.

SELECT empno,name FROM employ WHERE dob>’1-jan-1985’;

Vous aimerez peut-être aussi