BCS4L1-Database Management Lab
BCS4L1-Database Management Lab
PRACTICAL
(Semester -IV of B.Tech)
NEW EDITION
PREPARED BY
DR. M.K.VIDHYALAKSHMI
1
SCHOOL OF COMPUTING
2
LAB MANUAL
Regulation R2015
(2015-2016)
3
BCS4L1 DBMS LABORATORY L T P C
Total Contact Hours - 30 0 0 3 2
Prerequisite –Database Management System
Lab Manual Designed by – Dept. of Computer Science and Engineering
OBJECTIVES: The main objective isstudents gain knowledge about databases for storing the data
and to share the data among different kinds of users for their business operations.
COURSE OUTCOMES (COs)
CO1 Develop database modeling for a problem.
CO2 Design a database using normalization.
CO3 Implement a data base query language.
CO4 Develop GUI using front end tool.
CO5 Develop a connection between frontend and database.
CO6 Implement a Data Manipulation Language.
MAPPING BETWEEN COURSE OUTCOMES & PROGRAM OUTCOMES
(3/2/1 INDICATES STRENGTH OF CORRELATION) 3- High, 2- Medium, 1-Low
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 S S 2 3
CO2 2 2 3 1 2 2 1 S 2 3
CO3 S S 2 2 2 2 3
CO4 2 2 3
CO5 S 2 2 2 2 3
CO6 2 S 1 2 2 2 2 3
Category Professional Core (PC)
Approval 37th Meeting of Academic Council, May 2015
LIST OF EXPERIMENTS
1. Data Definition, Manipulation of base tables and views
2. High level programming language extensions.
3. Front end tools.
4. Forms-Triggers-Menu Design.
5. Reports.
6. Database Design and implementation
An exercise using Open Source Software like MySQL
4
DATABASE MANAGEMENT SYSTEMS (DBMS) LAB - [BCS4L1]
LIST OF EXPERIMENTS
4 Forms-triggers-menu design.
5 Reports
5
CONTENT
5 Reports 71
6
EX.NO:1a
DATA DEFINITION LANGUAGES (DDL) COMMANDS Of Base Tables and Views
Aim:
DDL commands:
✴ CREATE
✴ ALTER
✴ DROP
✴ RENAME
✴ TRUNCATE
SYNTAX’S OF COMMANDS
CREATE TABLE:
To make a new database, table, index, or stored query. A create statement in SQL
creates an object inside of a relational database management system (RDBMS).
7
ALTER A TABLE:
To modify an existing database object. Alter the structure of the database.
To add a column in a table
ALTER TABLE table_name ADD column_name datatype;
To delete a column in a table
ALTER TABLE table_name DROP column column_name;
DROP TABLE:
Delete Objects from the Database
DROP TABLE table_name;
TRUNCATE TABLE:
Remove all records from a table, including all spaces allocated for the records are
removed.
EXERCISE:
Create Table
SQL> create table employee
2(
3 empid varchar(10) primary key,
4 empname varchar2(20) not null,
5 gender varchar2(7) not null,
6 age number(3) not null,
7 dept varchar2(15) not null,
8 dob date not null,
9 doj date not null
10);
Table created.
8
SQL> create table salary
2 (
3 empid varchar(10) references employee(empid),
4 salary number(10) not null,
5 dept varchar(15) not null,
6 branch varchar2(20) not null
7 );
Table created.
DESCRIBE TABLE
SQL> desc employee;
Name Null? Type
9
SQL> desc salary;
Name Null? Type
ALTER TABLE
I. ADD:
SQL> alter table employee add(designation varchar2(15));
Table altered.
II. MODIFY
SQL> alter table employee modify (designation varchar2(20));
Table altered.
10
RENAME TABLE
SQL> create table emp
2 (
3 empid varchar2(10),
4 empname varchar2(20),
5 age number(3),
6 sex char
7 );
Table created.
EMPID VARCHAR2(10)
EMPNAME VARCHAR2(20)
AGE NUMBER(3)
SEX CHAR(1)
11
Enter value for dept: it
Enter value for age: 22
Enter value for sex: m
old 1: insert into emp values(&no,'&name','&dept',&age,'&sex')
1 row created.
1 arun it 22 m
12
2 bala service 26 m
3 chitra sales 25 f
SQL> commit;
Commit complete.
Commit complete.
DROP TABLE
SQL> drop table empl;
Table dropped.
SQL> desc empl;
ERROR:
ORA-04043: object empl does not exist
RESULT:
13
EX.NO:1b
DATA MANIPULATION LANGUAGE (DML) OF BASE TABLES AND VIEWS
Data manipulation language allows the users to query and manipulate data in existing
schema in object. It allows following data to insert, delete, update and recovery data in
schema object.
Aim:
To study DML commands in RDBMS.
DML COMMANDS:
❖ INSERT
❖ UPDATE
❖ DELETE
❖ SELECT
QUERY:
Query is a statement in the DML that request the retrieval of data from database.
❖ The portion of the DML used in a Query is called Query language. The SELECT
statement is used to query a database
SYNTAX OF COMMANDS
INSERT:
Values can be inserted into table using insert commands. There are two types of insert
commands. They are multiple value insert commands (using ‘&’ symbol) single value insert
command (without using ‘&’symbol)
Syntax:
INSERT INTO table_name VALUES (value1, value2, value3,…..);
(OR)
INSERT INTO table_name (column1, column2, column3,….) VALUES
(value1,value2,value3,…..);
14
UPDATE:
This allows the user to update the particular column value using the where clause
condition.
Syntax:
UPDATE <table_name> SET <col1=value> WHERE <column=value>;
DELETE:
This allows you to delete the particular column values using where clause condition.
Syntax:
DELETE FROM <table_name> WHERE <condition>;
SELECT:
The select statement is used to query a database .This statement is used to retrieve the
information from the database. The SELECT statement can be used in many ways. They are:
1. Selecting some columns :
To select specified number of columns from the table the
Syntax:
To select all columns from the table * is used instead of column names.
Syntax:
The DISTINCT keyword is used to return only different values (i.e. ) this
command does not select the duplicate values from the table.
Syntax:
15
4. Select using IN:
If you want to get the rows which contain certain values, the best way to do it
is to use the IN conditional expression.
Syntax:
BETWEEN can be used to get those items that fall within a range.
Syntax:
6. Renaming:
The select statement can be used to rename either a column or the entire
table.
Syntax:
Renaming a column:
Renaming a table:
7. Sorting:
The select statement with the order by Clause is used to sort the contents
Syntax:
16
8. To select by matching some patterns:
The select statement along with like clause I is used to match strings. The like
condition is used to specify a search pattern in a column.
Syntax:
SELECT column name FROM table_name WHERE Column name LIKE “% or-“;
The SELECT INTO statement is most often used to create backup copies of
tables or for archiving records.
Syntax:
WHERE condition.
We can use the SELECT statement to select the ‘null’ values also.
For retrieving roes where some of the columns have been defined as NULLs there is a special
comparison operator of the form IS [NOT]NULL.
Syntax:
Syntax:
17
EXERCISE:
INSERT COMMAND
18
old 1: insert into employee
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desi
new 1: insert into employee values('it9001','arunkumar','male',22,'it','12-jan-1988','23-oct-
2006'
1 row created.
19
Enter value for doj: 01-jan-1995
Enter value for desig: manager
old 1: insert into employee
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desi
1 row created.
20
Enter value for dept: service
Enter value for dob: 31-mar-1877
Enter value for doj: 3-jun-1999
Enter value for desig: manager
old 1: insert into employee
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desi
new 1: insert into employee values('ser9001','jagadheesh','male',33,'service','31-mar-
1877','3-jun
1 row created.
21
Enter value for empname: suresh
Enter value for gender: male
Enter value for age: 40
Enter value for dept: sales
22
SQL> insert into salary values(‘&empid’,&salary,’&dept’,’&branch’);
Enter value for empid: it9002
Enter value for salary: 18000
Enter value for dept: it
Enter value for branch: abt maruthi
old 1: insert into salary values('&empid',&salary,'&dept','&branch')
new 1: insert into salary values('it9002',18000,'it','abt maruthi')
1 row created.
23
Enter value for dept: service
Enter value for branch: chennai cars
old 1: insert into salary values('&empid',&salary,'&dept','&branch')
new 1: insert into salary values('ser9001',35000,'service','chennai cars')
1 row created.
24
new 1: insert into salary values('sal9006',17000,'sales ','abt maruthi')
1 row created.
8 rows selected.
DOJ DESIGNATION
25
DOJ DESIGNATION
DOJ DESIGNATION
26
it9001 35000 it abt maruthi
it9002 18000 it abt maruthi
acc9001 35000 accounts cars india
acc9002 26000 accounts cars india
ser9001 35000 service chennai cars
ser9006 12000 service greenland cars
sal9001 40000 sales abt maruthi
sal9006 17000 sales abt maruthi
8 rows selected.
27
1 row created.
UPDATE COMMAND
SQL> update employee set empname = 'arunprasanth' where empid='it9001';
1 row updated.
arunprasanth manager
balakrishnan coordinator
kannan manager
magudeshwaran asst manager
jagadheesh manager
28
muruganandam supervisor
suresh manager
sharmila executive
8 rows selected.
SELECT COMMAND
To retrieve particular column
SQL> select empname from emp;
EMPNAME
arun
bala
bakyaraj
chitra
1 arun it 22 m
2 bala accounts 26 m
3 bakyaraj stores 30 m
4 chitra sales 24 f
DELETE COMMAND
To delete particular record
SQL> delete emp where empid=1;
1 row deleted.
29
SQL> select * from emp;
EMPID EMPNAME DEPT AGE S
2 bala accounts 26 m
3 bakyaraj stores 30 m
4 chitra sales 24 f
3 rows deleted.
Table created.
IDNO NUMBER
NAME VARCHAR2(10)
BRANCH VARCHAR2(4)
Table altered.
IDNO NUMBER
30
NAME VARCHAR2 (10)
IDNO NUMBER
1 row created.
1 row created.
1 row created.
31
Enter value for idno: 04
1 row created.
SQL> /
1 row created.
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT BE
5 HARRY IT BE
2 rows updated.
32
SQL> select * from student;
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT B.TECH
5 HARRY IT B.TECH
1 row deleted.
NOT NULL
SQL> select * from student;
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT B.TEC
H
varchar(10),branch varchar(6)
); Table created.
33
SQL> desc staff;
NAME VARCHAR2(10)
BRANCH VARCHAR2(6)
1 row created.
SQL> /
1 row created.
SQL> /
ERROR at line 1:
UNIQUE
name varchar(10),
salary number
);
Table created.
ROLLNO NUMBER
NAME VARCHAR2(10)
SALARY NUMBER
1 row created.
SQL> /
1 row created.
SQL> /
ERROR at line 1:
PRIMARY KEY
name varchar(10),
cost number(6)
);
Table created.
36
SQL> desc cars;
NAME VARCHAR2(10)
COST NUMBER(6)
1 row created.
SQL> /
1 row created.
SQL> /
37
insert into cars values(1098,'innova',600000)
ERROR at line 1:
CHECK CONSTRAINT:
rno number(5),
name varchar(10),
);
Table created.
RNO NUMBER(5)
NAME VARCHAR2(10)
SALARY NUMBER(10)
38
SQL> /
1 row created.
SQL> /
ERROR at line 1:
FOREIGN KEY
name varchar(10),
permit number(6)
);
Table created.
39
SQL> desc admin;
NAME VARCHAR2(10)
PERMIT NUMBER(6)
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
1 ASWIN 80
2 ROHIT 67
4 SANJAY 45
5 KAMALINI 35
branch varchar(6),
sec varchar(2)
);
Table created.
41
SQL> insert into course values(&stuid,'&branch','&sec');
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
42
Enter value for sec: A
ERROR at line 1:
1 row deleted.
ERROR at line 1:
1 ASWIN 80
2 ROHIT 67
4 SANJAY 45
SQL> select * from course;
STUID BRANCH SE
1 CSE A
2 CSE A
4 IT A
43
SQL> create table student
idno varchar(4),
name varchar(10),
dept varchar(4),
degree varchar(6),
year number(4)
);
table created.
IDNO VARCHAR2(4)
NAME VARCHAR2(10)
DEPT VARCHAR2(4)
DEGREE VARCHAR2(6)
YEAR NUMBER(4)
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
45
Enter value for year: 1
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
46
SQL> SELECT * FROM STUDENT;
6 rows selected.
DISTINCT
CSE
ECE
IT
MECH
AARON
AKIL
BENNY
COOK
DANNY
ELAN
6 rows selected.
47
IN
SQL> select * from student where name BETWEEN 'AARON' and 'COOK';
AS
A01
A02
A03
B01
B02
B03
6 rows selected.
SORT
48
B03 ELAN IT B.TECH 1
B02 DANNY MECH BE 1
B01 COOK CSE BE 1
A03 BENNY IT B.TECH 2
A02 AKIL ECE BE 2
A01 AARON CSE BE 2
6 rows selected.
LIKE
49
IS NULL
no rows selected
LOGICAL OR
RESULT:
Thus the data manipulation language (dml) of base tables and views are executed.
50
EX.NO: 2
HIGH LEVEL PROGRAMMING LANGUAGE EXTENSIONS
Aim:
Introduction:
If-then:
Syntax:
IF condition THEN
Sequence_of_statements
END IF;
The sequence of statements is executed only if the condition is true. If the condition
is false or null, then if statement does nothing. The control passes to the next statement.
If-then-else:
The second form of IF statement adds the keyword ELSE followed by alternative
sequence of statements, as follows
Syntax:
IF condition THEN
Sequence_of_statements1
ELSE
Sequence_of_statements2
ENDIF;
51
The sequence of statements in the ELSE clause is executed only if the condition is
false or null. Thus the ELSE clause ensures that a sequence of statements is executed.
If-then-elseif:
Sometimes you want to select from several mutually exclusive alternatives. The
third form of IF statement uses ELSEIF to introduce additional as follows
Syntax:
IF conditional1 THEN
Sequence_of_statements1
ELSEIF condition2 THEN
Sequence_of_statements2
ELSE
Sequence_of_statements3
ENDIF;
Nested If:
Syntax:
IF condition THEN
statement1;
ELSE
IF condition THEN
statement2;
ELSE
statement3;
END
IF; END IF;
Case statement:
Like the IF statement, the CASE statement selects one of statements to execute.
However, to select the sequence the case statement uses a selector rather than multiple
Boolean expressions.
Syntax:
CASE selector
52
WHEN expression1 THEN sequence_of_statements1;
……
[ELSE sequence_of_statementsN+1;]
END CASE;
Simple Loop:
The simplest form of loop statements is the basic loop which encloses a sequence of
statements between the keyword LOOP and ENDLOOP as follows
Syntax:
LOOP
Sequence_of_statements
END LOOP;
With each iteration of the loop the sequence of the statements is executed then the
control resumes at the top of the loop. If further processing is undesirable or impossibly you
can use an EXIT statement to complete the loop.
While loop:
The while loop statement associates a condition with a sequence of statements
enclosed by the keywords LOOP and END LOOP as follows
Syntax:
Sequence_of_statements
END LOOP;
Before each iteration of the loop the condition is evaluated. If the condition is true the
sequence of statements is executed then the control resumes at the loop. If the condition is
false or null the loop is bypassed and the control passes to the next statement.
53
For loop:
The number of iterations through FOR loop is known before the loop is entered.
FOR loops iterate over a specified range of integers, the range is part of an iteration scheme,
which is enclosed by the keywords FOR and LOOP. A double dot (..) serves as the range
operator.
Syntax:
FOR counter IN [REVERSE]
LowerBound..UpperBound LOOP
Sequence_of_statements
END LOOP;
GOTO statement:
The GOTO statement branches to a label unconditionally. The label must be
unique within its scope and must proceed an executable statement or a pl/sql block.
When executed the GOTO statement transfers control to the labeled statement or block.
Syntax:
Begin
…
GOTO insert_row;
…
INSERT INTO values
END;
NULL statement:
The null statement does nothing other than pass control to the next statement. In
a conditional construct the NULL statement tells readers that a possibility has been
considered, but no action is necessary.
54
(b) PROCEDURES:
Syntax:
55
[EXCEPTION
Exception_section]
END [Procedure_Name];
(c) FUNCTIONS:
❖ A function is a program that might perform an action and does return a value. The
function is a subprogram that computes a value.
1. The specification
2. The body
The Specification:
❖ The function specification begins with the keyword FUNCTION and ends with the
RETURN clause, which specifies the data type of the return value.
❖ Parameter declaration are optional. Functions that take no parameters are written
without parentheses.
The Body:
❖ The function body begins with the keyword IS (or AS) and ends with keyword END
followed by an optional function name.
1. A Declarative part.
2. An Executable part.
❖ The declarative par contains local declarations, which are placed between the
keywords IS and BEGIN.
❖ The executable part contains statements, which are placed between the keywords
BEGIN, and EXCEPTION (or END).
56
Syntax:
EXERCISE:
FACTORIAL PROGRAM
SQL> declare
2 n number(2);
3 p number(5);
4 i number(2);
5 begin
6 n:=&n;
7 p:=1;
8 for i in 1..n
9 loop
10 p:=p*i;
11 end loop;
12 dbms_output.put_line('Factorial value is '||to_char(p));
13 end;
14 /
Enter value for n: 5
old 6: n:=&n;
new 6: n:=5;
PL/SQL procedure successfully completed.
57
new 6: n:=5;
Factorial value is 120
(b) PROCEDURES
Table created.
1 80 85 0
2 75 84 0
3 65 80 0
4 90 85 0
1 80 85 165
2 75 84 0
3 65 80 0
4 90 85 0
1 80 85 165
2 75 84 0
3 65 80 0
4 90 85 0
59
RNO MARK1 MARK2 TOTAL
1 80 85 165
2 75 84 159
3 65 80 145
4 90 85 0
(c)FUNCTION:
60
SQL> insert into stud values(&rno,&mark1,&mark2,&total);
Enter value for rno: 2
Enter value for mark1: 77
Enter value for mark2: 56
Enter value for total: 0
old 1: insert into stud values(&rno,&mark1,&mark2,&total)
new 1: insert into stud values(2,77,56,0)
1 row created.
1 80 65 0
2 77 56 0
3 89 90 0
61
9 end;
10 /
Function created.
145
133
179
RESULT:
62
EX.NO:3
FRONT END TOOLS
Introduction:
Visual basic uses object oriented techniques to create program that are powerful, robust and
efficient.
Project:
Forms:
A form is a collection of controls. The controls are placed on the form. The form also has its
own properties and methods. It has the extension .frm. - 99 -More than one form may be used in
an application.
Visual basic is referred to as an integrated development environment (IDE). IDE consists of
following elements,
● Title bar
● Menu bar
● Tool bar
● Tool box
● Control menu
● Project explorer window
● Properties window
● Object browser
● Form designer
63
● Code editor window
● Form layout window
TOOL BAR:
⮚ Right click anywhere on the menu bar, or choose toolbars from the view menu the
toolbar pop-up menu appears.
⮚ Select the type of standard toolbar that you want from the pop-up menu. If a check is
to the left of the toolbar type, that toolbar is already visible.
Under the menu, there is a toolbar. Toolbar is used to quick access the commonly used menu
commands. There are few build in toolbars,
● Standard toolbar
● Edit toolbar
● Debug toolbar
● Form edit toolbar
64
STANDARD TOOLBAR:
The standard toolbar is the central toolbar in the visual basic IDE. The standard toolbar offers
many features found in the file, project, debug and run menu.
The standard toolbar enables fast access to often use functionally and information.
The extended edit menu and some debug menu functions from the edit toolbar can be
accessed.
The feature of edit toolbar is similar to those of the edit menu. You can cut, copy and paste
text. You can manipulate the layout of the code and do text selection, searches and replacement. Also
you can use automatic coding features such as quick info.
The debug toolbar enables you to access the debugging functions of the visual basic IDE.
You can use the debug toolbar to test the program and restore errors that might occur. When you
debug a program you do such things as run the code a line at a time.
You can use the form editor toolbar to size, move, and align controls on a form. The form
editor toolbar has the same set of features as the format menu.
You align and size multiple controls on a form with the form editor toolbar. There are small
download facing arrowheads to the right of the align, centre and make toolbar buttons. These
arrowheads indicate that a dropdown menu will appear when you select that toolbar button.
To experiment with the project explorer window, click the toggle folders button. Notice that
the folders are collapsed.
To expand the folders, click the toggle button again. Still on the project explorer window,
click view code. You are presented with the code editor window.
65
To send the code editor window to the background again, on the project explorer windows,
click the view object button.
DEFAULT CONTROLS:
Common properties:
Important common properties include the following,
● Name
● Index
● Left
● Top
● Height
● Width
● Enabled
● Visible
Controls contained in the visual basic toolbox:
1) Picture box: Displays graphics. Can also serve as a container for other controls.
Property: caption, picture.
2) Label box: Displays text that user cannot edit.
Property: caption.
3) Text box: Displays text. Allows the user to enter and edit text.
Property: text.
4) Frame: Serves as a container for other commands. Provides grouping of controls.
Property: caption.
5) Command buttons: Allows the user to initiate actions by clicking the button.
6) Check box: Lets the user make a true/false choice.
7) Option button: Lets the users choose from one option from a group of items.
Property: caption.
8) Combo box: Lets the users choose from a list of items or enter a new values.
Property: caption.
9) List box: Lets the user choose from a list of items.
Property: list.
10) Horizontal/ Vertical scroll box: Lets the user choose a scrollbar value based on the
position of button in the bar.
66
11) Timer: Lets the program perform functions on a timed basic.
12) Drive list box: Let the user select a disk drive.
13) Directory list: Let the users select a box directory or folders.
14) File list box: Lets the user select a file.
15) Shape: Displays a shape on the form.
16) Line: Displays a line on the form.
17) Image: similar to a picture box control, uses fewer system resources but doesn’t
support as many properties, events and methods.
18) Data control: Provides an interface between the program and a data source.
19) OLE: Provides a connection between the program and an OLE server.
20) Common dialog: Allows use of windows standard dialog boxes to retrieve
information such as filenames and colors.
RESULT:
67
EX.NO:4
FORMS-TRIGGERS-MENU DESIGN
Aim:
TRIGGER:
A database trigger is a stored procedure that is fired when an insert, update or delete
statement is issued against the associated table. Database triggers can be used for the
following purposes.
To generate data automatically.
To enforce complex integrity constraints. (e.g., Checking with sysdate, checking
with data in another table).
To customize complex security authorizations.
To maintain replicate tables.
To audit data modifications.
PARTS OF A TRIGGER
A database trigger has three parts, namely, a trigger statement, a trigger body and a
trigger restriction.
68
TRIGGER STATEMENT:
A trigger statement specifies the DML statements like update, delete and insert and it
fires the trigger body. It also specifies the table to which the trigger is associated.
TRIGGER BODY:
Trigger body is a PL/SQL block that is executed when a triggering statement is
issued.
TRIGGER RESTRICTION:
Restrictions on a trigger can be achieved using the WHEN clause as shown in the
syntax for creating triggers. They can be included in the definition of a row trigger, where in,
the condition in the WHEN clause is evaluated for each row that is affected by the trigger.
TYPES OF TRIGGER:
Triggers are categorized into the following types based on when they are fired:
⮚ Before
⮚ After
⮚ For each row
⮚ For each statement (default)
Using a combination of the above options, we can assign 12 types of triggers to a database
table.
69
Before insert row / statement
After update row / statement
After delete row / statement
After insert row / statement
EXERCISE:
1. Write a PL/SQL program to create a trigger before the user inserts the data into the table.
2. Write a PL/SQL program to create a trigger before the user deletes the data from the table.
3. Write a PL/SQL program to create a trigger before the user changes the value of the salary
of the employee.
ANSWERS:
SQL>create or replace trigger ins1 before insert on emp begin
raise_application_error (-20001,'you can’t insert a row'); end;
OUTPUT:
SQL>insert into emp
values(&eid,'&name','&dob','&addr','&sex','&desig',&deptno,'&maritsta',&salary);
SQL>insert into emp *
values(&eid,'&name','&dob','&addr','&sex','&desig',&deptno,'&maritsta',&salary);
ERROR at line 1:
ORA-20001: you cant insert a row
ORA-06512: at "CSE382.ins1", line 2
ORA-04088: error during execution of trigger 'CSE382.ins1'
70
OUTPUT:
SQL>delete from emp where eid=4444;
delete from emp where eid=4444;
*
ORA-20001: you can’t delete a row
ORA-06512: at "CSE382.DEL1", line 2
ORA-04088: error during execution of trigger 'CSE382.DEL1'
SQL> create trigger upd1 before update on emp for each row 2 begin
3 if :new.sal < 1000 then
4 raise_application_error(-20001,'salary can’t be low than this'); 5 end if;
6 end;
7 /
Trigger created.
RESULT:
71
EX.NO: 5
REPORTS
Aim:
Steps:
Report name.Show
Eg
Data report1.Show
72
73
74
75
76
CRITERI MAX.MARK MARKSOBTAINED
A S
AIM& ALGORITHM 5
EXECUTION&OUTPUT 10
VIVA 5
TOTAL 20
RESULT:
77
EX.NO: 6
DATABASE IN BANK
Aim:
To design a forms and write a code for banking systems and make a connection with
back end using ADO Data control.
Description:
Table creation:
The student database has been created in Oracle and some rows have been inserted
using the DDL and DML command.
Table Creation:
SQL> create table employee (name varchar2(20), f_name varchar2(15), emp_no number(5),
dob date, sex varchar2(5) , m_tong varchar2(10) , city varchar2(10) , street varchar2(10) ,
state varchar2(10));
Table created.
78
Values Are Inserted By
1) Go to start → all programs→ Microsoft Visual Studio 6.0 → Microsoft Visual Basic
6.0
→Click.
2) While opening it will ask you New project in that click standard exe→ then open→
new
Form is opened. (Or)
To create a form:
4) From the tool bar drag the text box and label and place it in the form.
5) The number of text box and label depends upon the fields we have in the Table.
6) We can also have command buttons to perform particular action when they are
clicked.
7) To view the form we should press shift +F7.
Data control:
Visual Basic provides a set of controls that allow you to display, add edit data in the
database with minimal coding. When such controls are used the user need not write code,
instead they allow the user to use their properties to access the database. Such controls are
known as Data-aware controls. Data controls are a standard control available in the tool box.
Let us consider that we are maintaining a database named emp, which consists of
fields like empno, empname, empadd, empphone. The steps to connect the data control to the
emp database are:
79
1. Place the Data control on the form by double clicking on the icon representing the
2. Place four text boxes on the form to display the value of the fields empno, empname,
empadd and empphone from the table emp into respectively.
3. Set the connection string property of the Data control to Access. The Connection
string property determines the type of the database to access.
4. Set the DatabaseName property to emp. The DatabaseName property determines the
name of the database to be opened.
5. Set the RecordSource property of the Data control to empinfo. The RecordSource
property determines the name of the table to be accessed.
6. Make the text boxes bound to the Data control by using the DataSource and DataField
properties. A control is said to be data-aware when it is bound to a Data control. The
DataSource property determines the name of the Data control to which the text box is
to be bound. The DataField property determines the name of the field in the table. Set
the Name, DataSource and DataField properties of the text boxes as shown in the
below table.
DataSource data 1
DataField empno
Password tiger
80
RecordSource empinfo
UserName scott
7. Run the application and use the arrow buttons on the data control to navigate through
the records in the below screen. You have to write code to add, update, edit and delete
records in the below screen. Or else press the function key 5 (F5)
Form Design:
81
CODING WINDOW:
82
MsgBox "Record Found", vbInformation
Text1.Text = rs.Fields("name")
Text2.Text = rs.Fields("f_name")
Text3.Text = rs.Fields("emp_n0")
Text4.Text = rs.Fields("dob")
Text5.Text = rs.Fields("sex")
Text6.Text = rs.Fields("m_tong")
Text7.Text = rs.Fields("city")
Text8.Text = rs.Fields("street")
Text9.Text = rs.Fields("state")
End If
End Sub
Screen Shots:
1. Insertion
83
1. Deleting
84
2. Updating
85
3. Display a particular record
RESULT:
86
EX.NO: 7
Aim:
To use an open-Source Software My SQL and create a simple table with countries including
columns with country-id, country-name and region-id.
Code:
COUNTRY_NAME varchar(40),
REGION_ID decimal(10,0)
);
Output :
mysql> DESC countries;
+--------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| COUNTRY_ID | varchar(2) | YES | | NULL | |
| COUNTRY_NAME | varchar(40) | YES | | NULL | |
| REGION_ID | decimal(10,0) | YES | | NULL | |
+--------------+---------------+------+-----+---------+-------+
RESULT: