Académique Documents
Professionnel Documents
Culture Documents
Prepared by,
J.SUBA.,M.E.
Subject Code
Subject
Theory
MA1252
CS1254
EC1257
CS1252
CS1253
Operating Systems
IT1251
CS1256
CS1255
EC1258
Microprocessors Laboratory
LIST OF EXPERIMENTS
INDEX
S.NO
LIST OF EXPERIMENTS
VIEWS
FORMS
TRIGGERS
MENU DESIGN
10
REPORTS
PAGE NO
Ex No 1
DATA DEFINITION LANGUAGE, TABLE CREATION, CONSTRAINTS
AIM:
To execute the Data Definition Language (DDL) commands and creating the table with constraints
using RDBMS.
Data Definition Language
DDL(Data Definition Language) statements are used to create, delete, or change the objects of a database.
Typically a database administrator is responsible for using DDL statements or production databases in a
large database system. The commands used are:
Create - It is used to create a table.
Alter - This command is used to add a new column, modify the existing column definition and to
include or drop integrity constraint.
Drop - It will delete the table structure provided the table should be empty.
Truncate - If there is no further use of records stored in a table and the structure has to be retained,
then the records alone can be deleted.
Desc - This is used to view the structure of the table.
Table Creation
Rules:
Reserved words cannot be used.
Underscore, numerals, letters are allowed but not blank space.
Maximum length for the table name is 30 characters.
2 different tables should not have same name.
We should specify a unique column name.
We should specify proper data type along with width.
We can include not null condition when needed. By default it is null.
Syntax
create table <table name>
{
fieldname-1 datatype constraints if any,
fieldname-2 datatype constraints if any,
.
fieldname-n datatype constraints if any,
};
create table <table name> as
(
select(att-list) from <existing table name>
);
ALTER TABLE - syntax
alter table <table name> add/modify
(
fieldname-1 datatype,
fieldname-2 datatype,
..
fieldname-n datatype
);
alter table drop column column name;
Table altered.
DESCRIBING TABLE
Desc <tablename>;
2.
3.
'14-feb-2010')
insert into order_master values('o001','11-nov-2008','v002','p',
'14-feb-2010')
*
ERROR at line 1:
ORA-00001: unique constraint (USER06.ORDER_PRIM) violated
SQL> /
Enter value for oredrno: o002
Enter value for odate: 13-jan-2007
Enter value for vencode: v002
Enter value for o_status: p
Enter value for deldate: 16-oct-2009
old 1: insert into order_master values('&oredrno','&odate','&vencode',
'&o_status','&deldate')
new 1: insert into order_master values('o002','13-jan-2007','v002','p',
'16-oct-2009')
1 row created.
SQL> select * from order_master;
ORDER ODATE VENCO O DELDATE
----- --------- ----- - --------o001 11-NOV-08 voo2 p 14-FEB-10
o002 13-JAN-07 v002 p 16-OCT-09
o001 i01
25
RESULT:
Thus the Data Definition Language (DDL) and Data Control Language (DCL) commands in
RDBMS were executed and verified.
EX.NO:2
AIM:
To execute the Data Manipulation Language (DML) and Data Control Language (DCL) commands in
RDBMS.
Data Manipulation Language
DML commands are the most frequently used SQL commands and is used to query and manipulate the
existing database objects. Some of the commands are
1. Insert
2. Select
3. Update
4. Delete
Syntax :
INSERT: This is used to add one or more rows to a table. The values are separated by commas and
the data types char and date are enclosed in apostrophes. The values must br entered in the same order as
they are defined.
Inserting a single row into a table:
insert into <table name> values(fieldvalue-1,fieldvalue-2,,fieldvalue-n);
Inserting more than one record using a single insert command:
insert into <table name> values(&fieldname-1,&fieldname-2,&fieldname-n);
Skipping the fields while inserting:
insert into <tablename(coln names to which datas to b inserted)> values (list of values);
Other way is to give null while passing the values.
insert into <table name>(select(att_list) from <existing table name>);
SELECT: - It is used to retrieve information from the table.it is generally refered to as querying the
table. We can either display all columns in a table or only specify column from the table.
SELECT(att_list) FROM <table name> [WHERE <condition/expression>];
Retrieval of all columns from a table:
Select * from tablename; // This query selects all rows from the table.
Retrieval of specific columns from a table:It retrieves the specified columns from the table.
Syntax: Select column_name1, ..,column_namen from table name;
Elimination of duplicates from the select clause: It prevents retriving the duplicated values .Distinct
keyword is to be used.
Syntax: Select DISTINCT col1, col2 from table name;
Select command with where clause: To select specific rows from a table we include where clause in
the select command. It can appear only after the from clause.
TRANSACTION CONTROL
The DML language statements Insert, Delete, Update are affected i.e., written in the database
unless the user specially says so. The command for this is
SQL> commit;
Commit complete.
This will commit (write to database) the transactions done by the DML.
After inserting, updating or deleting the transactions the user does not want to commit the changes, then
the user can rollback the transaction using the command:
SQL> rollback;
Rollback complete.
It will rollback the transaction and will not commit the changes to the database.
SQL> savepoint s1;
Savepoint s1 created.
It will save the transactions under the name s1.
DATA CONTROL LANGUAGE:
Data control language provides users with privilege commands.
GRANT - Used to give privilege to user on object
Grant privilege on <object_name> to <user name>;
e.g) grant write on employee to user01;
REVOKE - Used to withdraw the privilege that has been granted to the user.
Revoke privilege on <object_name> from <user name>;
e.g) revoke write on employee from user01;
Sample Output
INSERT, SELECT, UPDATE AND DELETE COMMANDS
SQL> create table person(pid int, lastname varchar2(10),firstname varchar(10),
address varchar2(20),age number);
Table created.
INSERTING A SINGLE ROW INTO A TABLE
SQL> insert into person values(1,'Prettina','Anne','Bangalore',14);
1 row created.
SQL> insert into person values(2,'Benitto','Anish','Trichy',24);
1 row created.
SQL> select * from person;
PID
LASTNAME
FIRSTNAME
ADDRESS
---------- ---------- ---------- -------------------- ---------1
Prettina
Anne
Bangalore
14
2
Benitto
Anish
Trichy
24
AGE
AGE
3 Raj
4 kumar
Anita
Ashok
Chennai
Coimbatore
27
30
AGE
AGE
6 rows selected.
UPDATE VALUES USING CONDITION
SQL> update person set address='United States'where pid=5;
1 row updated.
UPDATE VALUES USING &
SQL> update person set address ='&address',age=&age where pid=&pid;
AGE
AGE
PID
LASTNAME
FIRSTNAME ADDRESS
---------- ---------- ---------- -------------------- ---------3
Raj
Anita
Chennai
27
4
kumar
Ashok
Coimbatore 30
AGE
AGE
AGE
AGE
PID
FIRSTNAME AGE
---------- ---------- ---------1
Anne
14
2
Anish
24
3
Anita
27
4
Ashok
30
6
Bhaskar 40
7
Chander 45
5
Benny
55
7 rows selected.
SELECT COMMAND TO CREATE A TABLE
SQL> create table individual as select * from person;
Table created.
SQL> select * from individual;
PID
LASTNAME FIRSTNAME ADDRESS
---------- ---------- ---------- ------------ -------1
Prettina Anne
Bangalore
14
2
Benitto Anish
Trichy
24
3
Raj
Anita
Chennai
27
4
Kumar
Ashok
Coimbatore 30
5
Hinn
Benny
Britain
55
6
Prakash Bhaskar Assam
40
7
Kumar
Chander Coimbatore 45
AGE
7 rows selected.
SELECT COMMAND TO INSERT RECORDS
SQL> insert into individual(select * from person);
7 rows created.
SELECT COMMAND WITH FUNCTIONS
SQL> select count(*) as pid from person;
PID
---------7
SQL> select count(distinct lastname) as pid from person;
PID
---------6
SQL> select max(age) from person;
MAX(AGE)
----------
55
SQL> select min(age) from person;
MIN(AGE)
---------14
SQL> select sum(age) from person;
SUM(AGE)
---------235
DATA CONTROL LANGUAGE (DCL) COMMANDS
SQL> select * from person;
PID LASTNAME FIRSTNAME ADDRESS
------- ---------- ---------- ------------ -------1
Prettina Anne
BAngalore
14
2
Benitto Anish
Trichy
24
3
Raj
Anita
Chennai
27
4
Kumar
Ashok
Coimbatore 30
5
Hinn
Benny
Britain
55
6 Prakash Bhaskar Assam
40
7 Kumar
Chander Coimbatore 45
AGE
7 rows selected.
SQL> commit;
Commit complete.
DELETE COMMAND
SQL> delete from person where lastname='Kumar';
2 rows deleted.
SQL> select * from person;
PID LASTNAME FIRSTNAME ADDRESS
------ ---------- ---------- ------------ -------1
Prettina Anne
BAngalore
14
2
Benitto Anish
Trichy
24
3
Raj
Anita
Chennai
27
5
Hinn
Benny
Britain
55
6 Prakash Bhaskar Assam
40
SQL> rollback;
Rollback complete.
AGE
AGE
7 rows selected.
SQL> savepoint s1;
Savepoint created.
SQL> delete from person;
7 rows deleted.
SQL> select * from person;
no rows selected
SQL> rollback to savepoint s1;
Rollback complete.
SQL> select * from person;
PID LASTNAME FIRSTNAME ADDRESS
------ ---------- ---------- ------------- ------1
Prettina Anne
BAngalore
14
2
Benitto Anish
Trichy
24
3
Raj
Anita
Chennai
27
4
Kumar
Ashok
Coimbatore
30
5
Hinn
Benny
Britain
55
6
Prakash Bhaskar Assam
40
7
Kumar
Chander Coimbatore
45
AGE
7 rows selected.
RESULT:
Thus the Data Manipulation Language (DML) and Data Control Language (DCL) commands in
RDBMS were executed and verified.
EX.NO:3
AIM:
To execute nested queries and join commands in SQL.
NESTED QUERIES :
A subquery is a query within a query. In Oracle, you can create subqueries within your SQL statements.
These subqueries can reside in the WHERE clause, the FROM clause, or the SELECT clause.
JOINS:
Join is a query in which data is returned from two or more tables.
How the join will be performed:
Step 1: Make the Cartesian product of the given tables.
Step 2: Check for the equality on common attributes for the given tables.
Natural join:
It returns the matching rows from the table that are being joined.
Syntax:
>select <attribute> from TN where TN1.attribute=TN2.attribute.
Inner join:
It returns the matching rows from the table that are being joined.
Syntax:
>select <attribute> from TN1 innerjoin TN2 on TN1.attribute=TN2.attribute.
Left outer join:
It returns all the rows from the table1 even when they are unmatched.
Syntax:
5. select <attribute> from TN1 left outer join TN2 on TN1.attribute=TN2.attribute.
2. select <attribute> from TN where TN1.attribute(+)=TN2.attribute.
Right outer join:
It returns all the rows from the table2 even when they are unmatched.
Syntax:
4. select <attribute> from TN1 right outer join TN2 on TN1.attribute=TN2.attribute.
2. select <attribute> from TN where TN1.attribute=(+)TN2.attribute.
Full join:
It is the combination of both left outer and right outer join.
Syntax:
>select <attribute> from TN1 full join TN2 on TN1.attribute=TN2.attribute.
Sample Output
NESTED QUERIES - Table Creation
SQL> create table emp_det(eno number(3) not null, ename varchar2(25),
address varchar2(30),
basic_sal number(12,2),job_status varchar2(15),dno number(3));
Table created.
SQL> create table pro_det(pno number(3) not null,pname varchar2(30),
no_of_staff number(3));
Table created.
SQL> /
Enter value for eno: 3
Enter value for ename:Rajkumar
Enter value for address: EastCoastRoad
Enter value for basic_sal: 10000
Enter value for job_status: Professor
Enter value for dno: 2
old 1: insert into emp_det values(&eno,'&ename','&address',&basic_sal,
'&job_status',&dno)
new 1: insert into emp_det values(3,'RajKumar','EastCoastRoad',10000,
'Professor',2)
1 row created.
SQL> /
Enter value for eno: 4
Enter value for ename: Shirley
Enter value for address: KKnagar
Enter value for basic_sal: 8000
Enter value for job_status: AsstManager
Enter value for dno: 3
old 1: insert into emp_det values(&eno,'&ename','&address',&basic_sal,
'&job_status',&dno)
new 1: insert into emp_det values(4,'Shirley','KKnagar',8000,
'AsstManager',3)
1 row created.
SQL> alter table emp_det modify(ename varchar2(15), address varchar2(15));
Table altered.
SQL> select * from emp_det;
ENO ENAME
ADDRESS
BASIC_SAL JOB_STATUS
---------- --------------- --------------- ---------- --------------- ---------1 SaravanaKumar GandhiNagar
8000 Manager
10
2 Mahendran
RainbowColony
5000 Supervisor
10
3 RajKumar
EastCoastRoad
10000 Professor
2
4 Shirley
KKnagar
8000 AsstManager
3
SQL> insert into pro_det values(&pno,'pname',&no_of_staff);
Enter value for pno: 1
Enter value for no_of_staff: 2
old 1: insert into pro_det values(&pno,'pname',&no_of_staff)
new 1: insert into pro_det values(1,'pname',2)
1 row created.
SQL> /
Enter value for pno: 2
Enter value for no_of_staff: 3
old 1: insert into pro_det values(&pno,'pname',&no_of_staff)
new 1: insert into pro_det values(2,'pname',3)
DNO
1 row created.
SQL> /
Enter value for pno: 3
Enter value for no_of_staff: 1
old 1: insert into pro_det values(&pno,'pname',&no_of_staff)
new 1: insert into pro_det values(3,'pname',1)
1 row created.
SQL> select * from pro_det;
PNO PNAME
NO_OF_STAFF
---------- ------------------------------ ----------1 pname
2
2 pname
3
3 pname
1
SQL>update pro_det set pname='DBMS' where pno=1;
1 row updated.
SQL> update pro_det set pname='COMPILER' where pno=2;
1 row updated.
SQL>update pro_det set pname='C' where pno=3;
1 row updated.
SQL> select * from Pro_det;
PNO PNAME
NO_OF_STAFF
---------- ------------------------------ ----------1 DBMS
2
2 COMPILER
3
3C
1
SQL> insert into work_in values(&pno,&eno,'&pjob');
Enter value for pno: 1
Enter value for eno: 1
Enter value for pjob: Programmer
old 1: insert into work_in values(&pno,&eno,'&pjob')
new 1: insert into work_in values(1,1,'Programmer')
1 row created.
SQL> /
Enter value for pno: 2
Enter value for eno: 1
Enter value for pjob: Analyst
old 1: insert into work_in values(&pno,&eno,'&pjob')
new 1: insert into work_in values(2,1,'Analyst')
1 row created.
SQL> /
Enter value for pno: 1
Enter value for eno: 2
NESTED QUERIES
(i) SQL> select ename from emp_det where dno not in(select dno from emp_det where ename =
'SaravanaKumar');
ENAME
--------------RajKumar
Shirley
(ii)SQL> select ename, dno from emp_det where dno = (select dno from emp_det where ename =
'RajKumar');
ENAME
DNO
--------------- ---------RajKumar
2
(iii)SQL> select ename from emp_det where eno in(select eno from work_in where pno = (select pno
from pro_det where pname = 'DBMS')) order by ename;
ENAME
--------------Mahendran
SaravanaKumar
(iv)SQL> select ename, basic_sal from emp_det where dno = 2 and basic_sal>(select max(basic_sal) from
emp_det where dno = 10) order by ename;
ENAME
BASIC_SAL
--------------- ---------RajKumar
10000
(v)SQL> select pno,pname from pro_det where exists(select pno from work_in where work_in.pno =
pro_det.pno);
PNO PNAME
------ -----------------------------1 DBMS
2 COMPILER
(vi)SQL>select ename, job_status,basic_sal from emp_det where (dno,basic_sal) in (select dno,basic_sal
from emp_det where ename ='RajKumar');
ENAME
JOB_STATUS
BASIC_SAL
--------------- --------------- ---------RajKumar
Professor
10000
(vii)SQL>select * from emp_det where basic_sal=(select max(basic_sal) from emp_det);
ENO ENAME
ADDRESS
BASIC_SAL JOB_STATUS
------ --------------- --------------- ---------- --------------- ---------3 RajKumar
EastCoastRoad
10000 Professor
2
DNO
(viii)SQL>select max(basic_sal) from emp_det where basic_sal< (select max(basic_sal) from emp_det);
MAX(BASIC_SAL)
--------------8000
(ix)SQL> select * from emp_det where basic_sal < (select avg(basic_sal) from emp_det);
ENO ENAME
ADDRESS
---- ----------------------------2 Mahendran
RainbowColony
BASIC_SAL JOB_STATUS
-----------------------5000
Supervisor
JOINS
SQL> create table emp(name varchar2(20),salary number(10));
Table created.
SQL> insert into emp values('&name',&salary);
Enter value for name: ashu
Enter value for salary: 10000
old 1: insert into emp values('&name',&salary)
new 1: insert into emp values('ashu',10000)
1 row created.
SQL> /
Enter value for name: asma
Enter value for salary: 1200
old 1: insert into emp values('&name',&salary)
new 1: insert into emp values('asma',1200)
1 row created.
DNO
---------10
SQL> /
Enter value for name: asif
Enter value for salary: 2000
old 1: insert into emp values('&name',&salary)
new 1: insert into emp values('asif',2000)
1 row created.
SQL> /
Enter value for name: arif
Enter value for salary: 1000
old 1: insert into emp values('&name',&salary)
new 1: insert into emp values('arif',1000)
1 row created.
SQL> /
Enter value for name: niyas
Enter value for salary: 3000
old 1: insert into emp values('&name',&salary)
new 1: insert into emp values('niyas',3000)
1 row created.
SQL> select * from emp;
NAME
SALARY
-------------------- ---------ashu
10000
asma
1200
asif
2000
arif
1000
niyas
3000
SQL> create table emp1(name varchar2(20),empid number(10));
Table created.
SQL> insert into emp1 values('&name',&empid);
Enter value for name: fathi
Enter value for empid: 12
old 1: insert into emp1 values('&name',&empid)
new 1: insert into emp1 values('fathi',12)
1 row created.
SQL> /
Enter value for name: sumi
Enter value for empid: 32
old 1: insert into emp1 values('&name',&empid)
new 1: insert into emp1 values('sumi',32)
1 row created.
SQL> /
Enter value for name: priya
Enter value for empid: 11
old 1: insert into emp1 values('&name',&empid)
new 1: insert into emp1 values('priya',11)
1 row created.
SQL> /
Enter value for name: wahab
Enter value for empid: 10
old 1: insert into emp1 values('&name',&empid)
new 1: insert into emp1 values('wahab',10)
1 row created.
SQL> /
Enter value for name: sweety
Enter value for empid: 09
old 1: insert into emp1 values('&name',&empid)
new 1: insert into emp1 values('sweety',09)
1 row created.
SQL>/
Enter value for name: asma
Enter value for empid: 1200
old 1: insert into emp1 values('&name',&empid)
new 1: insert into emp1 values('asma',1200)
1 row created.
SQL> select * from emp1;
NAME
EMPID
-------------------- ---------fathi
12
sumi
32
priya
11
wahab
10
sweety
9
asma
1200
6 rows selected.
NATURAL JOIN
************
SQL>select emp.name,salary from emp,emp1 where emp.name=emp1.name
NAME
SALARY
-------------------- ---------asma
1200
NAME
NAME
EMPID SALARY
-------------------- -------------------- ---------- ---------asma
asma
1200
1200
asif
2000
arif
1000
niyas
3000
ashu
10000
sweety
9
sumi
32
wahab
10
fathi
12
priya
11
10 rows selected.
RESULT:
Thus the nested queries and join operations are executed and verifiedin DBMS.
EX.NO:4
VIEWS
AIM:
To study and create View commands
VIEWS:
In SQL, a view is a virtual table based on the result-set of an SQL statement.A view contains rows and
columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
SQL CREATE VIEW Statement
In SQL, a view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more
real tables in the database.
SQL CREATE VIEW Syntax
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
SQL Updating a View
You can update a view by using the following syntax:
SQL CREATE OR REPLACE VIEW Syntax
CREATE OR REPLACE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
SQL Dropping a View
You can delete a view with the DROP VIEW command.
SQL DROP VIEW Syntax
DROP VIEW view_name
Sample Output
TABLE 1 CREATION
***************
`SQL> create table aa(name varchar2(20),book number(10),edition number(20),price number(20),
ISBN number(20));
Table created.
SQL> insert into aa values('&name',&number,&edition,&price,&ISBN);
Enter value for name: bb
Enter value for number: 23
Enter value for edition: 2001
Enter value for price: 12
Enter value for isbn: 23435
ISBN
SQL> /
Enter value for name: cc
Enter value for author: 43
Enter value for number: 55
Enter value for publisher: fg
Enter value for isbn: 65839
old 1: insert into qq values('&name','&author',&number,'&publisher',&ISBN)
new 1: insert into qq values('cc','43',55,'fg',65839)
1 row created.
SQL> /
Enter value for name: ee
Enter value for author: 44
Enter value for number: 21
Enter value for publisher: dfd
Enter value for isbn: 1235798
old 1: insert into qq values('&name','&author',&number,'&publisher',&ISBN)
new 1: insert into qq values('ee','44',21,'dfd',1235798)
1 row created.
SQL> /
Enter value for name: oo
Enter value for author: 87
Enter value for number: 34
Enter value for publisher: gfh
Enter value for isbn: 6358379
old 1: insert into qq values('&name','&author',&number,'&publisher',&ISBN)
new 1: insert into qq values('oo','87',34,'gfh',6358379)
1 row created.
SQL> select * from qq;
NAME
BOOK AUTHOR
PUBLISHER
-------------------- ---------- -------------------- ----------------------------bb
21 23
dfd
573568
cc
43 55
65839
fg
ISBN
ee
1235798
44 21
dfd
NAME
BOOK AUTHOR
PUBLISHER ISBN
-------------------- ---------- -------------------- -------------------- ---------oo
87 34
gfh
6358379
BOOK NAME
PUBLISHER
--------- -------------------- -------------------21 bb
dfd
BOOK
-------------------- ---------bb
21
bb
23
cc
43
cc
55
dd
2
ee
21
ee
44
oo
87
8 rows selected.
COMPLEX VIEW
*************
SQL> create view er as select author,name,ISBN from qq where book>43;
View created.
SQL> select * from er;
AUTHOR
NAME
ISBN
-------------------- -------------------- ---------21
ee
1235798
34
oo
6358379
SQL>select name from(select * from qq where publisher='fg')where ISBN=65839;
NAME
-------------------Cc
DROP VIEW
*************
SQL> drop view er;
View dropped
Result
Thus the view creation commands are executed successfully.
EX.NO:5
AIM:
To write PL/SQL(Functions)and to understand stored procedures in SQL.
FUNCTION:
A function is a subprogram that computes a value. The syntax for creating a function is given
below
Create or replace function<function_name>[argument]
Return datatype is
(local declaration)
begin
(executable statements)
[Exception]
(exception handlers)
end
PROCEDURE:
CREATE [ORREPLACE] PROCEDURE PROCEDURENAME
[PARAMETER[IN/OUT/IN/IN OUT] DATATYPE
[:=/DEFAULT EXPRESSION]
[(PARAMETER)]
IS/AS
DECLARATION
BEGIN
PL/SQL CODES
[EXCEPTION]
END
Sample Output
*****FUCTION USING FOR STATEMENT*****
SQL>create or replace function fact(a number)return number as
2 i number;
3 f number;
4 begin
5 f:=1;
6 for i in 1..a
7 loop
8 f:=f*i;
9 end loop;
10 return f;
11* end fact;
SQL> /
Function created.
Ex.no:6
AIM:
To study about Visual Basic forms and controls
Visual Basic:
Visual Basic is Easy to learn Programming language. With Visual Basic one can develop Windows based
applications and games.Visual Basic is much more easier to learn than other language (like Visual C++),
and yet it's powerful programming language.
Visual Basic suits more for application developing than for Games developing. We can create
sophisticated games using Visual Basic, But to make a really advanced professional game like Quake 2,
other language (like C++), can be chosen which are harder to program with. However, Visual Basic will
be probably powerful enough to suit all your application and games programming needs.
The advantages of Visual Basic:
1) It's simple language. Things that may be difficult to program with other language,can be done in Visual
Basic very easily.
2) Because Visual Basic is so popular, there are many good resources (Books,Web sites, News groups and
more) that can help us learn the language.
3) There are many tools (Sharewares and Freewares) on the internet that will reduce the programming
time.
Creating the Project
First thing to do is to create a Directory where all VB Projects can be saved. Call it VBApps, for
example. Then start VB. The first screen will ask whether to open a new project or an existing one - it's
obviously a new one and it will be a Standard EXE. Then, maximize all the windows. Now, save the
project. It will first prompt to save the form - call it Score.frm - and then the Project - call it Scorebrd.vbp.
From now on, do File-->Save Project very, very frequently.
Before starting to build-up the form, it will make it easier if the the color of the form is changed. To
change the color, just click anywhere on the form, go to the properties window, find the property called
BackColor and change it to the standard Window background (teal) or to any color desired in the palette.
Suppose if we need 6 labels and 2 command buttons go to the Toolbox. Each one of the object that is
kept on a Form is called a control. To get a control , click on the control, come back to the Form and click
and drag the control to the size and position needed. Position the controls somewhat like in the diagram
below.
Now that we have a bunch of controls on the form, we have to jazz them up a bit. We do this by changing
the Properties of the controls in the Properties window. Each control has a whole series of properties,
most of which we won't need right now. The ones we do need are:
If the application is executed at this point, the Form appears, just the way it was created. However if on
any of the controls is clicked, absolutely nothing happens! There are events that occur; the form opens, a
button is clicked, etc. But, there is nothing that tells the form what to do when it sees an event. That is why
code, also called script has to be written.
To switch between the Code window and the Form window, use the buttons just over the Project Explorer
window (diagram on the left).
Once in the Code window, We have the option of seeing all the code for the Project or the code for one
event at a time. Use the buttons in the lower left-hand corner (diagram on the right).
To select the object and the event to code, use the two Listboxes at the top of the Code window. The one
on the left for the object and the one on the right for the event. Start with General ... Declarations and
then Form ... Load, etc.
Now we can Run it and see something happen. When the Form loads, it will initialize the fields that we
specified in the code.Now code the Command1 button and Run it to see the result.
RESULT:
Thus the Visual Basic forms and controls are studied.
7. FORMS
AIM:
To implement the employee details using Visual Basic Form as front-end and Oracle as backend.
PROCEDURE:
1 row created.
SQL> /
Enter value for empname: Anitha
Enter value for empno: 1322
Enter value for designation: SrLecturer
Enter value for dept: Physics
Enter value for salary: 18000
Enter value for address: GoldenRock
old 1: insert into emp_details values('&empname',&empno,'&designation','&dept',&salary,'&address')
new 1: insert into emp_details values('Anitha',1322,'SrLecturer','Physics',18000,'GoldenRock')
1 row created.
SQL> /
Enter value for empname: Naveen
Enter value for empno: 1432
Enter value for designation: AP
Enter value for dept: CSE
Enter value for salary: 21000
Enter value for address: Tanjore
old 1: insert into emp_details values('&empname',&empno,'&designation','&dept',&salary,'&address')
new 1: insert into emp_details values('Naveen',1432,'AP','CSE',21000,'Tanjore')
1 row created.
SQL> /
Enter value for empname: Deepa
Enter value for empno: 1363
Enter value for designation: reader
Enter value for dept: English
Enter value for salary: 31000
Enter value for address: Karur
old 1: insert into emp_details values('&empname',&empno,'&designation','&dept',&salary,'&address')
new 1: insert into emp_details values('Deepa',1363,'reader','English',31000,'Karur')
1 row created.
SQL> select * from emp_details;
EMPNAME
EMPNO
----------------------------suba
1234
Anitha
1322
Naveen
1432
Deepa
1363
DESIGNATION DEPT
--------------- ---------AP
IT
SrLecturer
Physics
AP
CSE
reader
English
SALARY
ADDRESS
------------------21047
IBcolony
18000
GoldenRock
21000 Tanjore
31000
Karur
RESULT:
Thus the employee database has been implemented using Visual Basic Form as front-end and Oracle as
backend.
EX.NO:8
TRIGGERS
AIM:
To perform High-level language extension with triggers (Student mark list).
SYNTAX:
CREATE[OR REPLACE]TRIGGER[schema.]trigger
{BEFORE|AFTER|INSTEAD OF}
{DELETE
|INSERT
|UPDATE[OF column[,column].....]}
|OR {DELETE
|INSERT
|UPDATE[OF column,[,column]....]}]...
ON[schema.]{table|view}
REFERENCING(OLD[AS]old
|NEW[AS]new...]
FOR EACH{ROW|STATEMENT}{WHEN(condition)}]
DESCRIPTION:
The details about the students mark are being in the stu table with attributes.
Name, Rollno, Mark, Mark2, Mark3.
The stu1 table consists of attributes, Rollno, Total, Average, Result
The details of the first table are being given in the prompt by the user. The total, average are processed for
currently processed row in the stu table using after insert on trigger the values are placed in the table stu1.
Trigger
Create or replace trigger strig
After insert on st1
For each row
Declare
Total number(8);
Avg number(8);
Result varchar2(20);
Begin
Total:=(:new.m1+:new.m2+:new.m3);
Avg:=total/3;
If(:new.m1>50 and :new.m2>50 and:new.m3>50) yhen
Result:=pass;
Else
Result:=fail;
End if;
Insert into st2 values(:new.rollno,total,avg,result);
End;
/
Trigger created
SQL>insert into st1 values(raja,004,100,99,90)
1 row created
SQL>select * from st2;
ROLLNO
TOTAL
AVG RESULT
4
289
96
Pass
RESULT:
Thus the high-level language extension with triggers has been performed for generating the
students mark list.
EX.NO:9
MENU DESIGN
AIM:
To design menus using menu editor in Visual Basic.
PROCEDURE:
To create the following menus,
Color
o Setcolor
Red
Green
White
Size
Large
Small
Exit
It is required to do the following things:
1.
2.
Change the colour of the form if the user clicks a particular colour.
3.
Change the size of the form if the user clicks any of the option in size menu.
Steps to be followed:
1.
2.
Add a MDI form to the project by clicking Add MDI form from Project menu.
3.
Create menus.
Name this is the name you use to reference the menu control from code.
Caption this is the text that appears on the control.
Click OK button, the menus will be created on the top of MDI form.
4.
Either we can use the MDI form to see the changes or a separate form can be added to show
the changes on clicking the menu items.
5.
6.
7.
Ex.No.10
REPORTS
AIM:
To generate data report from the existing database.
OBJECTIVE:
Once you have gone to all the trouble of developing and managing a database, it is nice to have the
ability to obtain printed or displayed information from your data. The process of obtaining such
information is known as creating a data report.
There are two steps to creating a data report. First, we need to create a Data Environment. This is
designed within Visual Basic and is used to tell the data report what is in the database. Second, we create
the Data Report itself. This, too, is done within Visual Basic. The Data Environment and Data Report files
then become part of the Visual Basic project developed as a database management system.
The Visual Basic 6.0 data report capabilities are vast and using them is a detailed process. The use of
these capabilities is best demonstrated by example. We will look at the rudiments of report creation by
building a tabular report for our phone database.
Example - Phone Directory - Building a Data Report
We will build a data report that lists all the names and phone numbers in our phone database. We will do
this by first creating a Data Environment, then a Data Report. We will then reopen the phone database
management project and add data reporting capabilities.
Creating a Data Environment
1. Start a new Standard EXE project.
2. On the Project menu, click Add Data Environment. If this item is not on the menu, click
Components. Click the Designers tab, and choose Data Environment and click OK to add the designer
to your menu.
3. We need to point to our database. In the Data Environment window, right-click the Connection1 tab
and select Properties and set the connection.
4. We now tell the Data Environment what is in our database. Right-click the Connection1 tab and click
Rename. Change the name of the tab to Phone. Right-click this newly named tab and click Add
Command to create a Command1 tab. Right-click this tab and choose Properties. Assign the following
properties:
Command Name - PhoneList
Connection - Phone
DataBase Object - Table
ObjectName - PhoneList
5. Click OK. All this was needed just to connect the environment to our database.
6. Display the properties window and give the data environment a name property of denPhone. Click File
and Save denPhone As. Save the environment in an appropriate folder. We will eventually add this file to
our phone database management system.
In this form, Weve resized the labels a bit and added a Report Header. Also, make sure you close up the
Detail section to a single line. Any space left in this section will be inserted after each entry.
6. Click File and Save rptPhone As. Save the environment in an appropriate folder. We will now reopen
our phone database manager and attach this and the data environment to that project and add capabilities
to display the report.
Accessing the Data Report
1. Reopen the phone directory project. Add a command button named cmdReport and give it a Caption of
Show Report. (There may be two tabs in your toolbox, one named General and one named DataReport.
Make sure you select from the General tools.)
2. We will now add the data environment and data report files to the project. Click the Project menu item,
then click Add File. Choose denPhone and click OK. Also add rptPhone. Look at your Project Window.
Those files should be listed under Designers.
3. Use this code in cmdReport_Click:
Private Sub cmdReport_Click()
rptPhone.Show
End Sub
4. This uses the Show method to display the data report.
5. Save the application and run it. Click the Show Report button and this should appear:
RESULT:
Thus the Report has been generated in Visual Basic..