Dbms
Dbms
Dbms
Create
an
table
employee
with
eno,ename,basic
SQL> create table empp(eno number,name varchar2(30),basic number,hra number,da number,pf number,it n umber,gross number,net number); Table created. SQL> insert into empp(eno,name,basic)
values(&eno,'&name',&salary); Enter value for eno: 1 Enter value for name: manu Enter value for salary: 5000 old 1: insert into empp(eno,name,basic)
values(&eno,'&name',&salary) new 1: insert into empp(eno,name,basic) values(1,'manu',5000) 1 row created. SQL> / Enter value for eno: 2 Enter value for name: ravi Enter value for salary: 6000 old 1: insert into empp(eno,name,basic)
BASIC
HRA
DA
PF
IT
---------- ------------------------------ ---------- ---------- ---------- ---------- ---------- ----------1 8850 2 10620 manu 9530 ravi 11280 6000 900 3720 780 120 5000 750 3100 780 100
666884444 15-SEP-1962
Table 2: DEPARTMENT
DNAME DNUMBER MGRSSN MGRSTARTDATE ------------------------------------------------------------------------------------Research 5 333445555 22-MAY-1988 Administration 4 987654321 01-JAN-1995 Headquarters 1 888665555 19-JUN-1981 Testing 2 987987987 20-JUL-1986
Table 3: PROJECT PNAME PNUMBER PLOCATION DNUM ---------------------------------------------------------------------ProductX 1 Bellaire 5 ProductY 2 Sugarland 5 ProductZ 3 Houston 5 Computerization 10 Stafford 4 Reorganization 20 Houston 1 Newbenefits 30 Stafford 4
Table 4: WORKS_ON ESSN PNO HOURS -------------------------------------123456789 1 32.5 123456789 2 7.5 666884444 3 40 453453453 1 20 453453453 2 20 333445555 2 10 333445555 3 10 333445555 10 10 333445555 20 10 999887777 30 30 999887777 10 10 987987987 10 35 987987987 30 5 987654321 30 20 987654321 20 15 888665555 20 0
Table 5: DEPENDANT
ESSN DEPENDENT_NAME SEX BDATE RELATION ---------------------------------------------------------------------------------------------333445555 Alice F 05-APR-86 DAUGHTER 333445555 Theodore M 25-OCT-83 SON 333445555 Joy F 03-MAY-58 SPOUSE 987654321 Abner M 28-FEB-42 SPOUSE 123456789 Michael M 04-JAN-88 SON 123456789 Alice F 30-DEC-88 DAUGHTER 123456789 Elizabeth F 05-MAY-67 SPOUSE
Table 6: DEPARTMENT_LOCATIONS DNUMBER DLOCATION ---------------------------------------------1 Houston 4 Stafford 5 Bellaire 5 Sugar land 5 Houston
EXP:2
1. Simple queries: 01.Write a query to display details of all the departments. SQL> SELECT * FROM DEPARTMENT; DNAME DNUMBER MGRSSN MGRSTARTD
--------------- ---------- --------- -------------------------------------------Research Headquarters Administration Testing 5 1 4 2 333445555 888665555 987654321 987987987 22-MAY-88 19-JUN-81 01-JAN-95 20-JUL-86
02. Write a query to retrieve birth date and address of the employees whose name is John B Smith. SQL> SELECT BDATE, ADDRESS FROM EMPLOYEE WHERE FNAME='John' AND MINIT='B' AND LNAME='Smith'; BDATE ADDRESS
03. Write a query to retrieve all distinct Salary values. SQL> SELECT DISTINCT SALARY FROM EMPLOYEE; SALARY ---------25000 30000 38000 40000 43000 55000
04. Determine the fname, Address, salary rename the title as Employee-salary and the output must be in the following form 30000 ] SQL> SELECT FNAME || '[' | |ADDRESS ||' : ' || SALARY || ']' AS EMPLOYYEE_SAL FROM EMPLOYEE; EMPLOYYEE_SAL -------------------------------------------------John[731 Fondren Houston TX:30000] Franklin[638 Voss, Houston, TX:40000] Alicia[3321, Castle, Spring, TX:25000] Jennifer[291, Berry, Bellaire, TX:43000] Ramesh[975 Fire Oak,Humble,TX:38000] Ahmad[980 Dallas, Houston, TX:25000] James[450 Stone, Houston, Tx:55000] John[ 731 Fondren, Houston, TX :
EXP:3
2. Queries on Join operations (Multiple tables) : 01. Write a query to retrieve the names of all employee names that do not have supervisors. SQL> SELECT DISTINCT E.FNAME ,E.LNAME FROM EMPLOYEE E,EMPLOYEE S WHERE E.SSN=S.SUPERSSN AND E.SUPERSSN IS NULL; FNAME LNAME
02. Write a query display employees first name, last name, department number and department names for all employees who are working for deptno 5. SQL> SELECT FNAME,LNAME,E.DNO,DNAME FROM EMPLOYEE E,DEPARTMENT D WHERE E.DNO=D.DNUMBER AND E.DNO=5;
FNAME
LNAME
DNO
DNAME
--------------- --------------- ---------- --------------John Franklin Ramesh Joyce Smith Wong Narayan English 5 5 5 5 Research Research Research Research
03.. Write a query to retrieve name and address of all employee names who work for the Research department SQL> SELECT FNAME,LNAME,ADDRESS 2 FROM EMPLOYEE E,DEPARTMENT D 3 WHERE E.DNO=D.DNUMBER AND D.DNAME='Research'; FNAME LNAME ADDRESS
--------------- --------------- ----------------------------John Franklin Ramesh Joyce Smith Wong Narayan English 731 Fondren Houston TX 638 Voss, Houston, TX 975 Fire Oak,Humble,TX 5631 Rice, Houston,TX
04. Write a query to retrieve employee s first and last name and first and last name of his or her immediate supervisor. SQL> select e.fname,e.lname,s.fname MGR_FNAME,s.lname MGR_LNAME from employee e,employee s where e.superssn=s.ssn;
FNAME
LNAME
MGR_FNAME
MGR_LNAME
--------------- --------------- --------------- -----------------------------------John Franklin Alicia Jennifer Ramesh Ahmad Smith Wong Zelaya Wallace Narayan Jabbar Franklin James Jennifer James Franklin Jennifer Wong Borg Wallace Borg Wong Wallace
Joyce
English
Franklin
Wong
EXP:4
3. Nested Queries : 01. Write a query to retrieve the names of all employees who have two or more dependents. SQL> SELECT FNAME,COUNT(*) DEPENDENT_COUNT 2 FROM EMPLOYEE E,DEPENDENT D 3 WHERE E.SSN=D.ESSN 4 GROUP BY FNAME 5 HAVING COUNT(*)>=2 6 ORDER BY FNAME; FNAME DEPENDENT_COUNT --------------- --------------Franklin 3 John 3 02. Write a query to retrieve the names of all employees whose salary is greater than the MAXIMUM salary of all the employees in department 5.(remind to sir) SQL> SELECT FNAME,DNO,SALARY 2 FROM EMPLOYEE 3 WHERE SALARY>(SELECT MAX(SALARY) FROM EMPLOYEE WHERE DNO=5); FNAME DNO SALARY --------------- ---------- ---------Jennifer 4 43000 James 1 55000 03. Write a query to retrieve the name of each employee who has a dependent with the same first name and same sex as the employee. SQL> SELECT E.FNAME,E.LNAME 2 FROM EMPLOYEE E 3 WHERE E.SSN IN ( SELECT ESSN FROM DEPENDENT D 4 WHERE E.FNAME=DEPENDENT_NAME AND E.SEX=D.SEX); no rows selected 04. Write a query to retrieve the names of employees who have no dependents.
SQL> SELECT FNAME,LNAME,SSN 2 FROM EMPLOYEE 3 WHERE NOT EXISTS ( SELECT * FROM DEPENDENT WHERE SSN=ESSN); FNAME LNAME SSN --------------- --------------- --------Alicia Zelaya 999887777 Ramesh Narayan 666884444 Ahmad Jabbar 987987987 James Borg 888665555 Joyce English 453453453
EXP:5
4. Set Oriented Operations: 01. Display all the salaries of department no 4 and 5.(Use union) SQL> SELECT SALARY FROM EMPLOYEE WHERE DNO=4 2 UNION ALL 3 SELECT SALARY FROM EMPLOYEE WHERE DNO=5; SALARY ---------25000 43000 25000 30000 40000 38000 25000
02. display the common dependent names of employee 333445555 and 123456789. SQL> SELECT DEPENDENT_NAME FROM DEPENDENT WHERE ESSN=333445555 2 INTERSECT 3 SELECT DEPENDENT_NAME FROM DEPENDENT WHERE ESSN=123456789; DEPENDENT_NAME --------------Alice 03. List unique project numbers to employee 333445555 from other employees 999887777
987987987 SQL> SELECT PNO FROM WORKS_ON WHERE ESSN=333445555 2 MINUS 3 SELECT PNO FROM WORKS_ON WHERE ESSN IN (999887777,987987987); PNO ---------2 3 20
EXP:6
5. DDL and TCL commands: 1. Create a view which displays the SSN, DEPTNO, DEPTNAME for all the employees and ensure that updating the view is done automatically whenever DML operations are carried on the base tables.
SQL> create view emp_dept as select ssn,dno,dname from employee,department where employee.dno=department.dnumber;
View created.
SSN
DNO DNAME
--------- ---------- --------------123456789 333445555 999887777 987654321 666884444 987987987 888665555 5 Research 5 Research 4 Administration 4 Administration 5 Research 4 Administration 1 Headquarters
453453453
5 Research
DML OPERATIONS :
1 row deleted.
SSN
DNO DNAME
--------- ---------- --------------333445555 999887777 987654321 666884444 987987987 888665555 453453453 5 Research 4 Administration 4 Administration 5 Research 4 Administration 1 Headquarters 5 Research
1 row updated.
SSN
DNO DNAME
1 row created. SQL> insert into employee values('Pampapathi','M','MAnasani',999999999,'06-dec1979', 'BELLARY','M',320000,888665555,9); SQL> select * from emp_dept; SSN DNO DNAME
--------- ---------- --------------333445555 999887777 987654321 666884444 987987987 888665555 453453453 999999999 4 Administration 4 Administration 4 Administration 5 Research 4 Administration 1 Headquarters 5 Research 9 Development
2. Create a table and show the outputs with different types of TCL commands like COMMIT, ROLLBACK and SAVEPOINT commands.
Table created. SQL> insert into s1 values(1,'manu',5000); 1 row created. SQL> insert into s1 values(2,'hari',6000); 1 row created. SQL> select * From s1; SNO SNAME SALARY
SQL> commit; Commit complete. SQL> select * From s1; SNO SNAME SALARY
SQL> delete from s1 where sno=2; 1 row deleted. SQL> select * From s1; SNO SNAME SALARY
SQL> rollback; Rollback complete. SQL> select * From s1; SNO SNAME SALARY
1 manu 2 hari
5000 6000
SQL> delete from s1 where sno=1; 1 row deleted. SQL> delete from s1 where sno=2; 1 row deleted. SQL> select * From s1; no rows selected SQL> rollback to s2; Rollback complete. SQL> select * From s1; SNO SNAME SALARY
E XP:7
to 5000/-
Before update: the updated records will be transmitted to another table called updemp. Before delete: print the message the record is successfully deleted
SQL> create table emp(empno number,ename varchar2(10),salary number,commission number); SQL> insert into emp
values(&empno,'&ename',&salary,'&commission'); Enter value for empno: 1 Enter value for ename: manu Enter value for salary: 5000 Enter value for commission: old 1: insert into emp
SQL> / Enter value for empno: 2 Enter value for ename: hari Enter value for salary: 4000 Enter value for commission: 4000 old 1: insert into emp
EMPNO ENAME
SALARY
COMMISSION
---------- ---------- ---------- -----------------------------------1 2 3 SQL> manu hari Ravi create 5000 4000 5000 table 4000 3000 emp1(empno number,ename
varchar2(10),salary number,commission number); Trigger for BEFORE DELETE : create or replace trigger emp_bd before delete on emp for each row begin insert into emp1
values(:old.empno,:old.ename,:old.salary,:old.commission); dbms_output.put_line('...RECORD DELETED...'); end; / Trigger Created SQL> delete from emp where empno=1; ...RECORD IS SUCCESSFULLY DELETED... SQL> select *from emp1; EMPNO ENAME SALARY COMMISSION IS SUCCESSFULLY
Trigger for Before Insert : create or replace trigger emp_BI before insert on emp for each row begin if :new.salary<5000 then raise_application_error(-20001,'...SALARY IS NOT VALID...'); end if; end; / Trigger created; SQL> insert into emp values(3,'AAA',4000,400); insert into emp values(3,'AAA',4000,400) * SQL> insert into emp values(3,'AAA',8000,600); 1 row created. Trigger for After Update : SQL> create table oldupdemp(empno number,ename
before update on emp for each row begin insert into oldupdemp
values(:old.empno,:old.ename,:old.salary,:old.commission); dbms_output.put_line('...RECORD IS UPDATED...'); end; / Trigger created SQL> update emp set commission=10000 2 where empno=2; 1 row updated. SQL> select * from oldupdemp; EMPNO ENAME SALARY COMMISSION
EMPNO ENAME
SALARY COMMISSION
---------- ---------- ---------- ---------2 hari 3 AAA 4000 8000 10000 600
SQL>
create
table
updemp(empno
number,ename
create or replace trigger before_up1 after update on emp for each row begin insert into updemp
values(:new.empno,:new.ename,:new.salary,:new.commission); dbms_output.put_line('...RECORD IS UPDATED...'); end; / Trigger Created SQL> select * from emp; EMPNO ENAME SALARY COMMISSION
OS LAB
Week 1:
Path Man Echo Printf Script Password U name Who Date Cal Tty Pwd List Copy
Week 2:
Gzip Uncompressing a gzipped file Bc cmd W cmd Move Remove Cat More Word count Print files Octaldum(od) Directory commands Mkdir Cd Rmdir
Week 3:
Vi editor Commands Insert command Append command New line command Vertical line command Delete command Scroll command Undo command Save and exit command
Week 4:
Disk utility commands Df command Du command Backup commands Tar command 1. Creating backup 2. Restoring Cpio Network commands telnet rlogin ftp arp finger
Week 5:
Cat Head Tail Sort nl uniq
Week 6:
ONLY THEORY. THIS CAN WRITE IN THE COLLEGE.