P. 1
31774335 Database Management Systems Experiments

31774335 Database Management Systems Experiments

|Views: 96|Likes:
Published by Bani Johri

More info:

Published by: Bani Johri on Dec 09, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

01/05/2012

pdf

text

original

DATA DEFINITION LANGUAGE COMMANDS

EX NO: 01 DATE: AIM To study the various DDL commands and implement them on the database. COMMANDS SQL> create table stud (sname varchar2(30), sid varchar2(10), sage number(2), sarea varchar2(20)); Table created. SQL> desc stud; Name Null? Type ----------------------------------------------------- -------- -------------------------------SNAME VARCHAR2(30) SID VARCHAR2(10) SAGE NUMBER(2) SAREA VARCHAR2(20) SQL>alter table stud modify ( sage number(10)); Table altered. SQL> alter table stud add ( sdept varchar2(20)); Table altered. SQL> desc stud; Name Null? Type ----------------------------------------------------- -------- -------------------------------SNAME VARCHAR2(30) SID VARCHAR2(10) SAGE NUMBER(10) SAREA VARCHAR2(20) SDEPT VARCHAR2(20) SQL> alter table stud drop ( sdept varchar2(20)); Table altered.

1

SQL> desc studs; Name Null? Type ----------------------------------------------------- -------- -----------------------------------SNAME VARCHAR2(30) SID VARCHAR2(10) SAGE NUMBER(10) SAREA VARCHAR2(20) SQL> truncate table studs; Table truncated. SQL> desc studs; Name Null? Type ----------------------------------------------------- -------- -----------------------------------SNAME VARCHAR2(30) SID VARCHAR2(10) SAGE NUMBER(10) SAREA VARCHAR2(20) SDEPT VARCHAR2(20) SQL> drop table studs; Table dropped.

RESULT Thus the DDL commands were implemented and the output was verified.

2

DATA MANIPULATION LANGUAGE COMMANDS-SET1
EX NO: 2a DATE: AIM To study the various categories of DML commands such as logical operations, aggregate functions, string functions , numeric functions, date functions and conversion functions. THE ORACLE TABLE – DUAL Dual is a small oracle table which consists of only one row and one column and contains the value X in that column. INSERT This command is used to insert values into the table. SELECT This command is used to display the contents of the table or those of a particular column. RENAME This command renames the name of the table. ARITHMETIC OPERATIONS Various operations such as addition, multiplication, subtraction and division can be performed using the numbers available in the table. DISTINCT This keyword is used along with select keyword to display unique values from the specified column. It avoids duplicates during display. CONCATENATION OPERATOR This combines information from two or more columns in a sentence according to the format specified. LOGICAL OPERATORS  AND : The oracle engine will process all rows in a table and displays the result only when all of the conditions specified using the AND operator are specified.  OR : The oracle engine will process all rows in a table and displays the result only when any of the conditions specified using the OR operators are satisfied.  NOT : The oracle engine will process all rows in a table and displays the result only when none of the conditions specified using the NOT operator are specified.  BETWEEN : In order to select data that is within a range of values, the between operator is used. (AND should be included) PATTERN MATCH  LIKE PREDICATE : The use of like predicate is that it allows the comparison of one string value with another string value, which is not identical. This is achieved by using wildcard characters which are % and _. The purpose of % is that it matches any string and _ matches any single character.  IN AND NOT IN PREDICATE : The arithmetic operator = compares a single value to another single value. In case a value needs to be compared to a list of values then the in predicate is used.The not in predicate is the opposite of the in predicate. This will select all the rows whose values do not match all of the values in the list. NUMERIC FUNCTIONS 3

 TO_CHAR(N. It accepts a date as well as the format in which the date has to appear. CONVERSION FUCTIONS  TO_NUMBER(CHAR): It converts the char value containing a number to a value of number data type. DATE FUNCTIONS  SYSDATE : The sysdate is a pseudo column that contains the current date and time. AGGREGATE FUNCTIONS  AVG (N): It returns average value of n ignoring null values.FMT): It converts a value of number data type to a value of char data type.  INITCAP: It returns char with the first letter in upper case. m must be an integer.  LPAD: It returns char1. If fmt is omitted. n must be an integer else an error is returned. FMT): It converts a value of data type to char value.  MIN (EXPR): It returns minimum value of the expression. If char2 is omitted.  MAX (EXPR): It returns maximum value of the expression.  SUBSTR: It returns a portion of char beginning at character m. Fmt must be a date format. left padded to length n with the sequence of characters in char2. using the optional format string. Set is optional. The 1st position of char is one.  RTRIM: It returns char with final characters removed after the last character not in the set. If m is omitted.  POWER: It returns m raised to nth power. it is padded with blanks. n is rounded to zero places. replicated as many times as necessary. char2 defaults to blanks. 4 . date is the default date format.  RPAD: It returns char1. right padded to length n with the characters in char2. STRING FUNCTIONS  LOWER: It returns char with letters in lower case. It accepts a number n and a numeric format fmt in which the number has to appear. n is converted to a char value exactly long enough to hold significant digits. If fmt is omitted.  SUM(N): It returns sum of values of n. If n is omitted result is written up to the end character.  UPPER: It returns char with all letters forced to upper case.  LENGTH: It returns the length of char  LTRIM: It removes characters from the left of char with initial characters removed up to the 1st character not in set.  SQRT: It returns square root of n. It requires no arguments when selected from the table dual and returns the current date.  COUNT (EXPR): It returns the number of rows where expression is not null.  ROUND: It returns n rounded to m places right of the decimal point. It defaults to spaces. exceeding up to n characters. ABS: It returns the absolute value of ‘n’. n should be greater than zero.  COUNT (*): It returns the number of rows in the table including the duplicates and those with null values.  TO_CHAR(DATE.

'anna nagar'.'nungambakkam'. char must be a day of the week.'aerospace').D2): It returns number of months between D1 and D2. 1 row created. SNAME SID SAGE SAREA SDEPT -----------------------------.101. SQL> insert into stud values ('charith'. SQL> insert into stud values ('bhavesh'.'mechanical').'aeronautical').20.18. sarea varchar2(20). ADD_MONTHS(D.  NEXT_DAY(DATE.  LAST_DAY(D): It returns the last date of the month specified with the function  MONTHS_BETWEEN(D1.---------.N): It returns date after adding the number of months specified with the function.104.'anna nagar'. sid varchar2(10). INSERTION OF VALUES INTO THE TABLE SQL> insert into stud values ('ashwin'. 1 row created. Table renamed. SQL> insert into stud values ('pruthvik'. CHAR): It returns the date of the first week day named by char . Table created. sage number(10).103.'marine'). 1 row created. 1 row created.19. sdept varchar2(20)). COMMANDS CREATION OF TABLE SQL>create table stud (sname varchar2(30).102.-------------------.20.--------.'kilpauk'. SQL> select * from stud. 5 .-------------------ashwin 101 19 anna nagar aeronautical bhavesh 102 18 nungambakkam marine pruthvik 103 20 anna nagar aerospace charith 104 20 kilpauk mechanical RENAMING THE TABLE ‘STUD’ SQL> rename stud to studs.

SNAME SAGE -----------------------------.--------ashwin 19 bhavesh 18 BETWEEN OPERATOR SQL> select sname. pruthvik is a aerospace engineer.sage from studs where sage<=19. SNAME SAREA SID -----------------------------. sid+100 "stid" from studs. charith is a mechanical engineer.-------------------.ARITHMETIC OPERATION SQL> select sname. PROFESSION ------------------------------------------------------------------ashwin is a aeronautical engineer.---------bhavesh nungambakkam 102 pruthvik anna nagar 103 6 . SAREA -------------------anna nagar kilpauk nungambakkam USING THE WHERE CLAUSE SQL> select sname.sarea. bhavesh is a marine engineer. ' AS "PROFESSION" from studs. SNAME stid -----------------------------. DISPLAY ONLY DISTINCT VALUES SQL> select distinct sarea from studs.--------ashwin 201 bhavesh 202 pruthvik 203 charith 204 CONCATENATION OPERATOR SQL> select sname || ' is a ' || sdept || ' engineer. sid from studs where sid between 102 and 104.

7 .-------------------. Table altered. sarea from studs where sarea like '%g%'.---------ashwin 101 pruthvik 103 UPDATING THE TABLE SQL> alter table studs add ( spocket varchar2(20) ).104).---------ashwin 101 pruthvik 103 charith 104 NOT IN PREDICATE SQL> select sname.104).sid from studs where sid>102 or sarea='anna nagar'. SNAME SID -----------------------------. SNAME SID -----------------------------. SNAME SAREA SID -----------------------------.charith kilpauk 104 IN PREDICATE SQL> select sname.---------pruthvik 103 LOGICAL OR OPERATOR SQL> select sname . SNAME SID -----------------------------.sid from studs where sid>102 and sarea='anna nagar'.---------bhavesh nungambakkam 102 charith kilpauk 104 PATTERN MATCHING SQL> select sname. SNAME SAREA -----------------------------. sid from studs where sid not in(102. sid from studs where sid in(102.-------------------ashwin anna nagar bhavesh nungambakkam pruthvik anna nagar LOGICAL AND OPERATOR SQL> select sname .sarea .

--------. SNAME SID SAGE SAREA SDEPT -----------------------------. RESULT -------------------100 8 . 1 row updated. SQL> select * from studs. 1 row updated.---------. SQL> update studs set spocket=250 where sid=103. SQL> update studs set spocket=500 where sid=102.-------------------. RESULT --------400 SQL> select min(spocket) result from studs. SQL> update studs set spocket=100 where sid=104.-------------------SPOCKET -------------------ashwin 750 bhavesh 500 pruthvik 250 charith 100 101 102 103 104 19 18 anna nagar nungambakkam aeronautical marine aerospace mechanical 20 anna nagar 20 kilpauk AGGREGATE FUNCTIONS SQL> select avg( spocket ) result from studs. 1 row updated.SQL> update studs set spocket=750 where sid=101. 1 row updated.

RESULT --------2 SQL> select max(spocket) result from studs.2) result from dual.359. RESULT --------1024 SQL> select round(15. RESULT -------------------750 SQL> select sum(spocket) result from studs. RESULT --------9 . RESULT --------4 SQL> select count(*) result from studs.SQL> select count(spocket) result from studs. RESULT --------1600 NUMERIC FUNCTIONS SQL> select abs(-20) result from dual. RESULT --------20 SQL> select power (2. RESULT --------4 SQL> select count(spocket) result from studs where sarea='anna nagar'.10) result from dual.

'^') result from dual.10. RESULT ----racle SQL> select lpad('oracle'.36 SQL> select sqrt (36) result from dual.10. RESULT -----Oracle SQL> select substr('oracle' . RESULT ---------oracle^^^^ CONVERSION FUNCTIONS 10 . RESULT ---------####oracle SQL> select rpad ('oracle'.15.2 .5) result from dual. RESULT --------6 STRING FUNCTIONS SQL> select lower('ORACLE') result from dual. RESULT -----oracle SQL> select upper('oracle') result from dual. RESULT -----ORACLE SQL> select initcap('Oracle') result from dual.'#') result from dual.

-------------------SPOCKET -------------------ashwin 101 18 anna nagar aeronautical 750 bhavesh 102 18 nungambakkam marine 500 pruthvik 103 18 anna nagar aerospace 250 charith 104 18 kilpauk mechanical 100 SQL> select to_char( 17145.-------------------. SYSDATE --------16-JUL-08 SQL> select sysdate.---------.SQL> update studs set sage=to_number(substr(118.145 SQL> select to_char(sysdate. RESULT -------017.--------. SNAME SID SAGE SAREA SDEPT -----------------------------.2.'dd-mon-yyyy') result from dual. SYSDATE RESULT ----------------16-JUL-08 16-NOV-08 SQL> select sysdate. SQL> select * from studs.999') result from dual. 11 .4) result from dual.3)). 4 rows updated.add_months(sysdate. '099. last_day(sysdate) result from dual. RESULT ----------16-jul-2008 DATE FUNCTIONS SQL> select sysdate from dual.

next_day(sysdate.SYSDATE RESULT ----------------16-JUL-08 31-JUL-08 SQL> select sysdate.'sunday') result from dual.935484 RESULT Thus all the DML commands were executed and the output was verified. RESULT --------16. 12 . SYSDATE RESULT ----------------16-JUL-08 20-JUL-08 SQL> select months_between('09-aug-91'.'11-mar-90') result from dual.

HAVING CLAUSE The having clause can be used in conjunction with the group by clause. The output in an intersect clause will include only those rows that are retrieved by both the queries. This optional class tells oracle to group rows based on distinct values that exists for specified columns. Left Outer Join: It takes tuples in the left relation that did not match with any tuple in the right relation. SET OPERATIONS  UNION CLAUSE: Multiple queries can be put together and their output combined using the union clause. set operations.  INTERSECT CLAUSE: Multiple queries can be put together and their output can be combined using the intersect clause. pads the tuples with null values for all other attributes from the left relation and adds them to the result of the natural join. DESCRIPTION ORDER BY CLAUSE The order by clause arranges the contents of the table in ascending order (by default) or in descending order (if specified explicitly) according to the specified column. Having imposes a condition on the group by clause. Full Outer Join: It combines tuples from both the left and the right relation and pads the tuples with null values for the missing attributes and them to the result of the 13 . which further filters the groups created by the group by clause. The union clause merges the output of two or more queries into a single set of rows and columns. GROUP BY CLAUSE The group by clause is another section of the select statement. Right Outer Join: It takes tuples in the right relation that did not match with any tuple in the left relation.  OUTER JOIN: It is an extension of join operation to deal with missing information. join operations and nested queries.DATA MANIPULATION LANGUAGE COMMANDS-SET2 EX NO: 2b DATE: AIM To study the various categories of DML commands such as order by clause. group by clause. pads the tuples with null values for all other attributes from the right relation and adds them to the result of the natural join. The intersect clause outputs only rows produced by both the queries intersected. JOIN OPERATIONS  INNER JOIN/ NATURAL JOIN/ JOIN: It is a binary operation that allows us to combine certain selections and a Cartesian product into one operation.

SAREA -------------------anna nagar nungambakkam kilpauk RESULT -----------1000 500 100 HAVING CLAUSE SQL> select sarea.---------x 1 a 2 g 3 d 4 SQL> select * from emppp56 order by na NAME ID -------------------.---------a 2 d 4 g 3 x 1 GROUP BY CLAUSE SQL> select sarea. sum(spocket) result from studs group by sarea having spocket<600. 1 row deleted. NAME ID -------------------. SAREA -------------------nungambakkam kilpauk RESULT -----------500 100 DELETION SQL> delete from studs where sid=101. ORDER BY CLAUSE SQL> select * from emppp56.natural join. 14 . sum(spocket) result from studs group by sarea.

10010). prodno varchar2(10)).-------------------.---------. 1 row created.--------. SQL> insert into product values('cot'.10110).11010). Table created. SQL> insert into product values('chair'. 1 row created.SQL> select * from studs. SNAME SID SAGE SAREA SDEPT -----------------------------. SQL> insert into product values('desk'. 1 row created.10001). 15 .10010). SQL> SQL> insert into product values('tvstand'. 1 row created.11110). SQL> insert into product values('table'.-------------------SPOCKET ------------------bhavesh 102 18 nungambakkam marine 500 pruthvik 103 20 anna nagar aerospace 250 charith 104 20 kilpauk mechanical 100 CREATING TABLES FOR DOING SET OPERATIONS TO CREATE PRODUCT TABLE SQL> create table product(prodname varchar2(30). SQL> insert into product values('sofa'. 1 row created. 1 row created.

1 row created. Table created. 1 row created. PRODNAME -----------------------------table chair desk cot sofa SET OPERATIONS ORDERNO PRODNO -----------------801 10001 805 10010 809 10110 813 11110 817 10010 16 .---------table 10001 chair 10010 desk 10110 cot 11110 sofa 10010 tvstand 11010 TO CREATE SALE TABLE SQL> create table sale(prodname varchar2(30). 1 row created. 1 row created.10010).813. SQL> insert into sale values('desk'.10110). SQL> insert into sale values('table'. SQL> insert into sale values('sofa'.809. SQL> select * from sale.817.10010). SQL> insert into sale values('cot'.805. 1 row created. SQL> insert into sale values('chair'.orderno number(10). PRODNAME PRODNO -----------------------------.SQL> select * from product.10001).11110).prodno varchar2(10)).801.

SQL> select prodname from product where prodno=10010 union select prodname from sale where prodno=10010; PRODNAME -----------------------------chair sofa SQL> select prodname from product where prodno=11110 intersect select prodname from sale where prodno=11110; PRODNAME -----------------------------cot CREATING TABLES FOR DOING JOIN AND NESTED QUERY OPERATIONS TO CREATE SSTUD1 TABLE SQL> create table sstud1 ( sname varchar2(20) , place varchar2(20)); Table created. SQL> insert into sstud1 values ( 'prajan','chennai'); 1 row created. SQL> insert into sstud1 values ( 'anand','chennai'); 1 row created. SQL> insert into sstud1 values ( 'kumar','chennai'); 1 row created. SQL> insert into sstud1 values ( 'ravi','chennai'); 1 row created. SQL> select * from sstud1; SNAME PLACE -------------------- -------------------prajan chennai anand chennai kumar chennai ravi chennai

17

TO CREATE SSTUD2 TABLE SQL> create table sstud2 ( sname varchar2(20), dept varchar2(10), marks number(10)); Table created. SQL> insert into sstud2 values ('prajan','cse',700); 1 row created. SQL> insert into sstud2 values ('anand','it',650); 1 row created. SQL> insert into sstud2 values ('vasu','cse',680); 1 row created. SQL> insert into sstud2 values ('ravi','it',600); 1 row created. SQL> select * from sstud2; SNAME DEPT MARKS -------------------- ---------- --------prajan cse 700 anand it 650 vasu cse 680 ravi it 600 JOIN OPERATIONS SQL> select sstud1.sname, dept from sstud1 inner join sstud2 on ( sstud1.sname= sstud2.sname); SNAME DEPT -------------------- ---------anand it prajan cse ravi it SQL> select sstud1.sname, dept from sstud1 join sstud2 on ( sstud1.sname= sstud2.sname); SNAME DEPT -------------------- ---------anand it prajan cse 18

ravi

it

SQL> select sstud1.sname, dept from sstud1 left outer join sstud2 on ( sstud1.sname= sstud2.sname); SNAME DEPT -------------------- ---------prajan cse anand it ravi it kumar SQL> select sstud1.sname, dept from sstud1 right outer join sstud2 on ( sstud1.sname= sstud2.sname) SNAME DEPT -------------------- ---------prajan cse anand it ravi it cse SQL> select sstud1.sname, dept from sstud1 full outer join sstud2 on ( sstud1.sname= sstud2.sname); SNAME DEPT -------------------- ---------prajan cse anand it ravi it kumar cse NESTED QUERIES SQL> select sname from sstud1 where sstud1.sname in ( select sstud2.sname from 2 sstud2 ); SNAME -------------------anand prajan ravi

19

SNAME -------------------prajan vasu SQL> select sname from sstud2 where marks > all ( select marks from sstud2 where dept='cse' ).sname not in ( select sstud2.SQL> select sname from sstud1 where sstud1. no rows selected SQL> select sname from sstud2 where marks < all ( select marks from sstud2 where dept='cse' ).sname from sstud2 ). SNAME -------------------prajan SQL> select sname from sstud2 where marks >= some (select marks from sstud2 2 where dept='cse' ). SNAME -------------------anand ravi 20 . SNAME -------------------prajan SQL> select sname from sstud2 where marks >= any ( select marks from sstud2 2 where dept='cse' ). SNAME -------------------prajan vasu SQL> select sname from sstud2 where marks > any ( select marks from sstud2 where dept='cse' ). SNAME -------------------kumar SQL> select sname from sstud2 where marks > some(select marks from sstud2 2 where dept='cse').

sname ).sname=sstud2. SNAME -------------------Kumar SQL> select ename from e234 where exists(select * from e234).sname ).sname=sstud2. ENAME -------------------x y z a c SQL> select ename from e234 where not exists(select * from e234).sname from sstud2 2 where sstud1. NAME ID -------------------.sname from 2 sstud2 where sstud1. no rows selected TO RENAME A COLUMN SQL> select * from emppp56. SNAME -------------------prajan anand ravi SQL> select sname from sstud1 where not exists ( select sstud2.---------x 1 a 2 g 3 d 4 SQL> alter table emppp56 rename column name to emp_name.SQL> select sname from sstud1 where exists ( select sstud2. Table altered. 21 .

SQL> desc emppp56.---------x 1 a 2 g 3 d 4 RESULT Thus all the DML commands were executed and the output was verified.---------------------------EMP_NAME VARCHAR2(20) ID NUMBER SQL> select * from emppp56.-------. 22 . Name Null? Type ----------------------------------------. EMP_NAME ID -------------------.

1) 23 .DOMAIN CONSTRAINT NULL CONSTRAINT SQL> create table customer(cname varchar2(20). Integrity Constraints 1. Enter value for cname: x Enter value for accno: 1 old 1: insert into customer values('&cname'. SQL> desc customer. Table created. Referential Constraint a)FOREIGN KEY 1.---------------------------CNAME VARCHAR2(20) ACCNO NUMBER SQL> insert into customer values('&cname'.&accno). Entity Constraint a)UNIQUE b)PRIMARY KEY 3.&accno) new 1: insert into customer values('x'.-------.Domain Constraint a)NULL CONSTRAINT B)NOT NULL CONSTRAINT c)CHECK CONSTRAINT 2. Name Null? Type ----------------------------------------.INTEGRITY CONSTRAINTS EX NO: 3 DATE: AIM To study the various Integrity constraints available in the SQL query language.accno number constraint consn null).

SQL> select * from customer. SQL> select * from customer.---------x 1 y 2 z SQL> update customer set accno=3 where cname='z'. 1 row updated.null) 1 row created. Enter value for cname: z Enter value for accno: null old 1: insert into customer values('&cname'. CNAME ACCNO -------------------.---------x 1 y 2 z 3 NOT NULL CONSTRAINT 24 .1 row created. SQL> insert into customer values('&cname'. CNAME ACCNO -------------------.&accno) new 1: insert into customer values('y'.&accno).&accno) new 1: insert into customer values('z'. SQL> / Enter value for cname: y Enter value for accno: 2 old 1: insert into customer values('&cname'.2) 1 row created.

Enter value for cname: x Enter value for loan_no: 1 old 1: insert into borrower values('&cname'.&loan_no)."LOAN_NO") SQL> / Enter value for cname: a Enter value for loan_no: old 1: insert into borrower values('&cname'."BORROWER".2) 1 row created.SQL> create table borrower(cname varchar2(20). SQL> / Enter value for cname: y Enter value for loan_no: 2 old 1: insert into borrower values('&cname'.null) insert into borrower values('z'. SQL> / Enter value for cname: z Enter value for loan_no: null old 1: insert into borrower values('&cname'. Table created.null) * ERROR at line 1: ORA-01400: cannot insert NULL into ("SCOTT". SQL> insert into borrower values('&cname'.) insert into borrower values('a'.1) 1 row created.) * ERROR at line 1: ORA-00936: missing expression SQL> select * from borrower. CNAME LOAN_NO 25 .&loan_no) new 1: insert into borrower values('x'.loan_no number constraint consl not null).&loan_no) new 1: insert into borrower values('a'.&loan_no) new 1: insert into borrower values('y'.&loan_no) new 1: insert into borrower values('z'.

10000) 1 row created. Enter value for cname: x Enter value for balance: 10000 old 1: insert into withdraw values('&cname'.-------------------.20000) 1 row created. SQL> insert into withdraw values('&cname'.&balance) new 1: insert into withdraw values('x'. SQL> / Enter value for cname: y Enter value for balance: 200 old 1: insert into withdraw values('&cname'.200) insert into withdraw values('y'.&balance) new 1: insert into withdraw values('y'.balance number constraint consc check(balance>500)). CNAME BALANCE -------------------.200) * ERROR at line 1: ORA-02290: check constraint (SCOTT. SQL> select * from withdraw.---------x 1 y 2 CHECK CONSTRAINT SQL> create table withdraw(cname varchar2(20).&balance). Table created.&balance) new 1: insert into withdraw values('y'.---------26 .CONSC) violated SQL> / Enter value for cname: y Enter value for balance: 20000 old 1: insert into withdraw values('&cname'.

'tcs'.'madurai') 1 row created.'&place') new 1: insert into company1 values('y'. Table created.CONSC) violated SQL> create table company1(ename varchar2(20).x y 10000 20000 SQL> update withdraw set balance=balance-9700 where cname='x'.'chennai') 1 row created.'maadurai') * ERROR at line 1: ORA-02290: check constraint (SCOTT.'&place') new 1: insert into company1 values('y'. SQL> insert into company1 values('&emane'.'&place').'tcs'.'tcs'.'madurai'. Enter value for emane: x Enter value for cname: tcs Enter value for place: chennai old 1: insert into company1 values('&emane'.'&cname'. SQL> / Enter value for emane: y Enter value for cname: tcs Enter value for place: maadurai old 1: insert into company1 values('&emane'. update withdraw set balance=balance-9700 where cname='x' * ERROR at line 1: ORA-02290: check constraint (SCOTT.place varchar2(20) constraint consp check(place in ('chennai'.'&place') new 1: insert into company1 values('x'.cname varchar2(20).'maadurai') insert into company1 values('y'.CONSP) violated SQL> / Enter value for emane: y Enter value for cname: tcs Enter value for place: madurai old 1: insert into company1 values('&emane'.'trichy'))).'&cname'.'&cname'. 27 .'tcs'.'&cname'.

'adyar') insert into company1 values('z'.'&location') 28 .'&cname'.-------------------x tcs chennai y tcs madurai SQL> update company1 set place='vadapalani' where ename='x'. Name Null? Type ----------------------------------------.ENTITY INTEGRITY CONSTRAINT UNIQUE CONSTRAINT SQL> create table company(comp_name varchar2(20) not null unique. Table created.-------------------.'wipro'.-------.CONSP) violated SQL> select * from company1. update company1 set place='vadapalani' where ename='x' * ERROR at line 1: ORA-02290: check constraint (SCOTT. SQL> desc company.'wipro'. ENAME CNAME PLACE -------------------.location varchar2(20) not null uniq ue).---------------------------COMP_NAME NOT NULL VARCHAR2(20) LOCATION NOT NULL VARCHAR2(20) SQL> insert into company values('&comp_name'. Enter value for comp_name: tcs Enter value for location: vadapalani old 1: insert into company values('&comp_name'.'adyar') * ERROR at line 1: ORA-02290: check constraint (SCOTT.'&location').'&place') new 1: insert into company1 values('z'.SQL> / Enter value for emane: z Enter value for cname: wipro Enter value for place: adyar old 1: insert into company1 values('&emane'.CONSP) violated 2.

'&location') new 1: insert into company values('cts'.'&location') new 1: insert into company values('tcs'.SYS_C003014) violated SQL> / Enter value for comp_name: cts Enter value for location: vadapalani old 1: insert into company values('&comp_name'.'vadapalani') 1 row created.'padi') insert into company values(''.SYS_C003015) violated SQL> / Enter value for comp_name: null Enter value for location: solinganalur old 1: insert into company values('&comp_name'.'solinganalur') 1 row created.'&location') new 1: insert into company values(''.'adyar') * ERROR at line 1: ORA-00001: unique constraint (SCOTT.'adyar') insert into company values('tcs'. SQL> / Enter value for comp_name: tcs Enter value for location: adyar old 1: insert into company values('&comp_name'.'&location') new 1: insert into company values('null'.new 1: insert into company values('tcs'."COMPANY". SQL> / Enter value for comp_name: Enter value for location: padi old 1: insert into company values('&comp_name'.'padi') * ERROR at line 1: ORA-01400: cannot insert NULL into ("SCOTT".'vadapalani') * ERROR at line 1: ORA-00001: unique constraint (SCOTT."COMP_NAME") 29 .'vadapalani') insert into company values('cts'.

'&location') new 1: insert into company values('wipro'. SQL> insert into account values(&accno)."COMPANY". Enter value for accno: 1 old 1: insert into account values(&accno) new 1: insert into account values(1) 1 row created.-------------------tcs vadapalani null solinganalur SQL> create table account(accno number constraint consu unique).'') * ERROR at line 1: ORA-01400: cannot insert NULL into ("SCOTT". SQL> / Enter value for accno: 2 30 . SQL> / Enter value for accno: 2 old 1: insert into account values(&accno) new 1: insert into account values(2) 1 row created."LOCATION") SQL> select * from company.'') insert into company values('wipro'. Table created. SQL> / Enter value for accno: 3 old 1: insert into account values(&accno) new 1: insert into account values(3) 1 row created. COMP_NAME LOCATION -------------------.SQL> / Enter value for comp_name: wipro Enter value for location: old 1: insert into company values('&comp_name'.

1 row updated. 31 .old 1: insert into account values(&accno) new 1: insert into account values(2) insert into account values(2) * ERROR at line 1: ORA-00001: unique constraint (SCOTT. SQL> desc account. Name Null? Type ----------------------------------------. Table altered.---------------------------ACCNO NUMBER CNAME VARCHAR2(20) SQL> select * from account.-------.-------------------1 2 3 SQL> update account set cname='y' where accno=1. Name Null? Type ----------------------------------------. 1 row updated. SQL> update account set cname='z' where accno=2.---------------------------ACCNO NUMBER CNAME VARCHAR2(20) SQL> alter table account add constraint consuu unique(cname). Table altered. ACCNO CNAME ---------.-------. SQL> desc account.CONSU) violated SQL> alter table account add(cname varchar2(20)).

SQL> update account set cname='a' where accno=3; 1 row updated. SQL> select * from account; ACCNO CNAME ---------- -------------------1y 2z 3a SQL> create table depositor(cname varchar2(20),accno number,constraint consuni unique(cname,accno)); Table created. SQL> insert into depositor values('&cname',&accno); Enter value for cname: x Enter value for accno: 1 old 1: insert into depositor values('&cname',&accno) new 1: insert into depositor values('x',1) 1 row created. SQL> / Enter value for cname: x Enter value for accno: 2 old 1: insert into depositor values('&cname',&accno) new 1: insert into depositor values('x',2) 1 row created. SQL> / Enter value for cname: y Enter value for accno: 2 old 1: insert into depositor values('&cname',&accno) new 1: insert into depositor values('y',2) 1 row created. SQL> / Enter value for cname: y Enter value for accno: 2 32

old 1: insert into depositor values('&cname',&accno) new 1: insert into depositor values('y',2) insert into depositor values('y',2) * ERROR at line 1: ORA-00001: unique constraint (SCOTT.CONSUNI) violated CNAME ACCNO -------------------- ---------x 1 x 2 y 2 PRIMARY KEY AND FOREIGN KEY CONSTRAINTS SQL> create table empv(name varchar2(20),id number not null constraint cons_pri primary key); Table created. SQL> desc empv; Name Null? Type ----------------------------------------- -------- ---------------------------NAME VARCHAR2(20) ID NOT NULL NUMBER SQL> insert into empv values('&name',&id); Enter value for name: john Enter value for id: 11 old 1: insert into empv values('&name',&id) new 1: insert into empv values('john',11) 1 row created. SQL> / Enter value for name: henry Enter value for id: 11 old 1: insert into empv values('&name',&id) new 1: insert into empv values('henry',11) insert into empv values('henry',11) * ERROR at line 1: ORA-00001: unique constraint (SCOTT.CONS_PRI) violated SQL> / Enter value for name: henry 33

Enter value for id: 12 old 1: insert into empv values('&name',&id) new 1: insert into empv values('henry',12) 1 row created. SQL> select * from empv; NAME ID -------------------- ---------john 11 henry 12 SQL> create table project(pname varchar2(20),id number not null,constraint cons_fr foreign key(id) references empv(id)); Table created. SQL> desc project; Name Null? Type ----------------------------------------- -------- ---------------------------PNAME VARCHAR2(20) ID NOT NULL NUMBER SQL> insert into project values('&pname',&id); Enter value for pname: banking_system Enter value for id: 11 old 1: insert into project values('&pname',&id) new 1: insert into project values('banking_system',11) 1 row created. SQL> / Enter value for pname: banking_system Enter value for id: 12 old 1: insert into project values('&pname',&id) new 1: insert into project values('banking_system',12) 1 row created. SQL> / Enter value for pname: airline Enter value for id: 11 old 1: insert into project values('&pname',&id) 34

&id) new 1: insert into project values('payroll'.-------------------john 11 banking_system henry 12 banking_system john 11 airline henry 12 payroll TO DISABLE THE RESPECTIVE CONSTRAINT SQL> alter table empv disable constraint cons_pri.pname from empv. SQL> insert into empv values('&name'. Enter value for name: korth Enter value for id: 12 old 1: insert into empv values('&name'. NAME ID PNAME -------------------.&id).id.id=project. SQL> select * from project.11) 1 row created.&id) 35 .id. Table altered.project where empv.---------. PNAME ID -------------------.empv.12) 1 row created. SQL> / Enter value for pname: payroll Enter value for id: 12 old 1: insert into project values('&pname'.new 1: insert into project values('airline'.---------banking_system 11 banking_system 12 airline 11 payroll 12 SQL> select name.

SQL> select * from empv. NAME ID -------------------. SQL> select * from empv. SQL> desc empv.new 1: insert into empv values('korth'. NAME ID -------------------.primary key violated SQL> update empv set id=13 where name='korth'.-------. Table altered.CONS_PRI) . alter table empv enable constraint cons_pri * ERROR at line 1: ORA-02437: cannot validate (SCOTT.12) 1 row created.---------john 11 henry 12 korth 12 TO ENABLE THE RESPECTIVE CONSTRAINT SQL> alter table empv enable constraint cons_pri. 1 row updated.---------------------------NAME VARCHAR2(20) ID NOT NULL NUMBER 36 .---------john 11 henry 12 korth 13 SQL> alter table empv enable constraint cons_pri. Name Null? Type ----------------------------------------.

---------------------------DNO NOT NULL NUMBER 37 . SQL> desc emp1. Table created. SQL> alter table emp1 add constraint con_eid primary key(eid). Enter value for name: smith Enter value for id: 13 old 1: insert into empv values('&name'.dname varchar2(15)).&id). Table created.13) * ERROR at line 1: ORA-00001: unique constraint (SCOTT.eid number). SQL> alter table emp1 add(dno number).CONS_PRI) violated SQL> create table emp1(ename varchar2(15).SQL> insert into empv values('&name'.&id) new 1: insert into empv values('smith'. Name Null? Type ----------------------------------------.-------.13) insert into empv values('smith'. Table altered.-------. Table altered. SQL> desc dept1. Name Null? Type ----------------------------------------. SQL> alter table dept1 add constraint con_dno primary key(dno). Table altered.---------------------------ENAME VARCHAR2(15) EID NOT NULL NUMBER DNO NUMBER SQL> alter table emp1 add constraint conf_dno foreign key(dno) references dept1(dno). SQL> create table dept1(dno number. Table altered.

'&dname') new 1: insert into dept1 values(2.DNAME VARCHAR2(15) SQL> insert into emp1 values('&ename'. Enter value for dno: 1 Enter value for dname: eee old 1: insert into dept1 values(&dno.1. SQL> insert into dept1 values(&dno.'it') 1 row created.'cse') 1 row created.1) * ERROR at line 1: ORA-02291: integrity constraint (SCOTT. Enter value for dno: 1 Enter value for dname: it old 1: insert into dept1 values(&dno.'eee') * 38 .'&dname'). SQL> / Enter value for dno: 3 Enter value for dname: ece old 1: insert into dept1 values(&dno. SQL> / Enter value for dno: 2 Enter value for dname: cse old 1: insert into dept1 values(&dno.'&dname') new 1: insert into dept1 values(1.'&dname').CONF_DNO) violated .1) insert into emp1 values('x'.&eid.&eid.'&dname') new 1: insert into dept1 values(3.'ece') 1 row created.'eee') insert into dept1 values(1.1.parent key not found SQL> insert into dept1 values(&dno.&dno).&dno) new 1: insert into emp1 values('x'. Enter value for ename: x Enter value for eid: 1 Enter value for dno: 1 old 1: insert into emp1 values('&ename'.'&dname') new 1: insert into dept1 values(1.

SQL> / Enter value for ename: y Enter value for eid: 2 Enter value for dno: 1 old 1: insert into emp1 values('&ename'.1.&dno) new 1: insert into emp1 values('a'.&eid.&dno) new 1: insert into emp1 values('y'.&eid.ERROR at line 1: ORA-00001: unique constraint (SCOTT.CON_DNO) violated SQL> select * from dept1. SQL> / Enter value for ename: b Enter value for eid: 4 Enter value for dno: 2 old 1: insert into emp1 values('&ename'.2.1) 1 row created.3.&eid.2) 1 row created.&eid. DNO DNAME ---------.&dno). 39 .&dno) new 1: insert into emp1 values('x'.&dno) new 1: insert into emp1 values('b'.4.1) 1 row created.&eid.--------------1 it 2 cse 3 ece SQL> insert into emp1 values('&ename'.1) 1 row created. SQL> / Enter value for ename: a Enter value for eid: 3 Enter value for dno: 1 old 1: insert into emp1 values('&ename'. Enter value for ename: x Enter value for eid: 1 Enter value for dno: 1 old 1: insert into emp1 values('&ename'.

3) 1 row created.&eid.&dno) new 1: insert into emp1 values('e'.&dno) new 1: insert into emp1 values('e'. SQL> / Enter value for ename: d Enter value for eid: 6 Enter value for dno: 3 old 1: insert into emp1 values('&ename'. ENAME EID DNO --------------.CON_EID) violated SQL> / Enter value for ename: e Enter value for eid: 7 Enter value for dno: 3 old 1: insert into emp1 values('&ename'.3) 1 row created.SQL> / Enter value for ename: c Enter value for eid: 5 Enter value for dno: 2 old 1: insert into emp1 values('&ename'. SQL> select * from emp1.5.&eid.6.6.&dno) new 1: insert into emp1 values('d'.2) 1 row created.3) * ERROR at line 1: ORA-00001: unique constraint (SCOTT.---------x 1 1 y 2 1 40 .3) insert into emp1 values('e'. SQL> / Enter value for ename: e Enter value for eid: 6 Enter value for dno: 3 old 1: insert into emp1 values('&ename'.7.&eid.---------.6.&eid.&dno) new 1: insert into emp1 values('c'.

dno=dept1.dept1 where emp1.dept1 where emp1.--------------x it y it a it b cse c cse d ece e ece 7 rows selected. SQL> select ename. SQL> select ename.dno and dname='it'.dno=dept1.dno=dept1.dname from emp1.dname from emp1.--------------1 it 2 cse 3 ece SQL> select * from emp1. DNO DNAME ---------. ENAME EID DNO DNO DNAME --------------. 41 .dept1 where emp1.---------.dno.---------.a b c d e 7 rows selected.dno.---------. 3 4 5 6 7 1 2 2 3 3 SQL> select * from dept1. ENAME DNAME --------------.--------------x 1 1 1 it y 2 1 1 it a 3 1 1 it b 4 2 2 cse c 5 2 2 cse d 6 3 3 ece e 7 3 3 ece 7 rows selected.

SQL> insert into emp1 values('&ename'.4) insert into emp1 values('f'.dno.&eid.CONF_DNO) violated .ENAME DNAME --------------.parent key not found SQL> / Enter value for ename: f Enter value for eid: 8 Enter value for dno: 2 old 1: insert into emp1 values('&ename'.dname from emp1.&eid.&eid.dept1 where emp1.8.dept1 where emp1.dname from emp1. select ename.dno.dept1 where emp1.&dno).--------------x it y it a it SQL> select ename.4) * ERROR at line 1: ORA-02291: integrity constraint (SCOTT.dno * ERROR at line 1: ORA-00918: column ambiguously defined SQL> select ename.--------------x 1 it y 1 it a 1 it b 2 cse c 2 cse d 3 ece e 3 ece 7 rows selected.dno=dept1. ENAME DNO DNAME --------------.dno.8.dno.8.dno=dept1.dno=dept1. Enter value for ename: f Enter value for eid: 8 Enter value for dno: 4 old 1: insert into emp1 values('&ename'.2) 42 .---------.&dno) new 1: insert into emp1 values('f'.dno.emp1.&dno) new 1: insert into emp1 values('f'.dname from emp1.

SQL> select * from emp1.---------x 1 1 y 2 1 a 3 1 b 4 2 c 5 2 d 6 3 e 7 3 f 8 2 8 rows selected.---------.1 row created. ENAME EID DNO --------------. 43 .

Find the names of all employees in this database who live in the same city as the company for which they work.1000. 12. 3. 11. Update the salary of ‘bbc’ employees by Rs. Find the names of all employees who are living in Chennai. 20. Display the details of all employees in a sorted order.city) Manages(ename. 10. Identify all possible primary key and foreign key. Find the names of all employees who work for the ‘fbc’. Set a NOT NULL constraint for the salary column. 22. 44 . Hence the output was verified. Delete the record of employee ‘john’. SQL APPLICATION 1 EX. Find the names of all employees who do not work for fbc. 15. 6. Employee(ename.NO:4a DATE: Consider the following relational schemas for the employee database. 8. Create a view to store the companyname and the number of employees in each company and do all possible manipulations on the view. Create a view to store the employee name and the companyname and find out the type of view.salary) Company(companyname.mname) 1. 18. 4. 16. 9. Add a new column manager_no onto the manages relation. 14. Find the names of all employees whose first letter is ‘a’.city. If not justify your answer. 13. Find the names. Find the names of all employees who do have manager. Change the name of the companyname column to cname.RESULT Thus the various constraints were implemented and the tables were created using the respective constraints. 17. Find the names of all employees who do not have manager. 2. Find the names of all employees whose salary is in the range 100000 to 200000. Find the names of all employees where fifth letter is ‘y’. 19. 7.companyname.street) Works(ename. Find the companyname which has got the highest total salary. street addresses and cities of all employees who work for the ‘fbc’ and earn more than 200000 per annum. 21. 5. Find the names of all employees who are not living in Bangalore and Hyderabad. Find the names of all employees who earn more than every employee of sbc.

street varchar2(20)).'chennai'.'ambedkar’) 1 row created.'&city'.'kamarajar’) 1 row created.'&street’) new 1: insert into employee values('vijay'. Table created. SQL> / Enter value for ename: john Enter value for city: bangalore Enter value for street: ambedkar old 1: insert into employee values('&ename'. Table created.city varchar2(20).'&street'). SQL> create table works(ename varchar2(20). SQL> create table manages(ename varchar2(20). Table created.'&street’) new 1: insert into employee values('john'.'hyderabad'.'&city'.city varchar2(20)).companyname varchar2(20).'&city'. SQL> insert into employee values('&ename'.'rajiv’) 45 . Table created.'&city'. SQL> create table company(companyname varchar2(20).'bangalore'.salary number). SQL> / Enter value for ename: vijay Enter value for city: hyderabad Enter value for street: rajiv old 1: insert into employee values('&ename'.mname varchar2(20)). Enter value for ename: ajith Enter value for city: chennai Enter value for street: kamarajar old 1: insert into employee values('&ename'.'&street’) new 1: insert into employee values('ajith'.SQL> create table employee(ename varchar2(20).

150000) 1 row created.'&companyname'.-------------------ajith chennai kamarajar john bangalore ambedkar vijay hyderabad rajiv siva chennai kamarajar SQL> insert into works values('&ename'.'&companyname'.-------------------.&salary).&salary) new 1: insert into works values('ajith'.'kamarajar’) 1 row created.'fbc'. SQL> / Enter value for ename: siva Enter value for city: chennai Enter value for street: kamarajar old 1: insert into employee values('&ename'.300000) 1 row created. ENAME CITY STREET -------------------. SQL> / 46 .1 row created.&salary) new 1: insert into works values('john'. Enter value for ename: ajith Enter value for companyname: fbc Enter value for salary: 300000 old 1: insert into works values('&ename'.'&street’) new 1: insert into employee values('siva'. SQL> / Enter value for ename: john Enter value for companyname: sbc Enter value for salary: 150000 old 1: insert into works values('&ename'.'chennai'.'&companyname'. SQL> select * from employee.'&city'.'sbc'.

Enter value for ename: vijay Enter value for companyname: bbc Enter value for salary: 200000 old 1: insert into works values('&ename'.'bbc'. SQL> / Enter value for companyname: sbc Enter value for city: bangalore old 1: insert into company values('&companyname'.'&city') new 1: insert into company values('sbc'.200000) 1 row created.'chennai') 1 row created.'&companyname'.'&city') new 1: insert into company values('fbc'.'bangalore') 1 row created. ENAME COMPANYNAME -------------------. Enter value for companyname: fbc Enter value for city: chennai old 1: insert into company values('&companyname'. SQL> select * from works. SQL> / Enter value for ename: siva Enter value for companyname: fbc Enter value for salary: 400000 old 1: insert into works values('&ename'.'&city'). 47 .400000) 1 row created.&salary) new 1: insert into works values('siva'.'&companyname'.-------------------.&salary) new 1: insert into works values('vijay'.--------ajith fbc 300000 john sbc 150000 vijay bbc 200000 siva fbc 400000 SALARY SQL> insert into company values('&companyname'.'fbc'.

'&mname') new 1: insert into manages values('ajith'. SQL> select * from company.-------------------fbc chennai sbc bangalore bbc hyderabad SQL> insert into manages values('&ename'.'') 1 row created. Enter value for ename: ajith Enter value for mname: smith old 1: insert into manages values('&ename'.'henry') 1 row created.'&mname') new 1: insert into manages values('john'.'&mname') new 1: insert into manages values('vijay'.'hyderabad') 1 row created.SQL> / Enter value for companyname: bbc Enter value for city: hyderabad old 1: insert into company values('&companyname'.'') 48 . SQL> / Enter value for ename: vijay Enter value for mname: henry old 1: insert into manages values('&ename'.'&mname') new 1: insert into manages values('siva'. COMPANYNAME CITY -------------------. SQL> / Enter value for ename: john Enter value for mname: old 1: insert into manages values('&ename'.'&city') new 1: insert into company values('bbc'.'&mname'). SQL> / Enter value for ename: siva Enter value for mname: old 1: insert into manages values('&ename'.'smith') 1 row created.

ENAME STREET CITY -------------------. ENAME -------------------ajith siva SQL> select ename.street.company where employee. ENAME 49 .1 row created.street.ename 2 and employee.works.ename.-------------------ajith kamarajar chennai siva kamarajar chennai SQL> select employee.companyname.-------------------ajith kamarajar chennai siva kamarajar chennai SQL> select works.-------------------ajith smith john vijay henry siva SQL> select ename from works where companyname='fbc'.companyname=company.-------------------.city=company.city from employee inner join works on employee.ename=works.city from employee where ename in (select ename from works where 2 companyname='fbc' and salary>200000).-------------------.city and works.ename 2 where companyname='fbc' and salary>200000. ENAME STREET CITY -------------------. SQL> select * from manages. ENAME MNAME -------------------.ename from employee.ename=works.

companyname.city=company.companyname=company.city and works.ename 2 inner join company on employee.ename from employee inner join works on employee. ENAME -------------------ajith vijay siva SQL> select ename from works where salary >all (select max(salary) 2 from works where companyname='sbc'). 50 .-------------------ajith john siva vijay SQL> select employee. ENAME -------------------ajith john siva vijay SQL> select ename from works where salary>(select max(salary) from works where companyname='sbc'). ENAME -------------------ajith vijay siva SQL> select ename from works where companyname not in ('fbc'). ENAME -------------------john vijay SQL> select ename from works where companyname!='fbc'.ename=works.

street varchar2(20)). SQL> create view v1(cname. ENAME -------------------john siva SQL> select ename from manages where mname is not null.ENAME -------------------john vijay SQL> select ename from manages where mname is null. ENAME -------------------ajith vijay SQL> create table employee(ename varchar2(20) constraint con1 primary key. 2 city varchar2(20). SQL> create table works(ename varchar2(20).companyname varchar2(20).no_of_employees) as (select companyname. 2 city varchar2(20)).salary number. 2 constraint con3 foreign key (ename) references employee(ename).constraint con5 2 foreign key (ename) references employee (ename)).count(ename) from works 2 group by companyname). 51 . SQL> create table manages(ename varchar2(20). SQL> create table company(companyname varchar2(20) constraint con2 primary key.constraint con4 3 foreign key (companyname) references company(companyname)).mname varchar2(20).

COMPANYNAME -------------------fbc SQL> select ename from employee where ename like 'a%'.sum(salary) from works group by 2 companyname having sum(salary)=(select max(sum(salary)) from works group by companyname)).--------------bbc 1 fbc 2 sbc 1 SQL> update v1 set cname='hsbc' where no_of_employees=2. SQL> select * from employee.View created. update v1 set cname='hsbc' where no_of_employees=2 * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view SQL> select companyname from (select companyname.-------------------. SQL> select * from v1. ENAME -------------------ajith SQL> delete from employee where ename='john'.-------------------52 . ENAME CITY STREET -------------------. CNAME NO_OF_EMPLOYEES -------------------. 1 row deleted.

'hyderabad'). ENAME -------------------ajith siva SQL> select ename from employee where city not in ('bangalore'. ENAME -------------------ajith siva SQL> update works set salary=salary+1000 where companyname='bbc'.-------------------.ajith vijay siva chennai hyderabad chennai kamarajar rajiv kamarajar SQL> select * from employee order by ename.-------------------. 1 row updated. SQL> select * from works. ENAME CITY STREET -------------------. ENAME COMPANYNAME -------------------.--------ajith fbc 300000 john sbc 150000 vijay bbc 201000 siva fbc 400000 SALARY 53 .-------------------ajith chennai kamarajar siva chennai kamarajar vijay hyderabad rajiv SQL> select ename from employee where city in 'chennai'.

Table altered.companyname varchar2(20).SQL> alter table manages add(manager_no number).---------ajith smith john vijay henry siva SQL> create table works (ename varchar2(20).-------------------. ENAME -------------------john SQL> create view v2 as (select ename. View created. ENAME MNAME MANAGER_NO -------------------. 54 .salary number 2 constraint con6 not null). SQL> select ename from employee where ename like '____y%'.companyname from works). ENAME -------------------vijay SQL> select ename from works where salary between 100000 and 200000. SQL> select * from manages.

ENAME COMPANYNAME -------------------. Table altered.-------------------ajith john vijay siva fbc sbc bbc fbc SQL> alter table works rename column companyname to cname. SQL> select * from works. ENAME CNAME SALARY -------------------.SQL> select * from v2.-------------------.--------ajith fbc 300000 john sbc 150000 vijay bbc 201000 siva fbc 400000 RESULT: Thus the sql application1 is executed and the required output is obtained 55 .

employee(eno.basicpay number.dob varchar2(20).'&dob'.designation.dno) 4.dno) 2.dateworked.'&designation'. SQL> create table department(dno number.'&doj'. SQL> create table workfor(eno number.SQL APPLICATION-2 EX NO:4b DATE: Consider the company database. SQL> insert into employee values(&eno.outtime) SQL> create table employee(eno number.dname varchar2(20)).dob.pname. 2 &dno).intime varchar2(20).department(dno.dateworked varchar2(20).'&ename'. 2 doj varchar2(20).project(pno.pname varchar2(20).pno number.ename.dno number).dno number). SQL> create table project(pno number.doj. Table created.pno. Enter value for eno: 101 Enter value for ename: ram Enter value for dob: 18 NOV 1990 Enter value for gender: male Enter value for doj: 2 NOV 2005 56 .ename varchar2(20).'&gender'.intime.designation varchar2(20).workfor(eno. The schemas are 1. Table created.gender.dname) 3. Table created.gender varchar2(20). 2 outtime varchar2(20)).basicpay.&basicpay. Table created.

'male'.'team leader'.'&dob'.150 Enter value for dno: 2 old 2: &dno) 57 .'&doj'.'rahul'.'2 NOV 2005'. new 1: insert into employee values(102.'&dob'. Enter value for dno: 1 old 2: &dno) new 2: 1) 1 row created.'&ename'.'&designation'.'&gender'.'ram'.'4 MAR 2005'.'male'.'3 FEB 2005'.'21 JAN 1990'.30000. new 1: insert into employee values(103.&basicpay.'&designation'.'elango'.'22 FEB 1989'.'&gender'.25 Enter value for dno: 2 old 2: &dno) new 2: 2) 1 row created.'18 NOV 1990'.'&designation'.'male'.'&ename'.'manager'.&basicpay.'&doj'.'&doj'.&basicpay. SQL> / Enter value for eno: 103 Enter value for ename: rahul Enter value for dob: 22 FEB 1989 Enter value for gender: male Enter value for doj: 4 MAR 2005 Enter value for designation: team member Enter value for basicpay: 15000 old 1: insert into employee values(&eno.'&gender'.'&ename'.Enter value for designation: manager Enter value for basicpay: 30000 old 1: insert into employee values(&eno. SQL> / Enter value for eno: 102 Enter value for ename: elango Enter value for dob: 21 JAN 1990 Enter value for gender: male Enter value for doj: 3 FEB 2005 Enter value for designation: team leader Enter value for basicpay: 25000 old 1: insert into employee values(&eno.'&dob'.'teammember'. new 1: insert into employee values(101.

'25 SEP 1985'.'&designation'.'&ename'.-------------------.'team member'.-------------------58 .'male'.'2 AUG 2005'.160 Enter value for dno: 3 old 2: &dno) new 2: 3) 1 row created. new 1: insert into employee values(104.'&dob'. SQL> / Enter value for eno: 105 Enter value for ename: ajith Enter value for dob: 25 SEP 1985 Enter value for gender: male Enter value for doj: 2 AUG 2005 Enter value for designation: team member Enter value for basicpay: 16000 old 1: insert into employee values(&eno.'5 SEP 2005'.'17 MAR 1982'.'&gender'.'sethu'.'&gender'.'&dob'.-------------------.'&doj'.140 Enter value for dno: 2 old 2: &dno) new 2: 2) 1 row created. ENO ENAME DOB GENDER ---------.&basicpay.'&designation'.&basicpay. SQL> select * from employee.'male'. SQL> / Enter value for eno: 104 Enter value for ename: sethu Enter value for dob: 17 MAR 1982 Enter value for gender: male Enter value for doj: 5 SEP 2005 Enter value for designation: teammember Enter value for basicpay: 14000 old 1: insert into employee values(&eno.new 2: 2) 1 row created.'&doj'. new 1: insert into employee values(105.'ajith'.'teammember'.'&ename'.

-------------------.-------------------.---------101 ram 18 NOV 1990 male 2 NOV 2005 manager 30000 1 DNO 102 elango 3 FEB 2005 103 rahul 4 MAR 2005 21 JAN 1990 team leader 22 FEB 1989 teammember male 25000 male 15000 2 2 ENO ENAME DOB GENDER ---------.---------.'cse') 1 row created.---------104 sethu 17 MAR 1982 male 5 SEP 2005 teammember 14000 2 105 ajith 2 AUG 2005 25 SEP 1985 team member male 16000 3 SQL> insert into department values(&dno.'&dname') new 1: insert into department values(2.'&dname') new 1: insert into department values(3. Enter value for dno: 1 Enter value for dname: it old 1: insert into department values(&dno. SQL> / Enter value for dno: 3 Enter value for dname: ece old 1: insert into department values(&dno.-------------------.'it') 1 row created.'ece') 59 .-------------------DOJ DESIGNATION BASICPAY DNO -------------------.---------.-------------------.'&dname') new 1: insert into department values(1. SQL> / Enter value for dno: 2 Enter value for dname: cse old 1: insert into department values(&dno.DOJ DESIGNATION BASICPAY -------------------.'&dname').

'banking'. DNO DNAME ---------.3) 1 row created. SQL> select * from department.---------60 . Enter value for pno: 201 Enter value for pname: banking Enter value for dno: 2 old 1: insert into project values(&pno.1 row created.-------------------.-------------------1 it 2 cse 3 ece SQL> insert into project values(&pno. SQL> / Enter value for pno: 202 Enter value for pname: airline Enter value for dno: 1 old 1: insert into project values(&pno. SQL> select * from project.'&pname'.'&pname'.2) 1 row created.'&pname'.&dno) new 1: insert into project values(201.&dno) new 1: insert into project values(203.1) 1 row created. PNO PNAME DNO ---------.'airline'. SQL> / Enter value for pno: 203 Enter value for pname: accounting Enter value for dno: 3 old 1: insert into project values(&pno.&dno) new 1: insert into project values(202.'accounting'.&dno).'&pname'.

'&intime'.'&dateworked'.'5 pm') 1 row created. SQL> / Enter value for eno: 102 Enter value for pno: 202 Enter value for dateworked: 2 NOV 2009 Enter value for intime: 10 am Enter value for outtime: 5 pm old 1: insert into workfor values(&eno.'&dateworked'.'&outtime') new 1: insert into workfor values(101.'&dateworked'.'2 NOV 2009'.201 banking 202 airline 203 accounting 2 1 3 SQL> insert into workfor values(&eno.&pno.&pno.202.'&dateworked'.'&outtime') new 1: insert into workfor values(101.'&intime'. Enter value for eno: 101 Enter value for pno: 201 Enter value for dateworked: 2 NOV 2009 Enter value for intime: 9 am Enter value for outtime: 5 pm old 1: insert into workfor values(&eno.'11 pm') 1 row created.&pno. SQL> / Enter value for eno: 101 Enter value for pno: 202 Enter value for dateworked: 2 NOV 2009 Enter value for intime: 6 pm Enter value for outtime: 11 pm old 1: insert into workfor values(&eno.'5 pm') 1 row created.'2 NOV 2009'.'2 NOV 2009'.&pno.202.'9 am'.'&intime'.201. SQL> / Enter value for eno: 103 Enter value for pno: 203 Enter value for dateworked: 4 NOV 2009 Enter value for intime: 9 am Enter value for outtime: 5 pm 61 .'&intime'.'&outtime') new 1: insert into workfor values(102.'6 pm'.'&outtime').'10 am'.

&pno.'&intime'.'&dateworked'.'&dateworked'.'&outtime') new 1: insert into workfor values(105.'&outtime') new 1: insert into workfor values(103.203.old 1: insert into workfor values(&eno.'4 pm') 1 row created.-------------------OUTTIME -------------------101 201 2 NOV 2009 9 am 5 pm 102 5 pm 101 11 pm 202 2 NOV 2009 202 2 NOV 2009 10 am 6 pm 62 . SQL> select * from workfor.'6 pm') 1 row created.-------------------. SQL> / Enter value for eno: 104 Enter value for pno: 201 Enter value for dateworked: 5 NOV 2009 Enter value for intime: 10 am Enter value for outtime: 6 pm old 1: insert into workfor values(&eno.'8 am'.'&dateworked'.&pno.'5 pm') 1 row created.'&outtime') new 1: insert into workfor values(104.'4 NOV 2009'.'5 NOV 2009'.'&intime'.202. SQL> / Enter value for eno: 105 Enter value for pno: 202 Enter value for dateworked: 6 NOV 2009 Enter value for intime: 8 am Enter value for outtime: 4 pm old 1: insert into workfor values(&eno.&pno.---------. ENO PNO DATEWORKED INTIME ---------.'10 am'.'9 am'.201.'6 NOV 2009'.'&intime'.

ENO PNO DATEWORKED INTIME ---------. SQL> select dno. 63 .-------------------OUTTIME -------------------103 203 4 NOV 2009 9 am 5 pm 104 6 pm 105 4 pm 201 5 NOV 2009 202 6 NOV 2009 10 am 8 am 6 rows selected.no_of_employees in each department. SQL> select * from employee where basicpay < (select avg(basicpay) from employee).---------.-------------------.-------------------. 1 List the details of employees who earn a basic pay that is less than the average basic pay of every employees.-------------------.count(eno) as no_of_employees from employee group by dno. ENO ENAME DOB GENDER ---------.-------------------DOJ DESIGNATION BASICPAY DNO -------------------. List the dno.-------------------.---------103 rahul 22 FEB 1989 male 4 MAR 2005 teammember 15000 2 104 sethu 5 SEP 2005 105 ajith 2 AUG 2005 17 MAR 1982 teammember 25 SEP 1985 team member male 14000 male 16000 2 3 2.---------.

ename.-------------------. 64 . List the eno. List the details of employees who earned a basic pay in the range of 10000 to 20000.-------------------DOJ DESIGNATION BASICPAY DNO -------------------.---------103 rahul 22 FEB 1989 male 4 MAR 2005 teammember 15000 2 104 sethu 5 SEP 2005 105 ajith 2 AUG 2005 17 MAR 1982 teammember 25 SEP 1985 team member male 14000 male 16000 2 3 5.-------------------.---------.---------101 ram 18 NOV 1990 male 2 NOV 2005 manager 30000 1 104 sethu 5 SEP 2005 17 MAR 1982 teammember male 14000 2 4.DNO NO_OF_EMPLOYEES ---------.dno.-------------------DOJ DESIGNATION BASICPAY DNO -------------------.dateworked. If the employee worked in more than one project in a day.-------------------. SQL> select * from employee where eno in (select eno from workfor where pno in (select pno from 2 project where dno=(select dno from department where dname='cse'))). ENO ENAME DOB GENDER ---------.---------.-------------------.List the details of employees who have worked in the projects controlled by cse department.-------------------.--------------1 1 2 3 3 1 3. SQL> select * from employee where basicpay between 10000 and 20000.-------------------. ENO ENAME DOB GENDER ---------.

year number 2 .price number.country varchar2(20)). SQL> insert into book values('&title'.date'.ename.author varchar2(20).'&publisher'.price.&year.dateworked having count(pno)>1)) and dateworked in (select dateworked from (select eno.dateworked from workfor group by eno.&year.SQL> select employee.dno.eno.'pearson'. SQL> / Enter value for title: microprocessor Enter value for author: ramesh Enter value for publisher: tatamagraw Enter value for year: 2006 Enter value for price: 480 Enter value for country: uk 65 .date Enter value for publisher: pearson Enter value for year: 2001 Enter value for price: 200 Enter value for country: usa old 1: insert into book values('&title'.eno in (select eno from (select eno.'&country').author. The schemas are 1.-------------------.200.workfor where employee.'&publisher'.dateworked having count(pno)>1)).'usa') 1 row created.book(title.year.2001.'cj. Table created.&price.'&country') new 1: insert into book values('dbms'.-------------------101 ram 1 2nov2009 101 ram 1 2nov2009 101 ram 1 2nov2009 Consider the book database.---------.'&author'.publisher.&price. Enter value for title: dbms Enter value for author: cj.dateworked from workfor group by eno.'&author'.country) SQL> create table book(title varchar2(20).dateworked from employee.publisher varchar2(20). ENO ENAME DNO DATEWORKED ---------.

'tatamagraw'.2005.&price.&year.480.'&publisher'.'&publisher'.'&country') new 1: insert into book values('ds'.&year.390.'') 1 row created.'trivedi'.'&author'.'&author'. SQL> / Enter value for title: ds Enter value for author: revathi Enter value for publisher: tatamagraw Enter value for year: 2005 Enter value for price: 390 Enter value for country: old 1: insert into book values('&title'.'&country') new 1: insert into book values('oops'.'silberschatz'.'uk') 1 row created.2002.600.'ramesh'.&price.'revathi'.&year.'&author'.&price.'&publisher'.2003.'india') 1 row created.'pearson'.'&country') new 1: insert into book values('os'.'tatamagraw'.'pearson'.'&author'.'usa') 1 row created.old 1: insert into book values('&title'.&price. SQL> / Enter value for title: oops Enter value for author: trivedi Enter value for publisher: pearson Enter value for year: 2003 Enter value for price: 500 Enter value for country: india old 1: insert into book values('&title'. SQL> select * from book. TITLE AUTHOR PUBLISHER YEAR 66 .500.2006.'&country') new 1: insert into book values('microprocessor'.&year.'&publisher'. SQL> / Enter value for title: os Enter value for author: silberschatz Enter value for publisher: pearson Enter value for year: 2002 Enter value for price: 600 Enter value for country: usa old 1: insert into book values('&title'.

2005). publisher of all books except those published in the year 2002.2003). SQL> select title.-------------------.-------------------.date pearson 2001 200 usa microprocessor 480 uk os 600 usa TITLE AUTHOR PUBLISHER YEAR -------------------. Display the title.publisher from book where year in (2002.2004.2005.2004. author.date pearson microprocessor ramesh tatamagraw oops trivedi pearson 2.Display title. publisher of all books published in the year 2002 and 2003.-------------------. SQL> select title.-------------------os silberschatz pearson oops trivedi pearson revathi tatamagraw 2005 ramesh tatamagraw pearson 2002 2006 silberschatz 67 .-------------------oops trivedi pearson 2003 500 india ds 390 1. author.---------PRICE COUNTRY ---------. TITLE AUTHOR PUBLISHER -------------------.---------PRICE COUNTRY ---------.-------------------.-------------------.author.author.-------------------. TITLE AUTHOR PUBLISHER -------------------.publisher from book where year not in (2002.-------------------dbms cj.-------------------dbms cj.-------------------.

Find the title of books having price in the range 300 and 400.1000. TITLE -------------------dbms microprocessor os 4. Find the names of the publisher who got the total price greater than Rs.loan(loanno. TITLE -------------------microprocessor os oops 5.assets) 2.bname) 4. PUBLISHER -------------------pearson Consider the bank database.bcity.bname. SQL> select title from book where price>(select max(price) from book where year=2005).balance.amount) 68 . SQL> select title from book where country not in 'india'. The schemas are 1. TITLE -------------------ds 6.List the title of all books written by authors who do not live in INDIA.Get the title of all books that have price greater than atleat one book published in the year 2004. SQL> select publisher from book group by publisher having sum(price)>1000.street.branch(bname.ccity) 3. SQL> select title from book where price between 300 and 400.account(accno.3.customer(cname.

SQL> create table account(accno number.bname varchar2(20).'&bcity'. Table created.&assets) new 1: insert into branch values('perryridge'. Table created.loanno) SQL> create table branch(bname varchar2(20).'&bcity'.&assets). Table created.bname varchar2(20)).accno) 6.bcity varchar2(20).&assets) new 1: insert into branch values('adyar'.street varchar2(20). SQL> create table loan(loanno number.assets number). Table created. Table created. Enter value for bname: perryridge Enter value for bcity: new york Enter value for assets: 5000000 old 1: insert into branch values('&bname'.amount number). SQL> create table customer(cname varchar2(20).'&bcity'. SQL> create table depositor(cname varchar2(20).ccity varchar2(20)).balance number.borrower(cname.accno number). Table created. SQL> create table borrower(cname varchar2(20).'chennai'.5.'new york'.8000000) 69 . SQL> / Enter value for bname: adyar Enter value for bcity: chennai Enter value for assets: 8000000 old 1: insert into branch values('&bname'.depositor(cname. SQL> insert into branch values('&bname'.5000000) 1 row created.loanno number).

'&bcity'.'bangalore'.'chennai') 1 row created.---------perryridge new york 5000000 adyar chennai 8000000 avadi chennai 6000000 ashoknagar bangalore 7000000 SQL> insert into customer values('&cname'. Enter value for cname: yabesh Enter value for street: nehru Enter value for ccity: chennai old 1: insert into customer values('&cname'.&assets) new 1: insert into branch values('ashoknagar'.7000000) 1 row created.'&street'. BNAME BCITY ASSETS -------------------. SQL> / Enter value for bname: avadi Enter value for bcity: chennai Enter value for assets: 6000000 old 1: insert into branch values('&bname'.'nehru'.&assets) new 1: insert into branch values('avadi'.-------------------.'&street'.1 row created.'&ccity'). SQL> select * from branch.6000000) 1 row created.'chennai'.'&bcity'.'&ccity') new 1: insert into customer values('yabesh'. SQL> / 70 . SQL> / Enter value for bname: ashoknagar Enter value for bcity: bangalore Enter value for assets: 7000000 old 1: insert into branch values('&bname'.

Enter value for cname: siva Enter value for street: gandi Enter value for ccity: bangalore old 1: insert into customer values('&cname'.'netaji'.40000.'gandi'. SQL> / 71 . SQL> select * from customer.&balance.'&street'.'&bname').'&ccity') new 1: insert into customer values('siva'.'rajiv'. Enter value for accno: 101 Enter value for balance: 40000 Enter value for bname: perryridge old 1: insert into account values(&accno.'madurai') 1 row created.'&street'.'&ccity') new 1: insert into customer values('mahesh'.-------------------yabesh nehru chennai siva gandi bangalore loga netaji madurai mahesh rajiv chennai SQL> insert into account values(&accno.'&bname') new 1: insert into account values(101.'&street'.&balance.'&ccity') new 1: insert into customer values('loga'.'perryridge') 1 row created.'bangalore') 1 row created.-------------------.'chennai') 1 row created. SQL> / Enter value for cname: loga Enter value for street: netaji Enter value for ccity: madurai old 1: insert into customer values('&cname'. SQL> / Enter value for cname: mahesh Enter value for street: rajiv Enter value for ccity: chennai old 1: insert into customer values('&cname'. CNAME STREET CCITY -------------------.

'ashoknagar') 1 row created.Enter value for accno: 102 Enter value for balance: 50000 Enter value for bname: adyar old 1: insert into account values(&accno.&amount) new 1: insert into loan values(202. SQL> / Enter value for accno: 103 Enter value for balance: 60000 Enter value for bname: ashoknagar old 1: insert into account values(&accno. SQL> / Enter value for loanno: 203 Enter value for bname: perryridge 72 .800) 1 row created.-------------------101 40000 perryridge 102 50000 adyar 103 60000 ashoknagar SQL> insert into loan values(&loanno.'&bname') new 1: insert into account values(102.60000.'&bname'.&balance.&balance. Enter value for loanno: 201 Enter value for bname: adyar Enter value for amount: 800 old 1: insert into loan values(&loanno.'avadi'. SQL> select * from account.&amount) new 1: insert into loan values(201.'adyar'. SQL> / Enter value for loanno: 202 Enter value for bname: avadi Enter value for amount: 15000 old 1: insert into loan values(&loanno.---------.'&bname') new 1: insert into account values(103.15000) 1 row created.50000. ACCNO BALANCE BNAME ---------.'adyar') 1 row created.'&bname'.&amount).'&bname'.

&accno).---------201 adyar 800 202 avadi 15000 203 perryridge 1000 SQL> insert into depositor values('&cname'.'&bname'.101) 1 row created. SQL> select * from loan.&accno) new 1: insert into depositor values('siva'.103) 1 row created.1000) 1 row created.102) 1 row created. SQL> / Enter value for cname: siva Enter value for accno: 102 old 1: insert into depositor values('&cname'. CNAME ACCNO -------------------. LOANNO BNAME AMOUNT ---------.---------yabesh 101 siva 102 mahesh 103 73 .&accno) new 1: insert into depositor values('yabesh'. SQL> select * from depositor. Enter value for cname: yabesh Enter value for accno: 101 old 1: insert into depositor values('&cname'.&accno) new 1: insert into depositor values('mahesh'.'perryridge'.Enter value for amount: 1000 old 1: insert into loan values(&loanno.-------------------. SQL> / Enter value for cname: mahesh Enter value for accno: 103 old 1: insert into depositor values('&cname'.&amount) new 1: insert into loan values(203.

&loanno) new 1: insert into borrower values('yabesh'. SQL> / Enter value for cname: loga Enter value for loanno: 203 old 1: insert into borrower values('&cname'.&loanno).&loanno) new 1: insert into borrower values('loga'.loanno where amount>1200.202) 1 row created. SQL> / Enter value for cname: siva Enter value for loanno: 202 old 1: insert into borrower values('&cname'.loanno=borrower.Find the customer names of all loans of over Rs.201) 1 row created. 74 .&loanno) new 1: insert into borrower values('siva'. SQL> select * from borrower. CNAME LOANNO -------------------.203) 1 row created. CNAME -------------------siva SQL> select cname from borrower join loan on loan. Enter value for cname: yabesh Enter value for loanno: 201 old 1: insert into borrower values('&cname'. SQL> select cname from borrower where loanno in (select loanno from loan where 2 amount>1200).SQL> insert into borrower values('&cname'.---------yabesh 201 siva 202 loga 203 1.1200.

SQL> select cname from depositor union select cname from borrower. CNAME -------------------loga mahesh siva yabesh 4.accno=depositor. SQL> select cname from depositor intersect select cname from borrower.1200 in their account.CNAME -------------------siva 2.Find the names of all customers who have more than Rs. CNAME -------------------yabesh siva mahesh 3. SQL> select cname from depositor where accno in (select accno from account where balance>1200). CNAME -------------------yabesh siva mahesh SQL> select cname from depositor join account on account. CNAME -------------------siva yabesh 75 .Find the names of all customers who have both loan and account.accno where 2 balance>1200.Find the names of all customers who have either a loan or an account or both.

Find the names of all customers who have only loan. SQL> select cname from borrower join loan on borrower. CNAME -------------------loga 76 .Find the names of all customers who have only account. SQL> select cname from borrower minus select cname from depositor. SQL> select cname from depositor minus select cname from borrower.loanno where 2 bname='perryridge'. CNAME -------------------loga 6.loanno=loan. CNAME -------------------mahesh 7.5.Find the names of all customers who have loan at perryridge bank.

1) 1 row created.dno number(2)).'&ename'.&dno) new 1: insert into emp values(1. 77 .&bpay. SQL> insert into emp values(&eno. Views are created for the following reasons.'Priya'.12000.&bpay.INSERTION. • Data simplicity • To provide data security • Structural simplicity (because view contains only limited number of rows and colmns) TYPES OF VIEWS • • Updatable views – Allow data manipulation Read only views – Do not allow data manipulation CREATION OF VIEWS . UPDATION SQL> create table emp(eno number(1). DEFINITION A view is an object that gives the user the logical view of data from the underlying table. Enter value for eno: 1 Enter value for ename: Priya Enter value for bpay: 12000 Enter value for dno: 1 old 1: insert into emp values(&eno. They are generally used to avoid duplication of data.&dno).'&ename'. DELETION.ename varchar2(20).RESULT: Thus the sql application2 is executed and the required output is obtained VIEWS EX NO: 5 DATE: AIM To create views for the table and perform operations on it. Any relation that is not part of the logical model but is made visible to the user as a virtual relation is called a view. Table created.bpay number(6).

--------.20000.'&ename'.'Helen'.1) 1 row created.'&ename'.--------78 .'&ename'.36000. SQL> / Enter value for eno: 3 Enter value for ename: Gayathri Enter value for bpay: 35000 Enter value for dno: 2 old 1: insert into emp values(&eno.2) 1 row created.'Swetha'.&dno) new 1: insert into emp values(4.'Gayathri'.&bpay.2) 1 row created. SQL> select * from emp.16000.&dno) new 1: insert into emp values(5.&dno) new 1: insert into emp values(3.'&ename'.-------------------. SQL> / Enter value for eno: 4 Enter value for ename: Swetha Enter value for bpay: 16000 Enter value for dno: 3 old 1: insert into emp values(&eno.35000.3) 1 row created.SQL> / Enter value for eno: 2 Enter value for ename: Helen Enter value for bpay: 20000 Enter value for dno: 1 old 1: insert into emp values(&eno.&bpay.'Rohan'. ENO ENAME BPAY DNO --------.&bpay. SQL> / Enter value for eno: 5 Enter value for ename: Rohan Enter value for bpay: 36000 Enter value for dno: 2 old 1: insert into emp values(&eno.&dno) new 1: insert into emp values(2.&bpay.

SQL> / Enter value for dno: 3 Enter value for dname: ECE old 1: insert into dept values(&dno. SQL> select * from dept.'ECE') 1 row created.dname varchar2(20)).1 Priya 2 Helen 3 Gayathri 4 Swetha 5 Rohan 12000 20000 35000 16000 36000 1 1 2 3 2 SQL> create table dept(dno number(1). SQL> / Enter value for dno: 4 Enter value for dname: EEE old 1: insert into dept values(&dno.'&dname') new 1: insert into dept values(2.'&dname').'CSE') 1 row created. DNO --------DNAME -------------------79 .'&dname') new 1: insert into dept values(1. Enter value for dno: 1 Enter value for dname: IT old 1: insert into dept values(&dno.'EEE') 1 row created.'&dname') new 1: insert into dept values(3.'&dname') new 1: insert into dept values(4. SQL> insert into dept values(&dno.'IT') 1 row created. SQL> / Enter value for dno: 2 Enter value for dname: CSE old 1: insert into dept values(&dno. Table created.

ENO ENAME BPAY DNO --------.--------1 Priya 12000 1 2 Helen 20000 1 SQL> select * from emp. 1 row created. SQL> update view1 set bpay=40000 where eno=1.--------1 Priya 12000 1 2 Helen 20000 1 3 Gayathri 35000 2 4 Swetha 16000 3 5 Rohan 36000 2 6 Joe 50000 4 6 rows selected.--------1 Priya 12000 1 2 Helen 20000 1 SQL> insert into view1 values(6. ENO ENAME BPAY DNO --------.1 2 3 4 IT CSE ECE EEE SQL> create view view1 as select * from emp where dno=1. SQL> select * from view1.--------.50000. 80 . View created. SQL> select * from view1. 1 row updated. SQL> select * from view1.-------------------. ENO ENAME BPAY DNO --------.--------.-------------------.4).-------------------.'Joe'.--------.

--------1 Priya 40000 1 SQL> select * from emp.--------1 Priya 40000 1 2 Helen 20000 1 SQL> delete from view1 where ename='Helen'. DEPTNO --------1 2 3 4 SQL> update view2 set deptno =11 where deptno=2.--------. ENO ENAME BPAY DNO --------. ENO ENAME BPAY DNO --------.ENO ENAME BPAY DNO --------. SQL> select * from view2.--------. SQL> select * from view1. 1 row deleted.--------1 Priya 40000 1 3 Gayathri 35000 2 4 Swetha 16000 3 5 Rohan 36000 2 6 Joe 50000 4 CREATING VIEW WITH DISTINCT KEYWORD: SQL> create view view2(deptno) as select distinct(dno) from emp. update vnis2 set deptno =11 where deptno=2 * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view 81 .-------------------. View created.-------------------.--------.-------------------.

maximum) as select dno. create view view3 as select dno.max(bpay) from emp group by dno. View created.20000). SQL> select * from view3. DNO MAXIMUM --------.--------1 40000 2 36000 3 16000 4 50000 SQL> insert into view3 values(5.SQL> insert into view2 values(11).20000) * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view SQL> delete from view3 where dno=1. insert into view3 values(5. delete from vnis2 where deptno=1 * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view CREATING VIEW WITH AGGREGATE FUNCTIONS: SQL> create view view3 as select dno.max(bpay) from emp group by dno. delete from view3 where dno=1 82 . insert into vnis2 values(11) * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view SQL> delete from view2 where deptno=1.max(bpay) from emp group by dno * ERROR at line 1: ORA-00998: must name this expression with a column alias SQL> create view view3(dno.

--------. create view v45 as select dno. SQL> select * from v45.* ERROR at line 1: ORA-01732: data manipulation operation not legal on this view SQL> update view3 set maximum=90000 where dno=1.no_of_emp.sum(pay) from e234 group by dno.tot_pay) as select dno.--------.--------1 2 22000 2 2 15456 3 1 2345 SQL> update v45 set dnum=12 where dnum=1. update view3 set maximum=90000 where dno=1 * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view SQL> select * from e234. ENO ENAME PAY DNO --------.--------1x 12000 1 2y 10000 1 3z 12000 2 4a 3456 2 5c 2345 3 SQL> create view v45 as select dno.count(eno).count(eno). View created.-------------------.sum(pay) from e234 group by dno. DNUM NO_OF_EMP TOT_PAY --------.sum(pay) from e234 group by dno * ERROR at line 1: ORA-00998: must name this expression with a column alias SQL> create view v45(dnum.count(eno). update v45 set dnum=12 where dnum=1 * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view 83 .

--------. MAX(TOT_PAY) -----------22000 SQL> update v45 set dnum=11 where tot_pay=22000.dname from emp. SQL> select * from view4. View created. DNUM NO_OF_EMP TOT_PAY --------. update v45 set dnum=11 where tot_pay=22000 * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view SQL> delete from v45 where dnum=1. ENAME DNAME -------------------. delete from v45 where dnum=1 * ERROR at line 1: ORA-01732: data manipulation operation not legal on this view CREATING VIEW ON TWO TABLES: SQL> create view view4 as select ename.SQL> select * from v45.-------------------Priya IT Daisy IT Gayathri CSE Rohan CSE Swetha ECE 84 .dno=dept.--------1 2 3 2 2 1 22000 15456 2345 SQL> select max(tot_pay) from v45.dno.dept where emp.

'IT') * ERROR at line 1: ORA-01779: cannot modify a column which maps to a non key-preserved table SQL> delete from view4 where ename='Priya'. insert into view4 values('Frank'.'IT'). SQL> insert into view4 values('Frank'. update view4 set dname='ECE' where ename='Joe' * ERROR at line 1: ORA-01779: cannot modify a column which maps to a non key-preserved table 85 . delete from view4 where ename='Priya' * ERROR at line 1: ORA-01752: cannot delete from view without exactly one key-preserved table SQL> update view4 set dname='ECE' where ename='Joe'.Joe EEE 6 rows selected.

This language is used to provide certain priveleges to a particular user. • Select • Insert • Delete • Update • References • Execute • All GRANT COMMAND: It is used to create users and grant access to the database. Priveleges are rights to be allocated.RESULT: Thus views were studied and implemented. DESCRIPTION The DCL language is used for controlling the access to the table and hence securing the database.]. SYNTAX GRANT COMMAND Grant < database_priv [database_priv…. • Grant • Revoke The various priveleges that can be granted or revoked are. the DBA can revoke the granted database priveleges from the user. 86 .] > to <user_name> identified by <password> [. except that a user can change their password. A user can grant access to their database objects to other users. It requires database administrator (DBA) privilege.<password…. REVOKE COMMAND: Using this command . The privilege commands are namely. DATACONTROL LANGUAGE COMMANDS EX NO: 6 DATE: AIM To study the various data language commands (DCL) and implement them on the database...

Revoke <object_priv> on <object> from < user | public >. [ With Grant Option ] – Allows the recipient user to give further grants on the objects. insert on departments from abcde. SQL> Grant all on employees to abcde. emp_salary ).Specifies the system level priveleges to be granted to the users or roles. SQL> Revoke all on employees from abcde. dept_location ).Grant <object_priv> | All on <object> to <user | public> [ With Grant Option ]. 87 . EXAMPLES Consider the following tables namely “DEPARTMENTS” and “EMPLOYEES” Their schemas are as follows . SQL> Revoke select .Indicates all the priveleges. <all> -. Departments ( dept _no . Grant succeeded. The priveleges can be granted to different users by specifying their names or to all users by using the “Public” option. <object_priv> -.Specifies the actions such as alter / delete / insert / references / execute / select / update for tables. insert on departments to abcde with grant option. update . REVOKE COMMAND Revoke <database_priv> from <user [. Grant succeeded. update . Revoke succeeded. dept_ name . <database_priv> -. SQL> Grant select . user ] >. Revoke succeeded. Employees ( emp_id . This includes create / alter / delete any object of the system. emp_name .

TO INPUT A VALUE FROM THE USER AND DISPLAY IT SQL> set serveroutput on. 7 / Enter value for a: 5 old 4: a:=&a.put_line(a).RESULT Thus all the commands were executed and their output were verified. SQL> declare 2 a varchar2(20). SQL> declare 2 a varchar2(20). PROCEDURAL LANGUAGE/ STRUCTURAL QUERY LANGUAGE EX NO: 7 DATE: AIM To implement various programs using PL/SQL language. 5 dbms_output. 6 end. 7 / Hello PL/SQL procedure successfully completed. PROGRAMS TO DISPLAY HELLO MESSAGE SQL> set serveroutput on. 6 end. 5 dbms_output. 3 begin 4 a:='Hello'. 3 begin 4 a:=&a. new 4: a:=5. 5 88 .put_line(a).

put_line (' The greatest of the three is ' || c). 4 begin 5 a:=&a. 3 b number(7). GREATEST OF TWO NUMBERS SQL> set serveroutput on.put_line (' The grerater of the two is'|| b). 89 .PL/SQL procedure successfully completed. 13 / Enter value for a: 5 old 5: a:=&a. SQL> declare 2 a number(7). 9 if(a>b and a>c) then 10 dbms_output. 5 begin 6 a:=&a.put_line (' The grerater of the two is'|| a). new 5: a:=5. 9 else 10 dbms_output. 11 else if (b>c) then 12 dbms_output.put_line (' The greatest of the three is ' || b). 7 if(a>b) then 8 dbms_output. 13 else 14 dbms_output. 8 c:=&c.put_line (' The greatest of the three is ' || a). 12 end. 7 b:=&b. Enter value for b: 9 old 6: b:=&b. 6 b:=&b. new 6: b:=9. 11 end if. GREATEST OF THREE NUMBERS SQL> set serveroutput on. The grerater of the two is9 PL/SQL procedure successfully completed. SQL> declare 2 a number(7). 3 b number(7). 4 c number(7).

3 begin 4 loop 5 dbms_output. SQL> declare 2 a number:=1. new 8: c:=1. 8 end loop. 3 begin 4 while(a<5) 5 loop 6 dbms_output. 18 / Enter value for a: 5 old 6: a:=&a. 17 end. 16 end if. 6 a:=a+1. new 7: b:=7. new 6: a:=5. 90 . Enter value for c: 1 old 8: c:=&c.put_line (a). PRINT NUMBERS FROM 1 TO 4 USING WHILE LOOP SQL> set serveroutput on. The greatest of the three is 7 PL/SQL procedure successfully completed. 10 / 1 2 3 4 5 PL/SQL procedure successfully completed.15 end if. Enter value for b: 7 old 7: b:=&b. 9 end. PRINT NUMBERS FROM 1 TO 5 USING SIMPLE LOOP SQL> set serveroutput on. 7 exit when a>5. SQL> declare 2 a number:=1.put_line (a).

10 / 1 2 3 4 PL/SQL procedure successfully completed. 9 / 1 2 3 4 5 PL/SQL procedure successfully completed. 3 begin 4 for a in 1. 3 begin 4 for a in reverse 1. 7 end loop. 9 / 5 4 3 2 91 . PRINT NUMBERS FROM 1 TO 5 USING FOR LOOP SQL> set serveroutput on. 8 end loop.5 5 loop 6 dbms_output. 9 end.5 5 loop 6 dbms_output. SQL> declare 2 a number:=1.7 a:=a+1.put_line (a). 8 end... SQL> declare 2 a number:=1. PRINT NUMBERS FROM 1 TO 5 IN REVERSE ORDER USING FOR LOOP SQL> set serveroutput on.put_line (a). 8 end. 7 end loop.

2):=3.'kala'. 9 end. 5 begin 6 r:=&r. ACCNO NAME BAL --------. SQL> select * from saccount. 8 dbms_output. 4 r number(20). TO CREATE SACCOUNT TABLE SQL> create table saccount ( accno number(5). 3 a number(20).1 PL/SQL procedure successfully completed.'mala'. 1 row created. new 6: r:=2.--------1 mala 20000 2 kala 30000 SQL> set serveroutput on.2). SQL> declare 92 .20000). 7 a:= pi* power(r. SQL> insert into saccount values (2. 10 / Enter value for r: 2 old 6: r:=&r.14.-------------------. bal number(10)). The area of circle is 13 PL/SQL procedure successfully completed.put_line (' The area of circle is ' || a). Table created.30000). SQL> declare 2 pi constant number(4. 1 row created. TO CALCULATE AREA OF CIRCLE SQL> set serveroutput on. SQL> insert into saccount values ( 1. name varchar2(20).

Table created. minamt number(7):=500. 'madurai'. 12 end if. 9 a_bal:= a_bal-debit. destination varchar2(20). begin 7 a_no:=&a_no. 10 if (a_bal > minamt) then 11 update saccount set bal=bal-debit where accno=a_no. debit number(7):=2000. new 7: a_no:=1.--------1 mala 18000 2 kala 30000 TO CREATE TABLE SROUTES SQL> create table sroutes ( rno number(5).2 3 4 5 6 a_bal number(7).-------------------. PL/SQL procedure successfully completed. 'dindugal'. fare numbe r(10). 13 end. a_no varchar2(20). SQL> select * from saccount. 14 15 / Enter value for a_no: 1 old 7: a_no:=&a_no. 1 row created. SQL> insert into sroutes values ( 2. origin varchar2(20). 93 . 'chennai'. 8 select bal into a_bal from saccount where accno= a_no. 'chennai'. ACCNO NAME BAL --------. 400.230). 250. distance number(10)). SQL> insert into sroutes values ( 3.300).

distance % type. 16 end if. SQL> insert into sroutes values ( 6. dist from sroutes where rno=route.--------. SQL> declare 2 route sroutes. 1 row created. 10 else if dist between 250 and 370 then 11 update sroutes set fare=400 where rno=route. 'palani'.-------------------.rno % type. 14 end if.-------------------. 5 begin 6 route:=&route.-------------------. 7 select fare. RNO ORIGIN DESTINATION FARE DISTANCE --------. SQL> select * from sroutes.370). new 6: route:=3.--------.--------2 chennai dindugal 400 230 94 . distance into fares .-------------------. 'thanjavur'. 350. 15 end if.1 row created. PL/SQL procedure successfully completed. 12 else if (dist > 400) then 13 dbms_output.--------2 chennai dindugal 400 230 3 chennai madurai 250 300 6 thanjavur palani 350 370 SQL> set serveroutput on. SQL> select * from sroutes. 17 end. RNO ORIGIN DESTINATION FARE DISTANCE --------.fare % type. 18 / Enter value for route: 3 old 6: route:=&route.put_line('Sorry'). 8 if (dist < 250) then 9 update sroutes set fare=300 where rno=route. 4 dist sroutes. 3 fares sroutes.

12 end loop. 11 radius:=radius+1. area number(5. 95 . 10 insert into scalculate values (radius. Table created.04 7 153. SQL> declare 2 pi constant number(4.2). RADIUS AREA --------. 3 area number(5.--------3 28.14. 5 begin 6 radius:=3.-----------------------------------RADIUS NUMBER(3) AREA NUMBER(5. 7 while (radius <=7) 8 loop 9 area:= pi* power(radius. SQL> desc scalculate.5 6 113.2).86 TO CALCULATE FACTORIAL OF A GIVEN NUMBER SQL> set serveroutput on. 4 radius number(3). SQL> declare 2 f number(4):=1.area).2)). Name Null? Type ----------------------------------------------------.26 4 50.24 5 78.-------. 14 / PL/SQL procedure successfully completed.3 chennai 6 thanjavur madurai palani 400 350 300 370 TO CREATE SCA LCULATE TABLE SQL> create table scalculate ( radius number(3). 13 end.2) SQL> set serveroutput on. SQL> select * from scalculate.2):=3.

put_line('The value is ' || f). 11 dbms_output. begin i:=&i. 13 / Enter value for i: 5 old 5: i:=&i. while(i>=1) loop 8 f:=f*i.3 4 5 6 7 i number(4). 96 . 9 i:=i-1. The value is 120 PL/SQL procedure successfully completed. 12 end. 10 end loop. new 5: i:=5.

This statement makes use of the <<user defined name>> to jump into the block of code for execution. SQL> select * from sproductmasters.6000). 1 row created. GOTO AND EXCEPTIONS EX NO: 8 DATE: AIM To perform goto and exception handling mechanisms. sellprice number(10)).3200).--------p1 3200 p2 4000 p3 6000 97 . 1 row created.4000). PNO SELLPRICE ---------. SQL> insert into sproductmasters values('p1'. SQL> insert into sproductmasters values('p2'.RESULT Thus the various programs were implemented and their output was verified. 1 row created. Table created. SYNTAX GOTO <code block name> <<user defined name>> CREATING THE TABLES ‘SPRODUCTMASTERS’ AND ‘SOLDPRICES’ SQL> create table sproductmasters( pno varchar2(10). The entry point into such a block of code is marked using the tags. SQL> insert into sproductmasters values('p3'. GOTO COMMAND PURPOSE The GOTO statement changes the flow of control within a PL/SQL block.

5 if sellingprice < 4000 6 then 7 goto add_old_price. DISPLAYING THE CONTENTS OF ‘SOLDPRICES’ TABLE SQL> select * from soldprices. The price change is to be recorded on the old price table along with the product number and the date on which the price was last changed using PL/SQL.put_line(' Current price is '|| sellingprice). 10 end if. 8 else 9 dbms_output.sellingprice). 16 / PROGRAM OUTPUT The new price of p1 is 4000 PL/SQL procedure successfully completed. 13 insert into soldprices values('p1'.sysdate. 3 begin 4 select sellprice into sellingprice from sproductmasters where pno='p1'. PROGRAM 1 declare 2 sellingprice number(10. Table created. OPERATION TO BE PERFORMED If the price of a product is less than 4000 then change to 4000.put_line(' The new price of p1 is 4000 ').-------------------. 15 end. 14 dbms_output.2).---------p1 27-AUG-08 3200 EXCEPTIONS 98 .soldprices number(10)). PNO DATECHANGE SOLDPRICES ---------. datechange varchar2(20).SQL> create table soldprices( pno varchar2(10). 11 <<add_old_price>> 12 update sproductmasters set sellprice = 4000 where pno='p1'.

Table created.• • Exceptions are error handling mechanisms. They are of 2 types. Pre – defined exceptions User – defined exceptions TO CREATE THE TABLE ‘SSITEMS’ ON WHICH THE EXCEPTION HANDLING MECHANISMS ARE GOING TO BE PERFORMED SQL> create table ssitems( id number(10).2000).2. SQL> insert into ssitems values(101. ID QUANTITY ACTUALPRICE --------. SQL> insert into ssitems values(102.4000). actualprice number(10)). exception when < exception name > then 99 .5. 1 row created. 1 row created.5000). SQL> insert into ssitems values(103. quantity number(10).------------------100 5 5000 101 6 9000 102 4 4000 103 2 2000 PRE – DEFINED EXCEPTIONS SYNTAX begin sequence of statements. SQL> select * from ssitems. 1 row created. SQL> insert into ssitems values(100.9000).6. 1 row created.4.

sequence of statements; end; EXAMPLE USING PL/SQL SQL> set serveroutput on; SQL> declare 2 price ssitems.actualprice % type; 3 begin 4 select actualprice into price from ssitems where quantity=10; 5 exception 6 when no_data_found then 7 dbms_output.put_line ('ssitems missing'); 8 end; 9 / ssitems missing PL/SQL procedure successfully completed. DISPLAYING THE UPDATED TABLE SQL> select * from ssitems; ID QUANTITY ACTUALPRICE --------- ------------------100 5 5000 101 6 9000 102 4 4000 103 2 2000 USER DEFINED EXCEPTONS SYNTAX declare < exception name > exception; begin sequence of statements; raise < exception name >; exception when < exception name > then sequence of statements; end; EXAMPLE USING PL/SQL

100

SQL> set serveroutput on; SQL> declare 2 zero_price exception; 3 price number(8,2); 4 begin 5 select actualprice into price from ssitems where id=103; 6 if price=0 or price is null then 7 raise zero_price; 8 end if; 9 exception 10 when zero_price then 11 dbms_output.put_line('Failed zero price'); 12 end; 13 / PL/SQL procedure successfully completed. DISPLAYING THE UPDATED TABLE SQL> select * from ssitems; ID QUANTITY ACTUALPRICE --------- ------------------100 5 5000 101 6 9000 102 4 4000 103 2 2000

101

RESULT Thus the goto statement and exceptions were executed and their respective output’s were verified.

TRANSACTION CONTROL LANGUAGE
EX NO: 9 DATE: AIM To study the various TCL commands namely commit, rollback and savepoint. DESCRIPTION COMMIT: This command saves all the transactions to the database since the last commit or rollback command. ROLLBACK: This command is used to undo the transactions that have not been already saved to the database.It can be used to undo transactions since the last commit or rollback command. SAVEPOINT: This command is a point in transaction that you can roll the transaction back to without rolling back the entire transmission. CREATE THE TABLE ‘ITYR’ SQL> create table ityr(ename varchar(15),eid number(5),salary number(5)); Table created. PROGRAM SQL> set serveroutput on; SQL> declare 2 t number(6); 3 n number(6); 4 s number(6); 5 begin 6 insert into ityr values('a',100,19000); 7 insert into ityr values('b',102,1000); 8 s:=&s; 9 n:=&n; 10 savepoint a; 11 update ityr set salary=salary+2000 where eid=s; 12 update ityr set salary=salary+1500 where eid=n; 13 select sum(salary) into t from ityr; 102

---------. 20 end . new 9: n:=102. no rows selected SQL> insert into tyu values('&name'). Enter value for n: 102 old 9: n:=&n. 19 end if. ENAME EID SALARY --------------. new 8: s:=100. 1 row created. DISPLAYING THE UPDATED TABLE SQL> select * from ityr. Table created. Rollback complete.---------a 100 19000 b 102 1000 SQL> create table tyu(name varchar2(20)). Enter value for name: xyz 103 .14 15 16 17 18 if(t>20000) then rollback to a. else dbms_output. NAME --------dfg SQL> rollback.put_line('no updation'). Select*from tyu. SQL> insert into tyu values('dfg'). 21 / Enter value for s: 100 old 8: s:=&s. SQL> select * from tyu. PL/SQL procedure successfully completed.

SQL> delete from tyu where name='xyz'. Savepoint created. SQL> select * from tyu. SQL> select * from tyu.old 1: insert into tyu values('&name') new 1: insert into tyu values('xyz') 1 row created. Select*from tyu. NAME -------------------xyz wert hjk 104 . NAME -------------------wert hjk SQL> rollback to u. 1 row deleted. NAME -------------------xyz wert hjk SQL> savepoint u. Rollback complete.

105 . 1 row created.'nila'.12). SQL> insert into ssempp values(1. SQL> insert into ssempp values(5.18000. 1 row created. Cursor for loop Explicit cursor Implicit cursor TO CREATE THE TABLE ‘SSEMPP’ SQL> create table ssempp( eid number(10). 1 row created. CURSORS EX NO: 10 DATE: AIM • • • To write PL/SQL blocks that implement the concept of for the 3 types of cursors namely.20000.RESULT Thus the various commands were executed and the output was verified. SQL> insert into ssempp values(2. sal number (10). SQL> select * from ssempp.'professor'.dnonumber(5)).11).' seniorlecturer'.'kala'.'vijay'.12). job varchar2(20).30000.'lecturer'.'lecturer'.'ajay'. 1 row created.'lecturer'. Table created.'nala'. ename varchar2(20). 1 row created. SQL> insert into ssempp values(6.60000.11). SQL> insert into ssempp values(3.34000.11).

sal.EID ENAME JOB --------.eid ‘and’|| emy. SQL> declare 2 cursor cem is select eid. TO WRITE A PL/SQL BLOCK TO UPDATE THE SALARY OF ALL EMPLOYEES WHERE DEPARTMENT NO IS 11 BY 5000 USING CURSOR FOR LOOP AND TO DISPLAY THE UPDATED TABLE SQL> set serveroutput on. 5 for rem in cem 6 loop 7 update ssempp set sal=rem.-------------------. 9 --close cem. 3 begin 4 --open cem. 8 end loop.ename.ename from ssempp) 4 loop 5 dbms_output. SQL> declare 2 begin 3 for emy in (select eid.-------------------1 nala lecturer 2 kala seniorlecturer 5 6 3 ajay vijay nila lecturer lecturer professor SAL --------34000 20000 30000 18000 60000 DNO --------11 12 11 11 12 TO WRITE A PL/SQL BLOCK TO DISPLAY THE EMPOYEE ID AND EMPLOYEE NAME USING CURSOR FOR LOOP SQL> set serveroutput on.dno from ssempp where dno=11. 10 end. 11 / 106 . 8 / Employee id and employee name are 1 and nala Employee id and employee name are 2 and kala Employee id and employee name are 5 and ajay Employee id and employee name are 6 and vijay Employee id and employee name are 3 and nila PL/SQL procedure successfully completed. 7 end. 6 end loop.ename).eid.put_line('Employee id and employee name are '|| emy.sal+5000 where eid=rem.

TO CHECK IF UPDATES ARE MADE USING IMPLICIT CURSORS AND TO DISPLAY THE UPDATED TABLE SQL> declare 2 county number.-------------------.esal. SQL> / Employee code and employee salary are 1 and 39000 Employee code and employee salary are 5 and 35000 Employee code and employee salary are 6 and 23000 PL/SQL procedure successfully completed.put_line(' Employee code and employee salary are' || ecode ‘and’|| esal). SQL> select * from ssempp. 11 end loop.sal from ssempp where dno=11. 107 .eid%type.--------. 3 ecode ssempp.--------1 nala lecturer 39000 11 2 kala seniorlecturer 20000 12 5 ajay lecturer 35000 11 6 vijay lecturer 23000 11 3 nila professor 60000 12 TO WRITE A PL/SQL BLOCK TO DISPLAY THE EMPLOYEE ID AND EMPLOYEE NAME WHERE DEPARTMENT NUMBER IS 11 USING EXPLICIT CURSORS 1 declare 2 cursor cenl is select eid.-------------------.PL/SQL procedure successfully completed. 10 dbms_output. 4 esal empp. TO WRITE A PL/SQL BLOCK TO UPDATE THE SALARY BY 5000 WHERE THE JOB IS LECTURER . EID ENAME JOB SAL DNO --------. 12 close cenl. 5 begin 6 open cenl.sal%type. 7 loop 8 fetch cenl into ecode. 3 begin 4 update ssempp set sal=sal+10000 where job='lecturer'. 9 exit when cenl%notfound. 13* end. 5 county:= sql%rowcount.

SQL> select * from ssempp.put_line('Employee record is not found').put_line('Employee record modification successful').-------------------. EID ENAME JOB SAL DNO --------. 16 / The number of rows are 3 Employee record modification successful PL/SQL procedure successfully completed. 9 if sql %found then 10 dbms_output. 8 end if.put_line('The number of rows are '|| county).-------------------.----------------1 nala lecturer 44000 11 2 kala seniorlecturer 20000 12 5 ajay lecturer 40000 11 6 vijay lecturer 28000 11 3 nila professor 60000 12 RESULT 108 . 11 else if sql%notfound then 12 dbms_output.6 if county > 0 then 7 dbms_output. 14 end if. 15 end. 13 end if.

The parts of a trigger are. • Trigger restriction: Restrictions on the trigger can be achieved The different uses of triggers are as follows.Thus the various operations were performed on the table using cursors and the output was verified. After: It fires the trigger after executing the trigger statement. TRIGGERS EX NO: 11 DATE: AIM To study and implement the concept of triggers. VARIABLES USED IN TRIGGERS • :new 109 . For each statement: This is the default trigger that is invoked. DEFINITION A trigger is a statement that is executed automatically by the system as a sideeffect of a modification to the database. • Trigger statement: Specifies the DML statements and fires the trigger body. It also specifies the table to which the trigger is associated. For each row: It specifies that the trigger fires once per row. Before: It fires the trigger before executing the trigger statement. It specifies that the trigger fires once per statement. • Trigger body or trigger action: It is a PL/SQL block that is executed when the triggering statement is used. • To generate data automatically • To enforce complex integrity constraints • To customize complex securing authorizations • To maintain the replicate table • To audit data modifications TYPES OF TRIGGERS • • • • The various types of triggers are as follows.

1 row created. TO CREATE THE TABLE ‘ITEMPLS’ SQL> create table itempls (ename varchar2(10). The values in these variables can be used in the database triggers for data manipulation SYNTAX create or replace trigger triggername [before/after] {DML statements} on [tablename] [for each row/statement] begin ------------------------------------------------------------------------exception end. SQL> insert into itempls values('xxx'. 1 row created. 110 . Table created. USER DEFINED ERROR MESSAGE The package “raise_application_error” is used to issue the user defined error messages Syntax: raise_application_error(error number. salary number(10)).13. The error message should be a character string. SQL> select * from itempls.• :old These two variables retain the new and old values of the column updated in the database.11. 1 row created. SQL> insert into itempls values('yyy'.‘error message‘). SQL> insert into itempls values('zzz'.12. The error number can lie between -20000 and -20999.10500).15500).10000). eid number(5).

ENAME EID SALARY ---------- --------- --------xxx 11 10000 yyy 12 10500 zzz 13 15500 TO CREATE A SIMPLE TRIGGER THAT DOES NOT ALLOW INSERT UPDATE AND DELETE OPERATIONS ON THE TABLE SQL> create trigger ittrigg before insert or update or delete on itempls for each row 2 begin 3 raise_application_error(-20010,'You cannot do manipulation'); 4 end; 5 6 / Trigger created. SQL> insert into itempls values('aaa',14,34000); insert into itempls values('aaa',14,34000) * ERROR at line 1: ORA-20010: You cannot do manipulation ORA-06512: at "STUDENT.ITTRIGG", line 2 ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG' SQL> delete from itempls where ename='xxx'; delete from itempls where ename='xxx' * ERROR at line 1: ORA-20010: You cannot do manipulation ORA-06512: at "STUDENT.ITTRIGG", line 2 ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG' SQL> update itempls set eid=15 where ename='yyy'; update itempls set eid=15 where ename='yyy' * ERROR at line 1: ORA-20010: You cannot do manipulation ORA-06512: at "STUDENT.ITTRIGG", line 2 ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG' TO DROP THE CREATED TRIGGER SQL> drop trigger ittrigg; 111

Trigger dropped. triggers SQL> create table client_master(cno number,name varchar2(20),bal_due number(10,2)); Table created. SQL> insert into client_master values(&cno,'&name',&bal_due); Enter value for cno: 1 Enter value for name: x Enter value for bal_due: 1000 old 1: insert into client_master values(&cno,'&name',&bal_due) new 1: insert into client_master values(1,'x',1000) 1 row created. SQL> / Enter value for cno: 2 Enter value for name: y Enter value for bal_due: 1000 old 1: insert into client_master values(&cno,'&name',&bal_due) new 1: insert into client_master values(2,'y',1000) 1 row created. SQL> / Enter value for cno: 3 Enter value for name: z Enter value for bal_due: 2000 old 1: insert into client_master values(&cno,'&name',&bal_due) new 1: insert into client_master values(3,'z',2000) 1 row created. SQL> create table auditclient(cno number,name varchar2(20),bal_due number(10,2),operation varchar2(1 0),odate date); Table created. SQL> create trigger audit_trail after update or delete on client_master for each row 2 declare 3 oper varchar2(10); 4 cno number; 112

5 name varchar2(20); 6 bal_due number(10,2); 7 begin 8 if updating then 9 oper:='update'; 10 end if; 11 12 13 14 15 16 17 18 19 if deleting then oper:='delete'; end if; cno:= :old.cno; name:= :old.name; bal_due:= :old.bal_due; insert into auditclient values(cno,name,bal_due,oper,sysdate); end; /

Trigger created. SQL> select cno,name,bal_due from client_master; CNO NAME BAL_DUE --------- -------------------- --------1x 1000 2y 1000 3z 2000 SQL> select cno,name,bal_due,operation,odate from auditclient; no rows selected SQL> update client_master set bal_due=2300 where cno=1; 1 row updated. SQL> select cno,name,bal_due from client_master; CNO NAME BAL_DUE --------- -------------------- --------1x 2300 2y 1000 3z 2000 SQL> select cno,name,bal_due,operation,odate from auditclient; CNO NAME BAL_DUE OPERATION ODATE 113

'&oname') new 1: insert into order1 values(2. CNO NAME BAL_DUE --------.--------1x 2300 2y 1000 SQL> select cno.'fan') 1 row created.--------1x 1000 update 11-AUG-09 3z 2000 delete 11-AUG-09 SQL> SQL> create table order1(ono number.oname varchar2(20)).odate from auditclient.---------.--------.-------------------. Enter value for ono: 1 Enter value for oname: fan old 1: insert into order1 values(&ono.--------.name. Table created.-------------------.--------.-------------------.bal_due.name.'bulb') 114 .---------.'&oname') new 1: insert into order1 values(1.operation. SQL> / Enter value for ono: 2 Enter value for oname: bulb old 1: insert into order1 values(&ono. SQL> select cno.bal_due from client_master.'&oname'). SQL> insert into order1 values(&ono. CNO NAME BAL_DUE OPERATION ODATE --------.--------1x 1000 update 11-AUG-09 SQL> SQL> delete from client_master where cno=3. 1 row deleted.

ono.'12/7/09') 1 row created. SQL> select * from order1.'&odate') new 1: insert into order2 values(1. SQL> create table order2(ono number. SQL> insert into order2 values(&ono. 115 .-------------------1 fan 2 bulb SQL> select * from order2. 5 / Trigger created. SQL> / Enter value for ono: 2 Enter value for odate: 12/8/09 old 1: insert into order2 values(&ono. ONO ODATE --------.-------------------1 12/7/09 2 12/8/09 SQL> delete from order1 where ono=1. ONO ONAME --------.'&odate').'&odate') new 1: insert into order2 values(2. 4 end. SQL> create or replace trigger order_det after delete on order1 for each row 2 begin 3 delete from order2 where ono=:old.'12/8/09') 1 row created. Enter value for ono: 1 Enter value for odate: 12/7/09 old 1: insert into order2 values(&ono.1 row created. Table created.odate varchar2(20)).

--------.price*qty where bid= :new. price) 2 begin 3 update order_list set tot_pr= :new.bid.-------------------2 bulb SQL> select * from order2.1 row deleted. ONO ONAME --------. SQL> update book2 set price=400 where bid=1. 4 end. SQL> select * from book2.--------. ONO ODATE --------. SQL> select * from order1. ONO BID QTY TOT_PR --------. 5 / Trigger created.--------1 dbms 300 2 cn 100 SQL> select * from order_list.--------1 1 5 1000 SQL> create or replace trigger book_detail2 after update on book2 for each row when(new. BID TITLE PRICE 116 .price > old.-------------------. BID TITLE PRICE --------.-------------------2 12/8/09 SQL> select * from book2. 1 row updated.

--------.--------.--------1 1 5 2000 117 .--------1 dbms 400 2 cn 100 SQL> select * from order_list. ONO BID QTY TOT_PR --------.-------------------.--------.

RETURN: It is the datatype of the function’s return value because every function must return a value. used to pass values to a sub-program. KEYWORDS AND THEIR PURPOSES REPLACE: It recreates the procedure if it already exists. PROCEDURE: It is the name of the procedure to be created. this clause is required.as} 118 .inout} datatype ) {is. Paranthesis can be omitted if no arguments are present. PROCEDURES AND FUNCTIONS EX NO: 12 DATE: AIM To write PL/SQL programs that executes the concept of functions and procedures. OUT: Specifies that the procedure passes a value for this argument back to it’s calling environment after execution ie. Procedures and functions are made up of. INOUT: Specifies that a value for the argument must be specified when calling the procedure and that procedure passes a value for this argument back to it’s calling environment after execution. executed and their respective outputs were verified.out. • Declarative part • Executable part • Optional exception handling part These procedures and functions do not show the errors.RESULT Thus the triggers were created . ARGUMENT: It is the name of the argument to the procedure. PROCEDURES – SYNTAX create or replace procedure <procedure name> (argument {in. They are essentially sub-programs. IN: Specifies that a value for the argument must be specified when calling the procedure ie. This is the default parameter. DEFINITION A procedure or function is a logically grouped set of SQL and PL/SQL statements that perform a specific task. used to return values to a caller of the sub-program.

as} variable declaration. 500. 600. begin PL/SQL subprogram body. 201). constant declaration. 202). FUNCTIONS – SYNTAX create or replace function <function name> (argument in datatype. exception exception PL/SQL block. SQL> insert into ititems values(103. 1600. ITEMID ACTUALPRICE ------------------101 2000 102 3000 103 4000 ORDID -------500 1600 600 PRODID --------201 202 202 119 . 3000. end. 1 row created. SQL> select * from ititems. begin PL/SQL subprogram body. exception exception PL/SQL block. end. CREATING THE TABLE ‘ITITEMS’ AND DISPLAYING THE CONTENTS SQL> create table ititems(itemid number(3). 2000.variable declaration. 4000. prodid number(4)). ordid number(4). actualprice number(5). 202). Table created. 1 row created. 1 row created. constant declaration. SQL> insert into ititems values(102. SQL> insert into ititems values(101.……) return datatype {is.

SQL> select * from ititems. total number) is price number. 10 exception 11 when null_price then 12 dbms_output.put_line('price is null').PROGRAM FOR GENERAL PROCEDURE – SELECTED RECORD’S PRICE IS INCREMENTED BY 500 . SQL> create procedure yyy (a IN number) is price number. 13 end.put_line('Actual price is ' || price). 2 null_price exception. EXECUTING THE PROCEDURE CREATED AND DISPLAYING THE UPDATED TABLE SQL> create procedure itsum(identity number. 5 if price is null then 6 raise null_price. 7 else 8 update ititems set actualprice=actualprice+total where itemid=identity. 14 / Procedure created. ITEMID ACTUALPRICE ------------------101 2500 102 3000 103 4000 ORDID --------500 1600 600 PRODID --------201 202 202 PROCEDURE FOR ‘IN’ PARAMETER – CREATION. SQL> exec itsum(101.put_line('price is null'). 5 if price is null then 6 dbms_output. EXECUTION SQL> set serveroutput on. PL/SQL procedure successfully completed. 500). 4 dbms_output. 7 end if. 9 end if. 3 begin 4 select actualprice into price from ititems where itemid=identity. 120 . 2 begin 3 select actualprice into price from ititems where itemid=a.

Actual price is 4000 PL/SQL procedure successfully completed. PROCEDURE FOR ‘INOUT’ PARAMETER – CREATION. 5 / Procedure created. PROCEDURE FOR ‘OUT’ PARAMETER – CREATION. 121 . 4 if identity<1000 then 5 b:=100. 8 / The value of b is 100 PL/SQL procedure successfully completed. 2 begin 3 select ordid into identity from ititems where itemid=a.put_line('The value of b is '|| b). 8 / Procedure created. 6 dbms_output. SQL> declare 2 a number. 6 end if. EXECUTION SQL> create procedure itit ( a in out number) is 2 begin 3 a:=a+1. SQL> exec yyy(103). 7 end. 7 end. b out number) is identity number. 4 begin 5 zzz(101. SQL> create procedure zzz (a in number. 9 / Procedure created. 4 end. EXECUTION SQL> set serveroutput on.b).8 end. 3 b number.

new 3: update bvx set dno=dno+a where id=1. Enter value for id: 1 old 4: select dno into a from bvx where id=&id.---------1 11 2 12 SQL> create or replace procedure yu(a in out number) is 2 begin 3 update bvx set dno=dno+a where id=&id. 4 select dno into a from bvx where id=&id. SQL> declare 2 a number. ID DNO ---------. SQL> select * from xbv. SQL> set serveroutput on. 5 end. 122 .put_line(‘The updated value is ‘||a). NAME ID -------------------. 7 / The updated value is 8 PL/SQL procedure successfully completed. Procedure created. 5 dbms_output. 6 end. 3 begin 4 itit(a). 6 / Enter value for id: 1 old 3: update bvx set dno=dno+a where id=&id.---------x 1 y 2 SQL> select * from bvx. new 4: select dno into a from bvx where id=1.SQL> declare 2 a number:=7.

end. SQL>insert into ittrain values (1001. dbms_output. 600).put_line('sal is'||a).tfare % type. 1 row created. SQL>insert into ittrain values (1002. SQL>select * from ittrain. / Enter value for a: 500 old 4: a:=&a. ID DNO ---------. tfare number(10)). new 4: a:=500. TNO --------1001 1002 TFARE -----------550 600 PROGRAM FOR FUNCTION AND IT’S EXECUTION SQL> create function aaa (trainnumber number) return number is 2 trainfunction ittrain. sal is511 PL/SQL procedure successfully completed. 123 .3 4 5 6 7 8 begin a:=&a.---------1 511 2 12 CREATE THE TABLE ‘ITTRAIN’ TO BE USED FOR FUNCTIONS SQL>create table ittrain ( tno number(10). 550). yu(a). SQL> select * from bvx. Table created. 1 row created.

'||total). SQL> set serveroutput on.3 begin 4 select tfare into trainfunction from ittrain where tno=trainnumber. 5 return(trainfunction). 10 end loop. 6 while b>0 7 loop 8 fact:=fact*b. FACTORIAL OF A NUMBER USING FUNCTION — PROGRAM AND EXECUTION SQL> create function itfact (a number) return number is 2 fact number:=1. SQL> declare 2 a number:=7. 5 dbms_output. 3 f number(10). 12 end. 4 begin 5 f:=itfact(a). SQL> set serveroutput on. 7 / Train fare is Rs.put_line('Train fare is Rs. 4 begin 5 b:=a. 7 / Function created. 3 b number. 6 end. 6 end. 3 begin 4 total:=aaa (1001).550 PL/SQL procedure successfully completed. 11 return(fact). 124 . 9 b:=b-1. 13 / Function created. SQL> declare 2 total number.

8 / The factorial of the given number is 5040 PL/SQL procedure successfully completed.put_line(‘The factorial of the given number is’||f).6 dbms_output. 7 end. 125 .

No.pname. A F.D 3.D: 1. if two tuples in r agree on the values of the attributes in X.D 4.e.RESULT Thus the PL/SQL programs were executed and their respective outputs were verified.e determinants and Y denotes a set of attributes on the right hand side i.Full F. It is based on the concept of functional dependency.Partial F. It is a formal technique for analysing relations based on their primary key and functional dependencies.D 5.D: A F.D.hours. Here X denotes a set of attributes on the left hand side i. Ex.d X->Y is a full F.plocation.pno}->{hours.pname.plocation} Here ssn and pno are key attributes and they determine the other non key attributes such as hours.D: X->Y i.13 Date: STUDY EXPERIMENT NORMALIZATION: Normalization is the process of decomposing the relation into fragments.e.D from X to Y (set of attributes) exists if and only if for every instance of r. then they agree on the values of the attributes in Y.Transitive F. Eg: emp(ssn.D FULL F.pname. 126 .Join F. dependents. X determines Y or Y is functionally dependent on X.pno. TYPES OF F.plocation) {ssn.Multivalued F. if the dependency does not hold on the removal of any attribute A from the set of attributes of X.D 2. GENERAL FORMAT OF F. It determines the relationship between the attributes. FUNCTIONAL DEPENDENCY: Functional dependency is a tool to measure the appropriateness of the attributes grouping into relational schemas.

plocation} FD4 {ssn}->{ename} Note: In FD3. PARTIAL F.pno}->{pname.eclass. Therefore the key attribute eno determines the non key attribute ehours.ecourse) FD1 {eno}->{ename. no need to check for partial dependencies. Eg:emp(ssn.pno}->{ename} Here even if the key attribute pno is lost. there exists multiple values of B.plocation} Here if the key attribute ssn is lost.D: A F.bdate.ename depends on a part of the key If the LHS has single attribute. pname and plocation depend on a part of the key In FD4.ename. Eg:student(eno.address. Eg:emp(ssn.bdate. FD2 {ssn.mid} Here non key attributes such as ename.dno}->{ename.dname. {X-|A|}->Y This dependency holds.still the dependency holds and we can determine the other non key attributes such as pname and plocation.still we can determine ename using ssn. TRANSITIVE F.ecourse} FD2 {eclass}->{ehours} FD3 {eno}->{ehours} In FD1 the key attribute eno determines the other non key attributes.oname) Branch bno sname oname B3 Ann Carol B3 David Tina 127 .mid) {ssn. FD3 {pno}->{pname.eclass.dname.ename.dname.D: A dependency from A to B is said to be multivalued dependency if for a value of A.If any of the key attribute is lost then the dependency does not hold. MULTIVALUED F.D: An attribute that is dependent on the attribute other than the key arrribute.mgrid are entirely dependent on key attributes such as ssn and dno.pname.{X-|A|}->Y it does not hold.address. Eg:branch(bno.sname.ehours.dno.ename.address.D X->Y is a partial F.D if some attribute A belongs to X can be removed from X and the dependency still holds.pno. In FD2 the non key attribute eclass determines other non key attribute ehours.plocation} FD1 {ssn.bdate.

B.then we can swap sname and oname and get 2 new tuples.palne_type) Service flight Day_of_week Plane_type 106 Monday 747 106 Thursday 747 106 Monday 1011 106 Thursday 1011 204 Wednesday 707 204 Wednesday 727 service relation is decomposed into two relations namely servday(flight.plane_type) flight 106 106 204 204 Plane_type 747 1011 707 727 If rejoin is done on servday and servtype relations. Suppose if any of the rows in service relation is deleted. Branch bno B3 B3 B3 B3 sname Ann David Ann David oname Carol Tina Tina Carol JOIN DEPENDENCY: A relation R with subsets of the attributes of R denoted as R(A.day_of_week) flight Day_of_week 106 Monday 106 Thursday 204 Wednesday servtype(flight.day_of_week.B. it is possible to reconstruct the original relation service.Z) satisfies a join dependency if and only if for every legal value of R is equal to the join of its projections on A. ….{bno}->{sname} {bno}->{oname} If the two tuples agree in all the attributes of bno.Z. Eg:service(flight.There is no loss of information. then rejoin of servtype and servday 128 .….

all the determinants should be a candidate key and a non-key attribute should not determine a key attribute.relations do not produce the original service relation. VARIOUS NORMAL FORMS: 1. [Candidate Keys are minimal super keys. It does not contain multivalued attributes. i)Values should be atomic and indivisible. 5. 3NF: For relation to be in 3NF.Glasgo 01 pAddress rentSta rt Lawrence 1-Julstreet.Glasgo 00 w rentFinis h 31-Aug01 1-Sep02 ren ownerN oName t o 35 CO40 Tina 0 Murph y CO93 45 Tony 0 Shaw 129 . it should be in 2NF and there should be no transitive dependency. 3. For eg. 4.Composite attributes 3. 7. composite attributes and nested relations.Nested relations 2.0NF : It is the unnormalized form.It may have 1. it should be in 1NF and there should be no partial dependency.2NF : For a relation to be in 2NF.Primary keys are candidate keys] 6. BCNF (Boyce-Codd NF): For a relation to be in BCNF form.1NF : A relation in which the intersection of each row and column contains only one value. 5NF: For a relation to be in 5NF form there should be no join dependency. 4NF: For a relation to be in 4NF form it should be in BCNF and there should be no non-trivial multivalued dependency.Multivalued attributes 2. ii)No repeating groups. consider a table ClientRental clientN o CR76 cNam e John Kay property No PG4 PG16 Novar Dr 1-Sepstreet.

cName. in a separate relation. rentFinish. propertyNo -> rentStart. propertyNo.rentStart -> propertyNo. rentFinish. ownerNo.cName Primary Keys: 1.Glasg ow Manor Road. Client Rental(clientNo.clientNo 2.Glasgo w Novar Dr. rent.rentFinish (Candidate key) 0NF : The above table is in unnormalized form since it contains many repeating groups. rent. ownerNo. oName (Partial Dependency) ownerNo -> oName (Transitive Dependency) clientNo.w CR56 Aline PG4 Stewa rt PG36 PG16 Lawrence Street.oName (Candidate propertyNo.Glasgow 1-Sep99 10-oct00 1-Nov02 10-June00 1-Dec01 10-Aug03 35 0 37 5 CO40 CO93 Tina Murph y Tony Shaw CO93 45 0 Tony Shaw The ClientRental relation has the following functional dependencies: FD1 FD2 FD3 FD4 FD5 key) FD6 clientNo. pAddress. pAddress. remove the repeating group by placing the repeating data.clientNo 2.rentStart -> clientNo.propertyNo So in order to remove the repeating groups. oName) 1NF : To convert the 0NF form to 1NF form . along with a copy of the original key attribute. ownerNo.cName.we decompose the relation ClientRental into 130 . rentStart. rentFinish (Primary key) clientNo -> cName (Partial Dependency) propertyNo -> pAddress. rent. Repeating Groups: 1.

Glasgo w cName John Kay Aline Stewart rentSta rt 1-Jul00 1-Sep01 1-Sep99 10-oct00 1-Nov02 rentFin rent ish 31350 Aug-01 1-Sep02 10June00 1-Dec01 450 350 375 owner No CO40 CO93 CO40 CO93 CO93 oName Tina Murph y Tony Shaw Tina Murph y Tony Shaw Tony Shaw 10450 Aug-03 2NF : Secondary normal form applies to relations with composite keys. the relations with a primary key composed of two or more attributes. pAddress.Glas gow CR56 PG4 Lawrence Street. oName} 1NF : Client clientNo CR76 CR56 PropertyRentalOwner clientN property pAddress o No CR76 PG4 Lawrence street.Glas gow CR76 PG16 Novar Dr street. we remove the functionality dependent attributes from the relation by placing them in a new relation along with a copy of their determinant. rent. rentFinish. pAddress. rentStart.cName) PropertyRentalOwner(clientNo.Glasg ow CR56 PG16 Novar Dr.e. rentFinish. ownerNo.D’s are {clientNo} -> {cName} {clientNo. propertyNo} -> {pAddress. oName) Identified F. The normalization of 1NF relations to 2NF involves the removal of partial dependencies. rentStart. rentFinish. i. 131 . If it exists.Client(clientNo. propertyNo.cName) PropertyRentalOwner(clientNo.Glas gow CR56 PG36 Manor Road. propertyNo. rent. rent. 1NF relations are Client(clientNo. ownerNo. ownerNo. rentStart.

rent. rentStart. oName {clientNo. ownerNo.Glasgo w PG16 Novar Dr street.oName) Ignore all relations with single key attribute. If it exists. oName) Client clientNo CR76 CR56 Rental clientNo CR76 CR76 CR56 CR56 CR56 cName John Kay Aline Stewart propertyNo PG4 PG16 PG4 PG36 PG16 rent 350 450 375 rentStart 1-Jul-00 1-Sep-01 1-Sep-99 10-oct-00 1-Nov-02 ownerNo CO40 CO93 CO93 rentFinish 31-Aug-01 1-Sep-02 10-June-00 1-Dec-01 10-Aug-03 oName Tina Murphy Tony Shaw Tony Shaw PropertyOwner propertyNo pAddress PG4 Lawrence street. Identified partial dependencies are {propertyNo} -> pAddress.Glasgo w 3NF : The normalization from 2NF relations to 3NF involves the removal of transitive dependencies. rentFinish) PropertyOwner(propertyNo. To remove partial dependency we decompose the relation PropertyRentalOwner into Rental(propertyNo. rent. we remove the transitively dependent attributes from the relation by 132 . ownerNo. rentFinish Here without the key attribute clientNo.Glasgo w PG36 Manor Road.we can determine the other non key attributes with the key attribute propertyNo. pAddress. propertyNo} -> rentStart.

rent.placing the attributes in a new relation along with a copy of the determinant.we decompose the relation PropertyOwner into two new relations PropertyForRent( propertyNo.Ds in 3NF form are {clientNo} -> {cName} {clientNo.rentFinish} {propertyNo} -> {pAddress. pAddress. Identified transitive dependencies in PropertyOwner relations are {propertyNo} -> {pAddress. rentFinish) PropertyOwner(propertyNo. rent. ownerNo.ownerName} {ownerNo} -> {oName} rent 350 450 375 ownerName CO40 CO93 CO93 oName Tina Murphy Tony Shaw 133 . ownerNo. pAddress.oName) PropertyForRent propertyNo pAddress PG4 Lawrence street.Glasgow Owner ownerNo CO40 CO93 BCNF : The F. rent. rentStart. 2NF relations are Client(clientNo.Glasgow PG36 Manor Road. oName) Ignore all relations with less than 3 attributes. oName} {ownerNo} -> {oName} {propertyNo}->{oName} Here the non key attribute oName is dependent on another non key attribute ownerNo.rent.Glasgow PG16 Novar Dr street.propertyNo} -> {rentStart.cName) Rental(propertyNo. Client and Rental relations do not have transitive dependencies. Therefore to remove the transitive dependencies. ownerNo) Owner(ownerNo.

propertyNo.Glasgow PG36 Manor Road. ownerNo) Owner(ownerNo. Hence all the 3NF relations are in BCNF normal form. rentStart. rentStart.D i.Ds are {clientNo. cName) Rental(propertyNo.propertyNo}->>{propertyNo} This functional dependency is a trivial multivalued functional dependency and there is no nontrivial MVD. ownerNo) Owner(ownerNo. cName) Rental(propertyNo. rent. rent.Here all the determinants on the left hand side of the F.Glasgow PG16 Novar Dr street. The relations in 4Nf form are Client(clientNo. cName) Rental(propertyNo. rentFinish) PropertyForRent( propertyNo.oName) 5NF: ClientRental <. The relations in BCNf form are Client(clientNo.Glasgow rent 350 450 375 ownerName CO40 CO93 CO93 134 .ownerNo are all candidate keys. rentFinish) PropertyForRent( propertyNo.Client U Rental U PropertyForRent U Owner There is no lossy join dependency The relations in 5Nf form are Client(clientNo.e clientNo. ownerNo) Owner(ownerNo. pAddress. rentFinish) PropertyForRent( propertyNo. rent. pAddress.oName) The normalized form of ClientRental relation is PropertyForRent propertyNo pAddress PG4 Lawrence street.oName) 4NF: The F. pAddress. rentStart.

Client clientNo CR76 CR56 Rental clientNo CR76 CR76 CR56 CR56 CR56 Owner ownerNo CO40 CO93 cName John Kay Aline Stewart propertyNo rentStart PG4 1-Jul-00 PG16 PG4 PG36 PG16 1-Sep-01 1-Sep-99 10-oct-00 1-Nov-02 oName Tina Murphy Tony Shaw rentFinish 31-Aug-01 1-Sep-02 10-June-00 1-Dec-01 10-Aug-03 135 .

Result: Thus the ClientRental relation is normalized DATABASE DESIGN USING E-R DIAGRAMS EXNO:14 DATE: BANK DATABASE: 136 .

phoneno address Customer has Account cname cid accno acctype borro ws belong s to Loan Branch loanno loantype branchname city HOSPITAL DATABASE: 137 .

bedno status beds type datein accounts amount roomn o Bed _ass igne d dateout Has_a ccount phno exa min es dob doctors Office phone specialit y ssno name patients ssno name address phno RALWAY TICKET RESERVATION DATABASE: 138 .

age phoneno source destination Passenger board s Train pid pname queues at trainno name train_ ticket buys Reservation Counter Ticket countern o place ticketno boarding place fare LIBRARY DATABASE: 139 .

author book Pub lish ed by price pubid publisher booki d Publisher name Bor row ed by Sup plie d by Supplier name Member type member supplier memberid Member name address Supplier id AIRLINE RESERVATION DATABASE: 140 .

address phoneno name state Passenger arriv es at Airport pname pid code airpo rt_tic ket city board s buys name Flight flight _tick et Ticket arriva l num ber departure ticketno dateofjo urney fare seatno type EMPLOYEE DATABASE: 141 .

name empn o address employee Deptno Dept name phno ecity Works _on department Date_started job titl e leve l salary jobid 142 .

In the general tab use the CONNECTION STRING and build the connection. To connect the database in oracle to the project we use adodc(ActiveX Data Object Data Control) .Now the component will be available in the toolbox.A window appears with name Project1 with Form1 in it. 4. 2. SOME OF THE COMPONENTS IN THE TOOLBOX: 1. withdrawal… 3. 143 . Right click the adodc1 and then click ADODC properties. To use these components in the program the name of the component must be used.combobox: Allows us to select a data from a list. 2.Click on the authentication tab and enter the username and password. 2. label.Click on the connection tab. 3. Enter the server name.0 with the new project in standardexe mode.textbox: The values are entered in the textbox.Open visual basic 6. age…etc. Add the components to the form according to the project.To open visual basic 6. The label’s caption is changed as per the project. combobox.0 and then click on apply. Once a form is created to add another form project>>addform.0>>visual basic6.0 or simply double click the icon on the desktop.PROCEDURE FOR PROJECT CREATION CREATING A FORM: 1.A property pages window will appear. All these components are identified by their name indicated in the properties window. It depends on the project to be created. Add the component to the form. Initially if this component is not available then goto project>>components>>Microsoft ADO Data control 6.username and password in the text boxes that appear and click on test connection.label: Used to display the the names of the fields to be filled in the project. CONNECTING BACK END(ORACLE): 1. Eg: depositing an amount in the bank database. Eg name. If a message test connection succeeded is displayed then the connection is correct otherwise redo the steps. 4. 3. FORM DESIGN: The Toolbox contains the textbox.0 goto start>>programs>>Microsoft visual studio 6. command button. After selecting the provider as MICROSOFT OLE DB PROVIDER FOR ORACLE.command button: Te command button is used to perform a task.

INSERTING DATAS INTO THE ORACLE TABLE FROM VB: Adodc1. For text type the sql statement Select * from tablename in command text(SQL).recordset.to copy the values in the textbox or combobox to the field specified. Adodc1. Call Adodc1.0 and click on apply.fields(“fieldname”)= textboxname.recordset. USING DATA GRID FOR OUTPUT: If the data grid is not available in the toolbox then goto project>>components>>Microsoft datagrid control 6. Connect the data grid to adodc1 by making the datasource of the datagrid as adodc1.5.to create a new record.Click on the recordsource tab and command type—1-adcmdtext or 2-adcmdtable.update.text. 144 . A function with the name of the textbox will appear. The function will contain the code for that command button or the text box.refresh – to refresh. SEARCHING FOR A DATA: In the general section of the program : Dim s as string In the command button (search) S=”select * from tablename where searchfield=” & field1 This statement will retrieve the rows which satisfy the condition. For table select the tablename from the dropdown list box.addnew. WRITING PROGRAMS FOR THE PROJECT: SWITCHING OVER FROM FORM TO CODING: Double click on the command button or the text box which has to contain the code.recordset. Adodc1.to update the values onto the table.

145 .

Fields("seatno") = seatno.Recordset.Text Adodc1.Recordset.Text Adodc1.Text Adodc1.Text Adodc1.Recordset.Fields("gender") = gender.Recordset.Recordset.Fields("class") = class.Text Adodc1.Text Adodc1.Recordset.Fields("destplace") = destplace.Text Adodc1.Fields("age") = agetxt.Recordset.Fields("flightno") = flightno.Fields("name") = nametxt.AIRLINE RESERVATION SYSTEM EX NO:15 DATE: FLIGHT BOOKING: Private Sub bookflight_Click() Adodc1.Show End Sub 146 .Text Adodc1.Fields("boardplace") = boardplace.Recordset.Refresh End Sub Private Sub gotopasdetails_Click() passengerdetails.Recordset.Update Call Adodc1.Recordset.AddNew Adodc1.

Show End Sub Private Sub Command1_Click() b = "select * from airline where seatno=" & seatno.Text Adodc1.Refresh End Sub 147 .PASSENGER DETAILS: Dim b As String Private Sub BACK_Click() airline.Text & " and flightno=" & flightno.RecordSource = b Call Adodc1.

148 .RESULT: Thus Airline Reservation System is implemented.

Show End Sub Private Sub Command2_Click() Form3.NO:16 DATE: AIM: To implement bank management system with visual basic as front end and oracle as back end.BANK MANAGEMENT SYSTEM EX.Show End Sub Private Sub Command4_Click() End End Sub ACCOUNT CREATION: 149 . MAIN PAGE: Private Sub Command1_Click() Form2.Show End Sub Private Sub Command3_Click(Index As Integer) Form4.

Recordset.Private Sub Command1_Click() Adodc1.Update Call Adodc1.Recordset.Recordset.AddNew Adodc1.Fields("name") = Text1.Fields("accno") = Text2.Refresh End Sub Private Sub Command2_Click() Form1.Text Adodc1.Text Adodc1.Recordset.Text Adodc1.Fields("balance") = Text3. NAME -------------------SIVA ADAM YABESH ACCNO --------101 102 103 BALANCE --------45000 5000 55000 ADDRESS -------------------CHENNAI CHENNAI CHENNAI ACCOUNT DEPOSIT: 150 .Show End Sub AFTER CREATING ACCOUNT: SQL> select * from bank.Text Adodc1.Fields("address") = Text4.Recordset.Recordset.

Update Call Adodc1.Recordset.Refresh End Sub Private Sub Command2_Click() Form1. NAME ACCNO BALANCE ADDRESS -------------------.Show End Sub AFTER DEPOSIT: SQL> select * from bank.RecordSource = a Call Adodc1.Dim a As String Private Sub Command1_Click() Adodc1.Text Adodc1.Fields(2) + Text3.Fields(2) = Adodc1.--------.Recordset.--------.Recordset.Refresh End Sub Private Sub Text2_LostFocus() a = "select * from bank where accno=" & Text2.-------------------SIVA 101 45000 CHENNAI ADAM 102 5000 CHENNAI YABESH 103 60000 CHENNAI ACCOUNT WITHDRAW: 151 .Text Adodc1.

Update Call Adodc1.Recordset.Text Adodc1.Text3.--------. 152 .Fields(2) . NAME ACCNO BALANCE ADDRESS -------------------.--------.-------------------SIVA 101 40000 CHENNAI ADAM 102 5000 CHENNAI YABESH 103 60000 CHENNAI RESULT: Thus bank management system is implemented.RecordSource = a Call Adodc1.Refresh End Sub Private Sub Text2_LostFocus() a = "select * from bank where accno=" & Text2.Dim a As String Private Sub Command1_Click() Adodc1.Recordset.Refresh End Sub Private Sub Command2_Click() Form1.Show End Sub AFTER WITHDRAW: select * from bank.Recordset.Fields(2) = Adodc1.Text Adodc1.

MAIN PAGE: Private Sub Command1_Click() Form2.Show End Sub Private Sub Command2_Click() Form3.EMPLOYEE PAYROLL SYSTEM EX.NO: DATE:17 AIM: To implement employee payroll system with visual basic as front end and oracle as back end.Show End Sub Private Sub Command3_Click() End End Sub 153 .

-------------------.Recordset.ADD NEW: Private Sub Command1_Click() Adodc1.Fields("id") = Text4.Recordset.-------------------.--------101 CSE 67000 CHENNAI 98766754 102 CSE 70000 CHENNAI 98766866 103 IT 75000 NELLAI 987668678 154 .Text Adodc1.--------.Refresh End Sub Private Sub Command2_Click() Form1.Text Adodc1. NAME -------------------ISSAC SIVA YABESH ID DEPT SALARY ADDRESS PHNO --------.Recordset.AddNew Adodc1.Fields("address") = Text3.Text Adodc1.Recordset.Show End Sub AFTER ADDING NEW DETAILS : SQL> select * from ed.Recordset.Text Adodc1.Refresh Call Adodc1.Fields("salary") = Text5.Fields("name") = Text1.Recordset.Recordset.Text Adodc1.Text Adodc1.Refresh Call Adodc1.Recordset.Update Call Adodc1.Fields("dept") = Text2.Fields("phno") = Text6.

-------------------.Text Adodc1.--------ISSAC 101 CSE 67000 CHENNAI 98766754 SIVA 102 CSE 70000 CHENNAI 98766866 YABESH 103 IT 80000 NELLAI 987668678 RESULT : Thus employee payroll system is implemented.Show End Sub Private Sub Text2_LostFocus() a = "select *from ed where id=" & Text2.Recordset.-------------------.--------.Refresh End Sub AFTER UPDATING SALARY : SQL> select * from ed. 155 .RecordSource = a Call Adodc1.Refresh End Sub Private Sub Command2_Click() Form1.UPDATE SALARY : Dim a As String Private Sub Command1_Click() Adodc1.Recordset.--------. NAME ID DEPT SALARY ADDRESS PHNO -------------------.Fields(3) = Adodc1.Update Call Adodc1.Recordset.Fields(3) + Text3.Text Adodc1.

Text And r = passwordtxt. r As String Private Sub submit_Click() s = "vecita" r = "ita" If (s = usernametxt.Text) Then patient. vbCritical) End If End Sub PATIENT : 156 .HOSPITAL DATABASE EX NO:18 DATE: LOGIN: Dim s.Show Else Call MsgBox("invalid username/password".

Show End Sub Private Sub pitxt_LostFocus() k = "select * from patient where patientid=" & pitxt.Dim k As String Private Sub ADMIT_Click() Adodc1.Update Call Adodc1.Fields("sex") = sextxt.Text Adodc1.Fields("name") = nametxt.Fields("patientid") = pitxt.Recordset.RecordSource = k Call Adodc1.Text Adodc1.Fields("phoneno") = phtxt.Text Adodc1.Recordset.Refresh End Sub 157 .Recordset.Recordset.Fields("age") = agetxt.Text Adodc1.Text Adodc1.Recordset.Recordset.Recordset.Refresh End Sub Private Sub gotodoc_Click() doctor.AddNew Adodc1.Text Adodc1.

Fields("doctorid") = docidtxt.Update Call Adodc1.Text Adodc1.DOCTOR: Dim a As String Private Sub docidtxt_LostFocus() a = "select * from doctor where doctorid= " & docidtxt.Refresh End Sub 158 .Recordset.Fields("specialisation") = spltxt.Fields("phoneno") = phtxt.Show End Sub Private Sub SUBMIT_Click() Adodc1.Refresh End Sub Private Sub gotopatient_Click() patient.Recordset.Text Adodc1.Recordset.Fields("name") = nametxt.Recordset.Recordset.AddNew Adodc1.RecordSource = a Call Adodc1.Recordset.Text Adodc1.Text Adodc1.Text Adodc1.

159 .RESULT : Thus Hospital Dtabase system is implemented.

MAIN PAGE: Private Sub Command1_Click() Form2.NO:19 DATE: AIM: To implement library management system with visual basic as front end and oracle as back end.LIBRARY MANAGEMENT SYSTEM EX.Show End Sub Private Sub Command2_Click() Form3.Show End Sub Private Sub Command3_Click() End End Sub 160 .

Text Adodc1.-------------------101 DBMS 102 MICROPROCESSOR 103 PQT AUTHOR -------------------SILBER GAONKAR DONALD GROSS PUBLISHER -------------------PERSON MC GRAW HILL JOHN WILEY&SONS LTD 161 .Text Adodc1.Text Adodc1.AddNew Adodc1.ADD A BOOK: Private Sub Command1_Click() Adodc1.Text Adodc1.Recordset.Recordset.Fields("bookid") = Text1.Fields("author") = Text3.Recordset.Fields("publisher") = Text4.Update Call Adodc1.Recordset. BOOKID TITLE --------.Recordset.Recordset.Show End Sub AFTER ADDING A BOOK: SQL> select * from library.Refresh End Sub Private Sub Command2_Click() Form1.Fields("title") = Text2.

RecordSource = a Call Adodc1.Refresh End Sub Private Sub Command2_Click() Form1.Text Adodc1.Show End Sub Private Sub Text1_LostFocus() a = "select * from library where bookid=" & Text1. 162 .Refresh RESULT: Thus library management system is implemented.SEARCHING A BOOK: Dim a As String Private Sub Command1_Click() If a = "select * from library where bookid=" & Text1.Text Then Adodc1.RecordSource = a MsgBox ("book is available") Else MsgBox ("book is not available") End If Call Adodc1.

Recordset.Fields("age") = agetxt.RAILWAY TICKET RESERVATION EXNO:20 DATE: BOOK A TICKET: Private Sub book_Click() Adodc1.Text Adodc1.AddNew Adodc1.Text Adodc1.Text Adodc1.Recordset.Refresh End Sub Private Sub gotopasdetails_Click() passenger_details.Fields("class") = class.Text Adodc1.Recordset.Fields("boardplace") = board.Fields("sex") = sex.Text Adodc1.Recordset.Show End Sub 163 .Fields("dest") = dest.Fields("trainno") = trainno.Text Adodc1.Fields("name") = nametxt.Text Adodc1.Recordset.Text Adodc1.Recordset.Fields("seatno") = seat_no.Recordset.Recordset.Update Call Adodc1.Recordset.Recordset.

PASSENGER DETAILS: Dim s As String Private Sub gototicketreservation_Click() TICKETRESERVATION.RecordSource = s Call Adodc1.Text & "and trainno=" & train_no.Show End Sub Private Sub SEARCH_Click() s = "select * from ticket where seatno= " & seat_no.Text Adodc1.Refresh End Sub 164 .

RESULT: Thus Railway Ticket Reservation System is implemented. 165 .

Page Footer : Appears at the end of every page. Set the Database Object to Table. This is repeated over and over for each record in the Database. and for the Object Name pick the table emp. Note : If this option is not visible then Click Project>>Components. so if you have 100 records 166 . Add a command to the connection created in above step and edit the properties. Group Header: A group is associated with a Command in the Data Environment. You can use multiple groups to show data from multiple Commands. Step 2: Add Data Report by : Clicking on Project >> Add Data Report. Check the Data Report check box.MENU DESIGN AND DATA REPORT CREATION EX NO:21 DATE: CREATING A REPORT: Step 1 : Start a new project Add a Data Environment and set the connection to point to the employee database created earlier. Click Designers tab. Detail: This is where all the action happens. Report Footer: Appears at the End of the Report. Report Designer will be displayed as shown below : Set the following report propereties as given below : DataSource field to: DataEnvironment1 DataMember field to: Command1 Data Report Section Description: Report Header: Appears at the Beginning of the Report. Each group begins a new section based on a command. Page Header : Appears at the top of every page. Group Footer: Ends a group section. Click OK.

Run the project. The result will be displayed as shown below : How to call a report from a form Open the Form called Form1. In the Data Environment window expand Command1 so that you can see each of the fields.. Now doubleclick the CommandButton and place this code: Private Sub Command1_Click() DataReport1. Here the menu is used for data report creation. as Form1. Drag the label in the page header section so that it should appear once per page and in details section only the data will be displayed. TO CREATE A MENU: TOOLS>>MENUEDITOR Caption:&employee_details Name:mnuemployee_details A menu is created. and change the Caption to be "Preview". It should appear as shown below : Similarly drag other fields and adjust them.Show End Sub Set the Start Up property in the Project Properties. If you click on the left most one you will notice it is a Label.there will be 100 copies of this detail. Now drag the required fields onto the Data Report window and drop it in the Detail section. Run the project and click on the Preview button to see the report. as DataReport1. Add a CommandButton to the form.. which will display the field name and the rightmost one is a field (name:ReportTextBox) which will contain the data from that field. Preview the Report Set the Start Up property in the Project Properties. 167 .

FORM WITH MENU CREATED: DATA REPORT FOR EMPLOYEE: Private Sub mnuemployee_details_Click() DataReport1.Show End Sub 168 .

DATA REPORT FOR DEPARTMENT: Private Sub mnudepartment_details_Click() DataReport2.Show End Sub 169 .

170 .Procedure to do Menu design EXAMPLE 1: The end result of Example 1 will be a form containing a menu with two top-level items. Print. and Exit items. The File menu. File and Help. shown below. Note that separator bars appear above the Save. will have the following level-two items below it: New. Save. Open. and Exit. Print. Save As.

The Help menu contains just one level-two item below it. Invoke the Menu Editor from the Tools menu item as shown below: 171 . About.

To build the menu described above. 1 . we establish "F" as an access key for the File item it enables the user to drop down the File menu by keying "Alt+F" on the keyboard in addition to clicking the "File" item with the mouse). For "Name".Start a new VB project and invoke the Menu Editor using either method shown above (click the Menu Editor toolbar icon or select the Menu Editor option from the Tools menu). perform the following steps. 172 . as shown below: 1. The Menu Editor screen appears. For "Caption". type &File (by placing the ampersand to the left of the "F". type mnuFile.

or (3) keying Ctrl+N. For "Caption". Result: Thus the Report is generated successfully 173 . Click the "right-arrow" button (shown circled below). So here. for "Name". A ellipsis (. and for "Shortcut". you are providing the user three ways of invoking the "New" function: (1) clicking File.) will appear as the next item in the menu list. you allow the user to access the associated menu item by pressing that key combination.Click the Next button 2. Click the Next button…………………….N (because we set up an access key for "N" by placing an ampersand to left of "N" in "New")... By specifying a shortcut. (2) keying Alt+F. type &New. indicating that this item is a level-two item (below "File").. select Ctrl+N. type mnuNew. then clicking New on the menu.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->