dbms-lm kavi with minipjt

73
ACTCET-CSE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EX. NO:1 DDL COMMANDS Date: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Aim : To know the uses of following DDL Commands Create Table Alter Table Drop Table Syntax & Description: The SQL command for creating an empty table has the following form: create table <table> ( <column 1> <data type> [not null] [unique] [<column constraint>],… <column n> <data type> [not null] [unique] [<column constraint>], [<table constraint(s)>] ); For each column, a name and a data type must be specified and the column name must be unique within the table definition. Column definitions are separated by comma. There is no difference between names in lower case letters and names in upper case letters. In fact, the only place where upper and lower case letters matter are strings comparisons. A not null constraint is directly specified after the data type of the column and the constraint requires defined attribute values for that column, different from null. The keyword unique specifies that no two tuples can have the same attribute value for this column. Unless the condition not null is also specified for this column, the attribute value null is allowed and two tuples having the attribute value null for this column do not violate the constraint. Modifying Table- and Column Definitions It is possible to modify the structure of a table (the relation schema) even if rows have already been inserted into this table. A column can be added using the alter table command alter table <table> add(<column> <data type> [default <value>] [<column constraint>] ); If more than only one column should be added at one time, respective add clauses need to be separated by colons. A table constraint can be added to a table using alter table <table> add (<table constraint>); Note that a column constraint is a table constraint, too. not null and primary key constraints can only be added to a table if none of the 1

Upload: kavimithu

Post on 08-Nov-2014

37 views

Category:

Documents


0 download

DESCRIPTION

lab manual

TRANSCRIPT

Page 1: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:1 DDL COMMANDSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :

To know the uses of following DDL Commands Create Table Alter Table Drop Table

Syntax & Description:The SQL command for creating an empty table has the following form:create table <table> (<column 1> <data type> [not null] [unique] [<column constraint>],…<column n> <data type> [not null] [unique] [<column constraint>],[<table constraint(s)>] );For each column, a name and a data type must be specified and the column name must be

unique within the table definition. Column definitions are separated by comma. There is no difference between names in lower case letters and names in upper case letters. In fact, the only place where upper and lower case letters matter are strings comparisons. A not null constraint is directly specified after the data type of the column and the constraint requires defined attribute values for that column, different from null. The keyword unique specifies that no two tuples can have the same attribute value for this column. Unless the condition not null is also specified for this column, the attribute value null is allowed and two tuples having the attribute value null for this column do not violate the constraint.

Modifying Table- and Column DefinitionsIt is possible to modify the structure of a table (the relation schema) even if rows have already been

inserted into this table. A column can be added using the alter table commandalter table <table>add(<column> <data type> [default <value>] [<column constraint>] );If more than only one column should be added at one time, respective add clauses need to beseparated by colons. A table constraint can be added to a table usingalter table <table> add (<table constraint>);Note that a column constraint is a table constraint, too. not null and primary key constraints can only be added to a table if none of the specified columns contains a null value. Table definitions can be modified in an analogous way. This is useful, e.g., when the size of strings that can be stored needs to be increased. The syntax of the command for modifying a column isalter table <table>modify(<column> [<data type>] [default <value>] [<column constraint>]);

Deleting a TableA table and its rows can be deleted by issuing the command drop table <table> [cascade constraints];

TO CREATE TABLE. SQL> create table depart(dno number(10),dname varchar2(10),primary key(dno));

Table created.1

Page 2: Dbms-LM Kavi With Minipjt

ACTCET-CSE

SQL> desc depart;

Name Null? Type ----------------------------------------- -------- ---------------------------- DNO NOT NULL NUMBER(10) DNAME VARCHAR2(10)

SQL> create table emp(eno number(10),ename varchar2(10),dno number(10),sal number(10),jobid varchar2(10),mgrid varchar2(10),foreign key(dno) references depart(dno));

Table created

SQL> desc emp;

Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID VARCHAR2(10) MGRID VARCHAR2(10)

SQL > Create Table Cust(cname varchar2(15),cid number(5),caddr char(10),caccno number(5),cacctype varchar2(10),cbalance float,Primary key(cid),unique(cname),unique(caccno),check(cbalance>=1000));

SQL> desc cust;

Name Null? Type ----------------------------------------- -------- ---------------------------- CNAME VARCHAR2(15) CID NOT NULL NUMBER(5) CADDR CHAR(10) CACCNO NUMBER(5) CACCTYPE VARCHAR2(10) CBALANCE FLOAT(126)

TO ALTER TABLE ADD SQL> alter table emp add(primary key(eno),addr varchar2(10));

Table altered.

2

Page 3: Dbms-LM Kavi With Minipjt

ACTCET-CSESQL> desc emp;

Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID VARCHAR2(10) MGRID VARCHAR2(10) ADDR VARCHAR2(10)

SQL> alter table emp add(phno number(5));

Table altered.

SQL> desc emp;

Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20) MGRID VARCHAR2(10) ADDR VARCHAR2(10) PHNO NUMBER(5)

MODIFY SQL> alter table emp modify(jobid char);

Table altered.

SQL> desc emp;

Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20) MGRID VARCHAR2(10) ADDR VARCHAR2(10) PHNO VARCHAR2(10)

3

Page 4: Dbms-LM Kavi With Minipjt

ACTCET-CSESQL> alter table emp modify(jobid char(20));

Table altered.

SQL> desc emp;

Name Null? Type----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20) MGRID VARCHAR2(10) ADDR VARCHAR2(10) PHNO VARCHAR2(10)

SQL> alter table emp modify(jobid char(5));

alter table emp modify(jobid char(5)) *ERROR at line 1:

ORA-01441: cannot decrease column length because some value is too big

DROP

SQL> alter table emp drop(phno);

Table altered.

SQL> desc emp;

Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20) MGRID VARCHAR2(10) ADDR VARCHAR2(10)

SQL> alter table emp drop(addr);

Table altered.

4

Page 5: Dbms-LM Kavi With Minipjt

ACTCET-CSESQL> desc emp;

Name Null? Type----------------------------------------- -------- ----------------------------ENO NOT NULL NUMBER(10)ENAME VARCHAR2(10)DNO NUMBER(10)SAL NUMBER(10)JOBID CHAR(20)MGRID VARCHAR2(10)

TO DROP THE TABLE

SQL> drop table emp;

Table dropped.

SQL> desc emp;

ERROR:

ORA-04043: object emp does not exist

Result: Thus the DDL Commands have been run.

5

Page 6: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:2 DML COMMANDSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Aim :To know the uses of following DML Commands

Insert Update Delete

Syntax & Description:The most simple way to insert a tuple into a table is to use the insert statement

insert into <table> [(<column i, . . . , column j>)]values (<value i, . . . , value j>);

For each of the listed columns, a corresponding (matching) value must be specified. Thus an insertion does not necessarily have to follow the order of the attributes as specified in the create table statement. If a column is omitted, the value null is inserted instead. If no column list is given, however, for each column as defined in the create table statement a value must be given.

For modifying attribute values of (some) tuples in a table, we use the update statement:update <table> set<column i> = <expression i>, . . . , <column j> = <expression j>[where <condition>];An expression consists of either a constant (new value), an arithmetic or string operation, oran SQL query. Note that the new value to assign to <column i> must a the matching data type.An update statement without a where clause results in changing respective attributes of alltuples in the specified table. Typically, however, only a (small) portion of the table requires an update. All or selected tuples can be deleted from a table using the delete command:delete from <table> [where <condition>];If the where clause is omitted, all tuples are deleted from the table. An alternative commandfor deleting all tuples from a table is the truncate table <table> command. However, in thiscase, the deletions cannot be undone

SQL > Create Table Cust(cname varchar2(15),cid number(5),caddr char(10),caccno number(5),cacctype varchar2(10),cbalance float,Primary key(cid),unique(cname),unique(caccno),check(cbalance>=1000));

SQL> desc cust;

Name Null? Type ----------------------------------------- -------- ---------------------------- CNAME VARCHAR2(15) CID NOT NULL NUMBER(5) CADDR CHAR(10) CACCNO NUMBER(5) CACCTYPE VARCHAR2(10) CBALANCE FLOAT(126)

6

Page 7: Dbms-LM Kavi With Minipjt

ACTCET-CSE

SQL> insert into cust values('Anitha',01,'Chennai',1001,'savings',15000);

1 row created.

SQL> insert into cust values('Shriram',02,'Pondy',1002,'savings',25000);

1 row created.

SQL> insert into cust values('Chamundi',03,'Salem',1003,'fd',36200);

1 row created.

SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: SubhaEnter value for cid: 04Enter value for caddr: SalemEnter value for caccno: 1009Enter value for cacctype: 5000Enter value for cbalance: 5000Old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)New 1: insert into cust values('Subha',04,'Salem',1009,'RD',5000)

1 row created.SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: MadhanEnter value for cid: 4Enter value for caddr: SalemEnter value for caccno: 1004Enter value for cacctype: checkingsEnter value for cbalance: 5000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Madhan',4,'Salem',1004,'checkings',5000)

1 row created.

SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: SubhaEnter value for cid: 5Enter value for caddr: TrichyEnter value for caccno: 1005Enter value for cacctype: checkingsEnter value for cbalance: 10000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Subha',5,'Trichy',1005,'checkings',10000)

1 row created.

SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);7

Page 8: Dbms-LM Kavi With Minipjt

ACTCET-CSEEnter value for cname: JayashreeEnter value for cid: 6Enter value for caddr: PondyEnter value for caccno: 1006Enter value for cacctype: fdEnter value for cbalance: 15000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Jayashree',6,'Pondy',1006,'fd',15000)

1 row created.

SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: SridharanEnter value for cid: 7Enter value for caddr: KanchiEnter value for caccno: 1007Enter value for cacctype: fdEnter value for cbalance: 22000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Sridharan',7,'Kanchi',1007,'fd',22000)

1 row created.

SQL> select * from cust;

CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- -----------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Chamundi 3 Salem 1003 fd 36200Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000Jayashree 6 Pondy 1006 fd 15000Sridharan 7 Kanchi 1007 fd 22000

7 rows selected.

SQL>update cust set caccno=1111 where cname='Chamundi';

1 row updated

SQL> select * from cust;

CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- --------------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Chamundi 3 Salem 1111 fd 36200Madhan 4 Salem 1004 checkings 5000

8

Page 9: Dbms-LM Kavi With Minipjt

ACTCET-CSESubha 5 Trichy 1005 checkings 10000Jayashree 6 Pondy 1006 fd 15000Sridharan 7 Kanchi 1007 fd 22000

7 rows selected.

SQL>delete from cust where cacctype='fd';

3 row deleted

SQL> select * from cust;

CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- -------------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000

4 rows selected.

Result:

Thus the DML command have been run.

9

Page 10: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:3a SELECTIONDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :

To know the uses of following commands in Oracle Between…and In Not in Like Relational Operators Logical Operators

Syntax & Description:select [distinct] [<alias ak>.]<column i>, . . . , [<alias al>.]<column j>from <table 1> [<alias a1>], . . . , <table n> [<alias an>][where <condition>]The specification of table aliases in the from clause is necessary to refer to columns that have the same name in different tables. For example, the column DEPTNO occurs in both EMP and DEPT. If we want to refer to either of these columns in the where or select clause, a table alias has to be specified and put in the front of the column name. Instead of a table alias also the complete relation name can be put in front of the column such as DEPT.DEPTNO, but this sometimes can lead to rather lengthy query formulations.SQL> select * from cust;

CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- ---------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Chamundi 3 Salem 1003 fd 36200Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000Jayashree 6 Pondy 1006 fd 15000Sridharan 7 Kanchi 1007 fd 22000

7 rows selected.

SQL> select cname,caddr from cust where cbalance between 1000 and 10000;

CNAME CADDR--------------- ----------Madhan SalemSubha Trichy

SQL> select cname,cid,cacctype from cust where cacctype in ('savings','checkings','fd');

CNAME CID CACCTYPE--------------- ---------- ----------Anusha 1 savingsShriram 2 savingsChamundi 3 fd

10

Page 11: Dbms-LM Kavi With Minipjt

ACTCET-CSEMadhan 4 checkingsSubha 5 checkingsJayashree 6 fdSridharan 7 fd

7 rows selected.

SQL> select cname,cid,cacctype from cust where cacctype not in ('savings','checkings');

CNAME CID CACCTYPE--------------- ---------- ----------Chamundi 3 fdJayashree 6 fdSridharan 7 fd

SQL> select cname,cbalance from cust where cname like '_a%an';

CNAME CBALANCE--------------- ----------Madhan 5000

SQL> select cname,cbalance from cust where cbalance>=15000;

CNAME CBALANCE--------------- ----------Anusha 15000Shriram 25000Chamundi 36200Jayashree 15000Sridharan 22000

5 rows selected.

SQL> select cname,cacctype,cbalance from cust where cbalance>20000 and cacctype=’fd’;

CNAME CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- ----------Chamundi fd 36200Sridharan fd 22000

2 rows selected.

Result:

Thus the all types of select commands have been run.

11

Page 12: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:3b JOINSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :

To know the joins, its types and to use joins in tables

Description :Comparisons in the where clause are used to combine rows from the tables listed in the from clause.Example: In the table EMP only the numbers of the departments are stored, not their name. For each salesman, we now want to retrieve the name as well as the number and the name of the department where he is working:select ENAME, E.DEPTNO, DNAMEfrom EMP E, DEPT Dwhere E.DEPTNO = D.DEPTNOand JOB = ’SALESMAN’;Explanation: E and D are table aliases for EMP and DEPT, respectively. The computation of thequery result occurs in the following manner (without optimization):1. Each row from the table EMP is combined with each row from the table DEPT (this operationis called Cartesian product). If EMP contains m rows and DEPT contains n rows, wethus get n _ m rows.2. From these rows those that have the same department number are selected (whereE.DEPTNO = D.DEPTNO).3. From this result finally all rows are selected for which the condition JOB = ’SALESMAN’holds.In this example the joining condition for the two tables is based on the equality operator “=”.The columns compared by this operator are called join columns and the join operation is calledan equijoin. Any number of tables can be combined in a select statement.Example: For each project, retrieve its name, the name of its manager, and the name ofthe department where the manager is working:select ENAME, DNAME, PNAMEfrom EMP E, DEPT D, PROJECT Pwhere E.EMPNO = P.MGRand D.DEPTNO = E.DEPTNO;It is even possible to join a table with itself:Example: List the names of all employees together with the name of their manager:select E1.ENAME, E2.ENAMEfrom EMP E1, EMP E2where E1.MGR = E2.EMPNO;Explanation: The join columns are MGR for the table E1 and EMPNO for the table E2.The equijoin comparison is E1.MGR = E2.EMPNO.

JOIN OPERATIONS

SQL>create table locn (lid number(5),city varchar(10),area varchar(5),primary key(lid));

Table created;

SQL>desc locn;

12

Page 13: Dbms-LM Kavi With Minipjt

ACTCET-CSE Name Null? Type ----------------------------------------- -------- --------------------------- LID NOT NULL NUMBER(5) CITY VARCHAR2(10) AREA VARCHAR2(5)

SQL>create table dep (dno number(5),dname varchar(10),lid number(5),primary key(dno),foreign key(lid) references locn(lid));

Table created;

SQL>desc dep; Name Null? Type ----------------------------------------- -------- -------------------- DNO NOT NULL NUMBER(5) DNAME VARCHAR2(10) LID NUMBER(5)

SQL>create table emp (eid number(5),ename varchar(10),dno number(5),esal number(10),jobid number(5),mgrid varchar(5),primary key(eid),foreign key(dno) references dep(dno));

Table created;

SQL>desc emp;

Name Null? Type ----------------------------------------- -------- ---------------------------- EID NOT NULL NUMBER(5) ENAME VARCHAR2(10) DNO NUMBER(5) ESAL NUMBER(10) JOBID VARCHAR2(5) MGRID NUMBER(3)

SQL>create table grade(gno number(5),ls number(8),hs number(8));

Table created;

SQL>desc grade; Name Null? Type ----------------------------------------- -------- ------------------ GNO NOT NULL NUMBER(5) LS NUMBER(8) HS NUMBER(8)SQL>insert into locn values(&lid,'&city','&area');

13

Page 14: Dbms-LM Kavi With Minipjt

ACTCET-CSEenter lid:1enter city:chennaienter area:aaaold 1: insert into locn values(&lid,'&city','&area')new 1: insert into locn values(1,'chennai','aaa')1 row createdSQL>insert into dep values(&dno,'&dname',&lid);enter dno:1enter dname:adminenter lid:2old 1: insert into dep values(&dno,'&dname',&lid)new 1: insert into dep values(1,'admin',2)1 row createdSQL>insert into emp values(&eid,'&ename',&dno,&esal, &jobid,&mgr id);enter eid:3enter ename:zzzenter dno:3enter esal :3500enter jobid:2enter mgr id:2old 1: insert into emp values(&eid,'&ename',&dno,&esal,&jobid,&mgrid)new 1: insert into emp values(1,'zzz',3500,2,2)1 row created

SQL>insert into grade values(&gno,&ls,&hs);enter gno:1enter ls:1000enter hs:2000old 1: insert into grade values(&gno,&ls,&hs)new 1: insert into grade values(1,1000,2000)

1 row created

SQL> select * from dep;

DNO DNAME LID---------- ---------- ---------------------- 1 admin 2 2 finance 3 3 hr 1 4 market 3 5 sales 1

SQL> select * from locn;

LID CITY AREA---------- ---------- -----------------------

14

Page 15: Dbms-LM Kavi With Minipjt

ACTCET-CSE 1 chennai aaa 2 bombay bbb 3 calcutta ccc

SQL> select * from grade;

GNO LS HS---------- ---------- ---------- 1 1000 2000 2 2001 3000 3 3001 4000 4 4001 5000

SQL> select * from emp;

EID ENAME DNO ESAL JOBID MGRID------- ---------- ---------- ---------- ----- ---------- 5 bbc 4700 2 1 xxx 1 4000 1 2 yyy 2 2000 2 1 3 zzz 3 3500 2 2 4 abc 2 4500

EQUI-JOIN~~~~~~~~~SQL>select e.ename,d.dname from emp e,dep d where e.dno=d.dno;

ENAME DNAME---------- ----------xxx adminyyy financezzz hrabc finance

NON-EQUIJOIN~~~~~~~~~~~~SQL> select e.ename,e.esal,g.gno from emp e,grade g where e.esal between g.ls and g.hs;ENAME ESAL GNO---------- ---------- ----------bbc 4700 4xxx 4000 3yyy 2000 1zzz 3500 3abc 4500 4

15

Page 16: Dbms-LM Kavi With Minipjt

ACTCET-CSE

LEFTOUTER-JOIN~~~~~~~~~~~~SQL> select e.ename,d.dname from emp e,dep d where e.dno(+)=d.dno;

ENAME DNAME---------- ----------------xxx adminyyy financeabc financezzz hr market sales

RIGHTOUTER-JOIN~~~~~~~~~~~~~~~SQL> select e.ename,d.dname from emp e,dep d where e.dno=d.dno(+);

ENAME DNAME---------- ---------------bbcxxx adminyyy financezzz hrabc finance

FULLOUTER-JOIN~~~~~~~~~~~~~~SQL>select e.ename,d,dname from emp e,dep d where e.dno(+)=(+)d.dno;

ENAME DNAME-------- ---------------bbc xxx adminyyy financezzz hrabc finance market sales

SELFJOIN----TO DISPLAY ENAME & THEIR MANAGER NAMES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL> select e.ename,m.ename from emp e,emp m where e.mgrid=m.eid;

ENAME ENAME---------- ----------bbc yyy

16

Page 17: Dbms-LM Kavi With Minipjt

ACTCET-CSEyyy xxxzzz yyy

SELFJOIN----TO DISPLAY MANAGER'S SALARY FOR EVERY EMPLOYEE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL> select e.ename,m.esal from emp e,emp m where e.mgrid=m.eid;

ENAME ESAL---------- ----------------bbc 2000yyy 4000zzz 2000

Result:Thus the types of join queries have been run.

17

Page 18: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EX. NO:4 VIEWDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :

To create view for a table.

Syntax To create viewCreate view viewname as select columnname 1…columnname n from tablename where condition;

ExampleCreate view myview as select regno, name from stud;

Syntax To display viewselect columnname 1…columnname n from viewname where condition;

ExampleSelect regno, name from myview;

Syntax To delete viewdrop viewname;

Exampledrop myview;.

Result:

Thus the view is successfully created and displayed.

18

Page 19: Dbms-LM Kavi With Minipjt

ACTCET-CSE

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:5a PL/SQL-CONTROLSTRUCTUREDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :To implement control structure of PL/SQL.

SYNTAX's of CONTROL STATEMENTS in PL/SQL

1. BRANCHING2. SELECTION3. LOOPING

BRANCHING STATEMENTS

1.Simple IF2.ELSIF3.ELSE IF

SIMPLE IF

IF condition THEN statement1; statement2;END IF;

IF-THEN-ELSE STATEMENT

IF condition THEN statement1;ELSE statement2;END IF;

ELSIF STATEMENTS

IF condition1 THEN statement1;ELSIF condition2 THEN statement2;ELSIF condition3 THEN statement3;ELSE

19

Page 20: Dbms-LM Kavi With Minipjt

ACTCET-CSE statementn;END IF;

ITERATIONS IN PL/SQL

SIMPLE LOOP

LOOP statement1;EXIT [ WHEN Condition];END LOOP;

WHILE LOOP

WHILE condition LOOPstatement1;statement2;

END LOOP;

FOR LOOP

FOR counter IN [REVERSE] LowerBound..UpperBoundLOOP

statement1;statement2;

END LOOP;

WRITE A PL/SQL PROGRAM TO FIND THE LARGEST OF TWO NUMBERS

declarea number;b number;begina:=&a;b:=&b;if a=b thendbms_output.put_line('BOTH ARE EQUAL');elsif a>b thendbms_output.put_line('A IS GREATER');elsedbms_output.put_line('B IS GREATER');end if;end;

20

Page 21: Dbms-LM Kavi With Minipjt

ACTCET-CSEOUTPUT:SQL> @ GREATESTOF2.sql 13 /Enter value for a: 5old 5: a:=&a;new 5: a:=5;Enter value for b: 2old 6: b:=&b;new 6: b:=2;A IS GREATER

PL/SQL procedure successfully completed.

WRITE A PL/SQL PROGRAM TO FIND THE FACTORIAL OF A GIVEN NUMBER

declaren number;f number:=1;beginn:=&n;for i in 1..nloopf:=f*i;end loop;dbms_output.put_line('the factorial is'|| f);end;

OUTPUT:

SQL> @ FACTORIAL.sql 12 /Enter value for n: 5old 5: n:=&n;new 5: n:=5;the factorial is120

PL/SQL procedure successfully completed.

Result:

Thus the control structures using PL/SQL have been run.

21

Page 22: Dbms-LM Kavi With Minipjt

ACTCET-CSE

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO: 5b PROCEDURESDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :

To know the use of procedures in PL/SQL

Syntax & Description :PL/SQL provides sophisticated language constructs to program procedures and functions as stand-alone PL/SQL blocks. They can be called from other PL/SQL blocks, other procedures and functions. The syntax for a procedure definition iscreate [or replace] procedure <procedure name> [(<list of parameters>)] is<declarations>begin<sequence of statements>[exception<exception handling routines>]end [<procedure name>];The optional clause or replace re-creates the procedure/function. Valid parameters include all data types. However, for char, varchar2, and number no length and scale, respectively, can be specified. For example, the parameter number(6) results in a compile error and must be replaced by number.Constants, variables, cursors, and exceptions used in a PL/SQL block must be declared in the declare section of that block. Variables and constants can be declared as follows:<variable name> [constant] <data type> [not null] [:= <expression>];A PL/SQL block may contain statements that specify exception handling routines. Each error or warning during the execution of a PL/SQL block raises an exception. One can distinguish between two types of exceptions:• system defined exceptions• user defined exceptions (which must be declared by the user in the declaration part of a block where the exception is used/implemented)System defined exceptions are always automatically raised whenever corresponding errors or warnings occur. User defined exceptions, in contrast, must be raised explicitly in a sequence of statements using raise <exception name>. After the keyword exception at the end of a block, user defined exception handling routines are implemented. An implementation has the patternwhen <exception name> then <sequence of statements>;The most common errors that can occur during the execution of PL/SQL programs are handled by system defined exceptions. The table below lists some of these exceptions with their names and a short description.SQL> create table stud(rno number(2),mark1 number(3),mark2 number(3),total number(3),primary key(rno));

Table created.

SQL> desc stud; Name Null? Type ----------------------------------------- -------- ---------------------------- RNO NOT NULL NUMBER(2) MARK1 NUMBER(3) MARK2 NUMBER(3) TOTAL NUMBER(3)

22

Page 23: Dbms-LM Kavi With Minipjt

ACTCET-CSE

SQL> select * from stud;

RNO MARK1 MARK2 TOTAL---------- ---------- ---------- ---------- 1 80 85 0 2 75 84 0 3 65 80 0 4 90 85 0

SQL> create or replace procedure studd(rnum number) is 2 m1 number; 3 m2 number; 4 total number; 5 begin 6 select mark1,mark2 into m1,m2 from stud where rno=rnum; 7 if m1<m2 then 8 update stud set total=m1+m2 where rno=rnum; 9 end if; 10 end; 11 /

Procedure created.

SQL> exec studd(1);

PL/SQL procedure successfully completed.

SQL> select * from stud;

RNO MARK1 MARK2 TOTAL ---------- ---------- ---------- ---------- 1 80 85 165 2 75 84 0 3 65 80 0 4 90 85 0

SQL> exec studd(4);

PL/SQL procedure successfully completed.

SQL> select * from stud;

RNO MARK1 MARK2 TOTAL ---------- ---------- ---------- ---------- 1 80 85 165 2 75 84 0 3 65 80 0

23

Page 24: Dbms-LM Kavi With Minipjt

ACTCET-CSE 4 90 85 0

SQL> exec studd(2);PL/SQL procedure successfully completed.

SQL> exec studd(3);

PL/SQL procedure successfully completed.

SQL> select * from stud;

RNO MARK1 MARK2 TOTAL ---------- ---------- ---------- ---------- 1 80 85 165 2 75 84 159 3 65 80 145 4 90 85 0

Result:

Thus the procedure using PL/ SQL have been done.

24

Page 25: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:5c PL/SQL FUNCTIONSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :To write function in PL/SQL.

Procedure:

Write the following pl/sql program in oracle editorSave it as cube..sqlRun it in sql prompt as SQL> @cube.sql

PL/SQL PROGRAMS- FUNCTIONS

CUBE

create or replace function cube(n number) return numberasc number;beginc:=n*n*n;return c;end;

output:-SQL> @cub /

Function created.

SQL> select cube(6)from dual;

CUBE(6) ------ 216

Result:

Thus the Function using PL/SQL have been run.

25

Page 26: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:5d.i SINGLE ROW FUNCTIONSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :

To know the following functions Character Functions Number Functions Date Functions

Syntax & Description :In order to compare an attribute with a string, it is required to surround the string by apostrophes,

e.g., where LOCATION = ’DALLAS’. A powerful operator for pattern matching is the like operator. Together with this operator, two special characters are used: the percent sign % (also called wild card), and the underline , also called position marker. For example, if one is interested in all tuples of the table DEPT that contain two C in the name of the department, the condition would be where DNAME like ’%C%C%’. The percent sign means that any (sub)string is allowed there, even the empty string. In contrast, the underline stands for exactly one character. Thus the condition where DNAME like ’%C C%’ would require that exactly one character appears between the two Cs. To test for inequality, the not clause is used.Further string operations are:• upper(<string>) takes a string and converts any letters in it to uppercase, • lower(<string>) converts any letter to lowercase,• length(<string>) returns the length of the string.• substr(<string>, n [, m]) clips out a m character piece of <string>, starting at positionn. If m is not specified, the end of the string is assumed.substr(’DATABASE SYSTEMS’, 10, 7) returns the string ’SYSTEMS’.The concatenation operator “||” can be used to concatenate single strings to one string.SQL> DESC EMPLOYEE22; Name Null? Type ----------------------------------------- -------- ----------------------- ENO NOT NULL NUMBER(5) ENAME VARCHAR2(50) DEPTID NUMBER(3) SALARY NUMBER(7) JOB VARCHAR2(5) MGRID NUMBER(3) COM VARCHAR2(6)

SQL> select * from employee22;

ENO ENAME DEPTID---------- -------------------------------------------------- ---------- SALARY JOB MGRID COM---------- ----- ---------- ----------------------------------- 1 x 10 100000 MD 0 15

2 y 20 50000 Mgr 1 10

26

Page 27: Dbms-LM Kavi With Minipjt

ACTCET-CSE

3 z 20 25000 Mgr 2 2

ENO ENAME DEPTID---------- -------------------------------------------------- ---------- SALARY JOB MGRID COM---------- ----- ---------- -------------------------------------------- 4 a 30 15000 Mgr 2 1

5 b 40 10000 Emp 3 5

SQL> select * from employee22 where LOWER(ename)='x';

ENO ENAME DEPTID---------- -------------------------------------------------- -------------------------- SALARY JOB MGRID COM---------- ----- ---------- ---------------------------------------------------- 1 X 10 100000 MD 0 15

SQL> select * from employee22 where UPPER(ename)='y';

no rows selected

SQL> select * from employee22 where UPPER(ename)='Y';

ENO ENAME DEPTID---------- -------------------------------------------------- ---------- SALARY JOB MGRID COM---------- ----- ---------- ---------------------------------------------- 2 y 20 50000 Mgr 1 10

SQL> select 'Salary of ' || ename || ' is ' || salary from employee22;

'SALARYOF'||ENAME||'IS'||SALARY--------------------------------------------------------------------------Salary of X is 100000Salary of y is 50000Salary of z is 25000Salary of a is 15000Salary of b is 10000

27

Page 28: Dbms-LM Kavi With Minipjt

ACTCET-CSE

SQL> select * from employee22 where LOWER(ename)='x';

ENO ENAME DEPTID---------- -------------------------------------------------- ---------- SALARY JOB MGRID COM---------- ----- ---------- ------------------------------------------------- 1 X 10 100000 MD 0 15

SQL> select * from employee22 where UPPER(ename)='y';no rows selected

SQL> select * from employee22 where UPPER(ename)='Y';

ENO ENAME DEPTID---------- -------------------------------------------------- ------------------------- SALARY JOB MGRID COM---------- ----- ---------- ----------------------------------------------------------- 2 y 20 50000 Mgr 1 10

SQL> select 'Salary of ' || ename || ' is ' || salary from employee22;

'SALARYOF'||ENAME||'IS'||SALARY--------------------------------------------------------------------------------Salary of X is 100000Salary of y is 50000Salary of z is 25000Salary of a is 15000Salary of b is 10000

SQL> create table sample(name varchar2(30),fname varchar2(10),lname varchar2(10));

Table created.

SQL> desc sample Name Null? Type ----------------------------------------- -------- ---------------------------- NAME VARCHAR2(30) FNAME VARCHAR2(10) LNAME VARCHAR2(10)

SQL> alter table sample add(fno float(10));

Table altered.

SQL> desc sample28

Page 29: Dbms-LM Kavi With Minipjt

ACTCET-CSE Name Null? Type ----------------------------------------- -------- ---------------------------- NAME VARCHAR2(30) FNAME VARCHAR2(10) LNAME VARCHAR2(10) FNO FLOAT(10)

SQL> insert into sample values('Hello world','Lovelyn','Divya',120.856);

1 row created.

SQL> insert into sample values('Welcome everyone','Dhivyaa','Meens',340.15);

1 row created.

SQL> insert into sample values('Hi everybody','Harsha','Innanji',280.59);

1 row created.

SQL> select * from sample;

NAME FNAME LNAME FNO------------------------------ ---------- ---------- -------------------------------Hello world Lovelyn Divya 120.9Welcome everyone Dhivyaa Meens 340.2Hi everybody Harsha Innanji 280.6 SQL> select concat(fname,lname),fno from sample;

CONCAT(FNAME,LNAME) FNO-------------------- ---------------------------------LovelynDivya 120.9DhivyaaMeens 340.2HarshaInnanji 280.6

SQL> select upper(name) from sample;

UPPER(NAME)------------------------------HELLO WORLDWELCOME EVERYONEHI EVERYBODY

SQL> select lower(lname) from sample;

LOWER(LNAME)----------divya

29

Page 30: Dbms-LM Kavi With Minipjt

ACTCET-CSEmeensinnanji

SQL> select substr(fname,1,5) from sample;

SUBST-------------LovelDhivyHarsh

SQL> select length(name) from sample;

LENGTH(NAME)------------------------- 11 16 12

SQL> select length(lname) from sample;

LENGTH(LNAME)------------- 5 5 7

SQL> select name,instr(name,1) from sample;

NAME INSTR(NAME,1)------------------------------ ----------------------Hello world 0Welcome everyone 0Hi everybody 0

SQL> select name,instr(name,'e',1) from sample;

NAME INSTR(NAME,'E',1)------------------------------ -----------------Hello world 2Welcome everyone 2Hi everybody 4

SQL> select fname,instr(fname,'a') from sample;

FNAME INSTR(FNAME,'A')---------- -----------------------------------Lovelyn 0Dhivyaa 6

30

Page 31: Dbms-LM Kavi With Minipjt

ACTCET-CSEHarsha 2

SQL> select lpad(lname,10,'*') from sample;

LPAD(LNAME)------------------*****Divya*****Meens***Innanji

SQL> select rpad(fname,10,'*')from sample;

RPAD(FNAME)----------Lovelyn***Dhivyaa***Harsha****

SQL> select trim('d' from 'dhivyaa')from sample;

TRIM('------hivyaahivyaahivyaa

SQL> select trim('d' from 'dhivyaa')from sample where fno=340.2;

TRIM('------hivyaa

SQL> select trim('a' from fname)from sample;

TRIM('A'FR----------LovelynDhivyHarsh

NUMBER FUNCTIONS:

SQL> select ROUND(45.923,2),ROUND(45.923,0),ROUND(45.923,-1) from DUAL;

ROUND(45.923,2) ROUND(45.923,0) ROUND(45.923,-1)--------------- --------------- ---------------------------------------------------------- 45.92 46 50

31

Page 32: Dbms-LM Kavi With Minipjt

ACTCET-CSE

SQL> select trunc(45.923,2),trunc(45.923),trunc(45.923,-2) from DUAL;

TRUNC(45.923,2) TRUNC(45.923) TRUNC(45.923,-2)--------------- ------------- ------------------------------------------------------- 45.92 45 0

SQL> desc sample Name Null? Type ----------------------------------------- -------- ---------------------------- NAME VARCHAR2(30) FNAME VARCHAR2(10) LNAME VARCHAR2(10) FNO FLOAT(10) HIREDATE DATE

SQL> insert into sample values('REC CSE','Anitha','Anu',320.7,'21-mar-88');

1 row created.

SQL> insert into sample values('Hi chennai','aishwarya','sukumar',170,'30-oct-87');

1 row created.

SQL> select * from sample;

NAME FNAME LNAME FNO HIREDATE------------------------------ ---------- ---------- ---------- -------------------------------------Hello world Lovelyn Divya 120.9Welcome everyone Dhivyaa Meens 340.2Hi everybody Harsha Innanji 280.6REC CSE Anitha Anu 320.7 21-MAR-88Hi chennai aishwarya sukumar 170 30-OCT-87

SQL> select lname,hiredate from sample where lname like 'a%';

no rows selected

SQL> select lname,hiredate from sample where lname like 'A%';

LNAME HIREDATE---------- ---------------------------Anu 21-MAR-88

SQL> select sysdate from DUAL;

32

Page 33: Dbms-LM Kavi With Minipjt

ACTCET-CSESYSDATE-----------------22-AUG-07

SQL> select fname,(sysdate-hiredate)/7 as weeks from sample where fno=170;

FNAME WEEKS---------- ----------aishwarya 1033.78013

SQL> select fname,hiredate,months_between(sysdate,hiredate) from sample where fno=320.7;

FNAME HIREDATE MONTHS_BETWEEN(SYSDATE,HIREDATE)---------- --------- -----------------------------------------------------------------------Anitha 21-MAR-88 233.047329

SQL> select fname,hiredate,add_months(hiredate,6),next_day(hiredate,'friday'),last_day(hiredate) from sample;

FNAME HIREDATE ADD_MONTH NEXT_DAY( LAST_DAY(---------- --------- --------- --------- ---------------------------------------------------LovelynDhivyaaHarshaAnitha 21-MAR-88 21-SEP-88 25-MAR-88 31-MAR-88aishwarya 30-OCT-87 30-APR-88 06-NOV-87 31-OCT-87

SQL> select fname ,hiredate,round(hiredate,'Month'),trunc(hiredate,'month') from sample where fno=170;

FNAME HIREDATE ROUND(HIR TRUNC(HIR---------- --------- --------- -----------------------------------------aishwarya 30-OCT-87 01-NOV-87 01-OCT-87

Result:

Thus the built in single row functions using SQL have been done.

33

Page 34: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:5d.ii MULTIROW FUNCTIONSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :

To know about the following multi row functions Order By Group By Aggregate Functions

Syntax & DescriptionIt is also possible to specify a sorting order in which the result tuples of a query are displayed. For this the order by clause is used and which has one or more attributes listed in the select clause as parameter. desc specifies a descending order and asc specifies an ascending orderselect [distinct] <column(s)>from <table>[ where <condition> ][ order by <column(s) [asc|desc]> ]Often applications require grouping rows that have certain properties and then applying an aggregate function on one column for each group separately. For this, SQL provides the clause group by <group column(s)>. This clause appears after the where clause and must refer to columns of tables listed in the from clause.select <column(s)>from <table(s)>where <condition>group by <group column(s)>[having <group condition(s)>];Those rows retrieved by the selected clause that have the same value(s) for <group column(s)> are grouped. Aggregations specified in the select clause are then applied to each group separately.It is important that only those columns that appear in the <group column(s)> clause can be listed without an aggregate function in the select clause !Aggregate functions are statistical functions such as count, min, max etc. They are used to compute a single value from a set of attribute values of a column: count Counting RowsExample: How many tuples are stored in the relation EMP?select count(_) from EMP;Example: How many different job titles are stored in the relation EMP?select count(distinct JOB) from EMP;max Maximum value for a columnmin Minimum value for a columnExample: List the minimum and maximum salary.select min(SAL), max(SAL) from EMP;Example: Compute the difference between the minimum and maximum salary.select max(SAL) - min(SAL) from EMP;sum Computes the sum of values (only applicable to the data type number)Example: Sum of all salaries of employees working in the department 30.select sum(SAL) from EMPwhere DEPTNO = 30;avg Computes average value for a column (only applicable to the data type number)

34

Page 35: Dbms-LM Kavi With Minipjt

ACTCET-CSESQL> select * from cust;

CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- -------------------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Chamundi 3 Salem 1111 fd 36200Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000Jayashree 6 Pondy 1006 fd 15000Sridharan 7 Kanchi 1007 fd 22000

ORDER BY========SQL> select cname from cust order by cname desc;

CNAME---------------SubhaSridharanShriramMadhanJayashreeChamundiAnusha7 rows selected.SQL> select cname,caccno,cbalance from cust order by cbalance desc,cname asc;

CNAME CACCNO CBALANCE--------------- ---------- --------------------------Chamundi 1003 36200Shriram 1002 25000Sridharan 1007 22000Anusha 1001 15000Jayashree 1006 15000Subha 1005 10000Madhan 1004 50007 rows selected.

GROUP BY=========

SQL> select max(cbalance),cacctype from cust group by cacctype;

MAX(CBALANCE) CACCTYPE------------- ---------- 25000 savings 10000 checkings 36200 fd

35

Page 36: Dbms-LM Kavi With Minipjt

ACTCET-CSE

AGGREGATE FUNCTIONS=======================

SQL> select count(*) from cust;

COUNT(*) ---------- 7

SQL> select count(distinct cname) from cust;

COUNT(CNAME)------------ 7SQL>select sum(cbalance) as totbal,avg(sum(cbalance)) as average from cust where cacctype='savings';

TOTBAL AVERAGE-----------------------------

40000 20000

SQL> select max(cbalance),min(cbalance) from cust; MAX(CBALANCE) MIN(CBALANCE)----------------------------------------------------- 36200 5000

Result:

Thus the built in multi row functions using SQL have been done.

36

Page 37: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:6 FRONT END TOOLSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim:

To know the uses of Front end tools.

List of Front End Tools:-

PICTURE: This control is used to display images are set with the picture property. The picture box control supports of number of methods for generating drawings

LABEL: This control display text on a form that user can’t edit labels commonly identify other controls and can be transparent so that text appears to be placed directly on the form your can set the label is text with the cap from property.

TEXT BOX: This control display text that the user can edit we can set the text during the program and password property allows to hide the entering text by using ‘*’delimiter.

FRAM: This control used to draw boxes on the form and to group other elements.

COMMAND BUTTON: This control looks like a button with gray color if in used to trigger any event while clicking it.

CHECK BOX: If present one or more choice that the user selects we can set is the value to the check box as/or 0’1’ represent checked status ‘0’ represent cleared status.

OPTION BUTTON (OR) RADIO BUTTON: Appeared in group user can chose only one of them. If the value is set by ‘tree’ then it is toggled and false otherwise.

COMBO BOX: If is similar like box but it contains a text edit field.

LIST BOX: Thus control used to list to more items user can scroll the list box to view it.

HOREGENTAL,VERTICAL SCROLL BOXES: By scrolling this control we car view lengthier item in the screen.

TIMER: To set the interval of an action.

FILE SYSTEM CONTROL:37

Page 38: Dbms-LM Kavi With Minipjt

ACTCET-CSE This control used to add files, folders ,directions to your screen.

DRIVE LIST BOX: This control used to display drop- down list.

SHAPE CONTROL: Used to draw graphical elements MSG boxes used to display the message .

DATA: Used to point-click access to the DB.

OLE: Used to link other object.

OUTPUT:

RESULT: Thus we study the basic front end tools successfully.

38

Page 39: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:7 FORMS CREATIONDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim:

To create forms using VB.

Procedure:STEP 1: Open a new standard project.STEP 2: Create new form STEP 3: Select Add_Ins - > Visual Data ManagerSTEP 4: Create new table using MS Access 7.0STEP 5: Build the table and add minimum 5 new recordsSTEP 6: Design form using labels, text boxes and frame.STEP 7: Insert data grid to display recordsSTEP 8: Assign the data base name, record source to data gird in its properties table.STEP 9: Assign data field values to the respective text boxes.STEP 10: Run the form.

Sample output:

Result: Thus the Form design done by using MS access and VB.

39

Page 40: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:8 TRIGGERSDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim :To use the triggersSyntax & DescriptionA trigger definition consists of the following (optional) components:• trigger namecreate [or replace] trigger <trigger name>• trigger time pointbefore | after• triggering event(s)insert or update [of <column(s)>] or delete on <table>• trigger type (optional)for each row• trigger restriction (only for for each row triggers !)when (<condition>)• trigger body<PL/SQL block>The clause replace re-creates a previous trigger definition having the same <trigger name>. The name of a trigger can be chosen arbitrarily, but it is a good programming style to use a trigger name that reflects the table and the event(s), e.g., upd ins EMP. A trigger can be invoked before or after the triggering event. The triggering event specifies before (after) which operations on the table <table> the trigger is executed. A single event is an insert, an update, or a delete; events can be combined using the logical connective or. If for an update trigger no columns are specified, the trigger is executed after (before) <table> is updated. If the trigger should only be executed when certain columns are updated, these columns must be specified after the event update. If a trigger is used to maintain an integrity constraint, the triggering events typically correspond to the operations that can violate the integrity constraint. In order to program triggers efficiently (and correctly) it is essential to understand the difference between a row level trigger and a statement level trigger. A row level trigger is defined using the clause for each row. If this clause is not given, the trigger is assumed to be a statement trigger. A row trigger executes once for each row after (before) the event. In contrast, a statement trigger is executed once after (before) the event, independent of how many rows are affected by the event. For example, a row trigger with the event specification after update is executed once for each row affected by the update. Thus, if the update affects 20 tuples, the trigger is executed 20 times, for each row at a time. In contrast, a statement trigger is only executed once. When combining the different types of triggers, there are twelve possible trigger that can be defined

BEFORE TRIGGERcreate or replace trigger tday before insert or delete or update on empdeclarewe varchar2(10);beginwe:=to_char(sysdate,'dy');if we='sat' or we='sun' thenraise_application_error(-20015,'its a weekend');end if;end;

40

Page 41: Dbms-LM Kavi With Minipjt

ACTCET-CSEoutput:-

SQL> @trig1 /

Trigger created.

SQL> delete from emp where empno=7902;

ERROR at line 1:ORA-20015: its a weekendORA-06512: at "SCOTT.TDAY", line 6ORA-04088: error during execution of trigger 'SCOTT.TDAY'AFTER TRIGGER

create or replace trigger ttime after insert or delete or update on emp1 for each rowdeclarett varchar2(5);begintt:=to_char(sysdate,'hh24');if tt not between 10 and 17 thenraise_application_error(-20010,'not working hours');end if;end;

output:-SQL> @trig2; 10 /

Trigger created.

SQL> update emp1 set empno=7777 where empno=7902;

*ERROR at line 1:ORA-20010: not working hours

RESULT: Thus the sample Trigger experiment successfully executed.

41

Page 42: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:9 MENU DESIGNDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim:

Design the menu for the text editor using visual basicProcedure:

Step1: Open STD Dxe VB projectStep2: Select tools menu->go to menu editor (ctrl+E)Step3: Create main menu for EditStep4: Create sub menu under edit menu that are Cut, Copy, PasteStep5: Create Exit main menu

Main Program:Copy:

Private Sub Form_copy ()Clipboard. ClearClipboard.SetText Text1.SelTextEnd Sub

Cut: Private Sub Cut_Click ()Clipboard.SetText Text1.SelTextText1.SelText = " "End Sub

Paste:Private Sub Paste_Click ()Text1.SelText = Clipboard.GetTextEnd Sub

SAMPLE OUTPUT:

RESULT: Thus the Menu Design experiment successfully executed.

42

Page 43: Dbms-LM Kavi With Minipjt

ACTCET-CSE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:10 REPORT GENERATIONDate:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Aim:

To generate report for a given database.

Procedure:STEP 1: open a new standard project.STEP 2: set up the data source.STEP 2a: open the project menu and select add data environment.STEP 2b: click on connection 1 and changes its name property.STEP 2c: right click on connection1 and select the data link property.STEP 2d: on the provider tab select Microsoft jet 3.51 ole database provider and click next.STEP 2c: on the connection tab, click on the builder button for dbname,

then click text connection button.Step 2f: right click on connection 1,select command and changes the properties.STEP 2g: for source of data ,drop down the list for db object and select table.STEP 3: design the report.STEP 3.1: open the project menu and select all data report.STEP 3.2: set the report properties.STEP 3.2a: drop down the list for the data source properties then change the data environment1.STEP 3.2b: set the data member property to command 1.STEP 3.3: close the report header selection.STEP 3.4: place a title in the page header section.STEP 3.5: place found controls in the details click on the field in the data environment window and drag a control on to the detail section of the report layout.STEP 4: save the report design.STEP 5: Design new form using command button with caption Generate ReportSTEP 6: Write the code.

Private Sub Command1_Click()DataReport1.ShowEnd Sub

STEP 7: Run the form

43

Page 44: Dbms-LM Kavi With Minipjt

ACTCET-CSE

Output:

RESULT: Thus the Report Generation experiment successfully executed.

44

Page 45: Dbms-LM Kavi With Minipjt

ACTCET-CSE

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EX. NO:11 SAMPLE MINI PROJECTDate: Student Data Base System~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Aim: To create “Student Data Base System” for an organization using VB, MS Access.

Procedure: Step 1: Open Standard exe VB form.Step 2: Goto Menu bar -> AddIns ->Visual Data Manager -> create MS Access 7.0 table named

Newtable with following fields regno, sname, m1…m5, total, avg, grade.Step 3: Create Index using regno.Step 4: Design form using Labels, Textboxes, command buttons, DAO controls as in the scree shot.Step 5: Type coding as in the code part.Step 6: Run the form

Abstract:In this system we propose student data base management system to generate student mark sheet

with grade for given marks.

System Requirements: PIII..V processor computer CPU, 17” Monitor, Mouse, 103 keyboardFront end: Visual Basic 6.0Back end: Ms Access 7.0

Modular diagram / List of modules:1. Admin login2. Student view3. Update table 4. Generate Report

Gantt Chart:

Date

Phase

13/0

3/20

12

20/0

3/20

12

27/0

3/20

12 29/0

3/20

12 03/0

4/20

12 04/0

4/20

12 10/0

4/20

12 16/0

4/20

12Phase 1 Select

mini

project

name,

write

abstract

Phase 2 Select

45

Page 46: Dbms-LM Kavi With Minipjt

ACTCET-CSEfront

end and

back

end

tools

Phase 3 Collect

dams

question

s

Phase 4 Add the

question

s into

database

Phase 5 Design

forms

Phase 6 Write

coding

Phase 7 Testing

the

project

Phase 8 Make

that as

docume

nt

46

Page 47: Dbms-LM Kavi With Minipjt

ACTCET-CSEDATA BASE DESIGN

Coding47

Page 48: Dbms-LM Kavi With Minipjt

ACTCET-CSE

Dim db As DatabaseDim rs As RecordsetDim rs1 As RecordsetDim ws As WorkspaceDim rno, i As IntegerDim stname As StringDim m1 As IntegerDim m2 As IntegerDim m3 As IntegerDim m4 As IntegerDim m5 As IntegerDim tot As IntegerDim ave As DoubleDim gra As StringDim op As String Dim L As Label Option Explicit

Private Sub Command1_Click()Text1(0).Text = ""Text1(1).Text = ""Text1(2).Text = ""Text1(3).Text = ""Text1(4).Text = ""Text1(5).Text = ""Text1(6).Text = ""Text1(7).Text = ""Text1(8).Text = ""Text1(9).Text = ""

MsgBox "ENTER NEW DATA"

End Sub

Private Sub Command10_Click()

With rs.AddNew!regno = Val(Text1(0).Text)!sname = Text1(1).Text!mark1 = Val(Text1(2).Text)!regno = Val(Text1(0).Text)

48

Page 49: Dbms-LM Kavi With Minipjt

ACTCET-CSE!sname = Text1(1).Text!mark1 = Val(Text1(2).Text)!mark2 = Val(Text1(3).Text)!mark3 = Val(Text1(4).Text)!mark4 = Val(Text1(5).Text)!mark5 = Val(Text1(6).Text)rno = Val(Text1(0).Text)stname = Text1(1).Textm1 = Val(Text1(2).Text)m2 = Val(Text1(3).Text)m3 = Val(Text1(4).Text)m4 = Val(Text1(5).Text)m5 = Val(Text1(6).Text)

tot = m1 + m2 + m3 + m4 + m5!total = totText1(7).Text = totText1(8).Text = tot / 5

If (!mark1 > 50) And (!mark2 > 50) And (!mark3 > 50) And (!mark4 > 50) And (!mark5 > 50) ThenText1(9).Text = "S"ElseText1(9).Text = "u"End If!total = !mark1 + !mark2 + !mark3 + !mark4 + !mark5!Avg = !total / 5!grade = Text1(9).TextText1(7).Text = !total Text1(8).Text = !Avg Text1(9).Text = !grade.UpdateMsgBox ("record added")End With

End Sub

Private Sub Command2_Click()Set rs1 = db.OpenRecordset("newtable", dbOpenDynaset)op = MsgBox("r u sure to delete?", vbYesNo)MsgBox ("option " = op)'If op = "False" Thenrs1.Delete

Text1(0).Text = ""Text1(1).Text = ""Text1(2).Text = ""Text1(3).Text = ""Text1(4).Text = ""Text1(5).Text = ""

49

Page 50: Dbms-LM Kavi With Minipjt

ACTCET-CSEText1(6).Text = ""Text1(7).Text = ""Text1(8).Text = ""Text1(9).Text = ""MsgBox ("record deleted")'rs1.Update'End Ifrs1.MoveNext'rs1.EditWith rs1

Text1(0).Text = !regnoText1(1).Text = !snameText1(2).Text = !mark1Text1(3).Text = !mark2Text1(4).Text = !mark3Text1(5).Text = !mark4Text1(6).Text = !mark5Text1(7).Text = !totalText1(8).Text = !AvgText1(9).Text = !gradeEnd With

End Sub

Private Sub Command3_Click()Set rs1 = db.OpenRecordset("newtable", dbOpenDynaset)With rs1.Edit!regno = Val(Text1(0).Text)!sname = Text1(1).Text!mark1 = Val(Text1(2).Text)!regno = Val(Text1(0).Text)!sname = Text1(1).Text!mark1 = Val(Text1(2).Text)!mark2 = Val(Text1(3).Text)!mark3 = Val(Text1(4).Text)!mark4 = Val(Text1(5).Text)!mark5 = Val(Text1(6).Text)!total = Val(Text1(7).Text)!Avg = Val(Text1(8).Text)!grade = Text1(9).Text

.Update End WithEnd Sub

Private Sub Command4_Click()50

Page 51: Dbms-LM Kavi With Minipjt

ACTCET-CSESet rs1 = db.OpenRecordset("newtable", dbOpenDynaset)With rs1.MovePreviousIf .BOF ThenMsgBox ("this is first record")EndElseText1(0).Text = !regnoText1(1).Text = !snameText1(2).Text = !mark1Text1(3).Text = !mark2Text1(4).Text = !mark3Text1(5).Text = !mark4Text1(6).Text = !mark5Text1(7).Text = !totalText1(8).Text = !AvgText1(9).Text = !gradeEnd IfEnd With

End Sub

Private Sub Command5_Click()Set rs1 = db.OpenRecordset("newtable", dbOpenDynaset)With rs1.MoveNextIf .EOF ThenMsgBox ("this is last record")EndElseText1(0).Text = !regnoText1(1).Text = !snameText1(2).Text = !mark1Text1(3).Text = !mark2Text1(4).Text = !mark3Text1(5).Text = !mark4Text1(6).Text = !mark5Text1(7).Text = !totalText1(8).Text = !AvgText1(9).Text = !gradeEnd IfEnd WithEnd Sub

Private Sub Command6_Click()Set rs1 = db.OpenRecordset("newtable", dbOpenDynaset)With rs1.MoveFirst

51

Page 52: Dbms-LM Kavi With Minipjt

ACTCET-CSEText1(0).Text = !regnoText1(1).Text = !snameText1(2).Text = !mark1Text1(3).Text = !mark2Text1(4).Text = !mark3Text1(5).Text = !mark4Text1(6).Text = !mark5Text1(7).Text = !totalText1(8).Text = !AvgText1(9).Text = !gradeEnd With

End Sub

Private Sub Command7_Click()Set rs1 = db.OpenRecordset("newtable", dbOpenDynaset)With rs1.MoveLast'For i = 1 To 9'Text1(i).Text = ""Text1(0).Text = !regnoText1(1).Text = !snameText1(2).Text = !mark1Text1(3).Text = !mark2Text1(4).Text = !mark3Text1(5).Text = !mark4Text1(6).Text = !mark5Text1(7).Text = !totalText1(8).Text = !AvgText1(9).Text = !gradeEnd WithEnd Sub

Private Sub Command8_Click()EndForm1.HideEnd Sub

Private Sub Command9_Click()Set rs1 = db.OpenRecordset("newtable", dbOpenDynaset)With rs1.EditIf (!mark1 > 50) And (!mark2 > 50) And (!mark3 > 50) And (!mark4 > 50) And (!mark5 > 50) ThenText1(9).Text = "S"ElseText1(9).Text = "u"End If!total = !mark1 + !mark2 + !mark3 + !mark4 + !mark5

52

Page 53: Dbms-LM Kavi With Minipjt

ACTCET-CSE!Avg = !total / 5!grade = Text1(9).TextText1(7).Text = !total Text1(8).Text = !Avg Text1(9).Text = !grade.Update.MoveNextEnd WithMsgBox ("Grade shown")End Sub

Private Sub Form_Load()Set ws = DBEngine.Workspaces(0)Set db = ws.OpenDatabase("D:\dbms minipjt\kavidb.mdb")Set rs = db.OpenRecordset("newtable", dbOpenDynaset)End Sub

Screen shots Sample output

To Add new record

53

Page 54: Dbms-LM Kavi With Minipjt

ACTCET-CSE

Go first.

54

Page 55: Dbms-LM Kavi With Minipjt

ACTCET-CSE

Go last.

To delete record

55

Page 56: Dbms-LM Kavi With Minipjt

ACTCET-CSE

Result:Thus the “Student Data Base System” has been demonstrated using VB, MS Access.

56