4IT4-22 - DBMS Lab Manual - Anjali Pandey
4IT4-22 - DBMS Lab Manual - Anjali Pandey
A
Hands on Lab Guide
On
Programme: B.Tech.
Semester: IV
Session: 2021-22
Lab Manual
4IT4-22
Session 2021-22
Signature
Page | 1
Swami Keshvanand Institute of Technology, Management & Gramothan,
Ramnagaria, Jagatpura, Jaipur-302017, INDIA
Approved by AICTE, Ministry of HRD, Government of India
Recognized by UGC under Section 2(f) of the UGC Act, 1956
Tel. : +91-0141- 3500300 Fax: +91-0141-2759555
E-mail: [email protected] Web: www.skit.ac.in
Instructions
Before Entering the Lab
• All the students are supposed to prepare the theory regarding the next program
• Students are supposed to bring the practical file and lab copy
• Previous program should be written in the practical file
• Algorithm of the current program should be written in lab copy
• Any student not following these instructions will be denied entry in the lab
Marking/Assessment System
Total Marks – 100
Page | 2
Table of Contents
S.No. Content Page Remarks
Number
1 Course Objective
3 Syllabus
1. Design a Database and create required tables. For e.g. Bank, College Database
2. Apply the constraints like Primary Key, Foreign key, NOT NULL to the tables.
3. Write a SQL statement for implementing ALTER,UPDATE and DELETE.
4. Write the queries to implement the joins.
5. Write the query for implementing the following functions: MAX (), MIN (), AVG ()
and COUNT ().
6. Write the query to implement the concept of Integrity constrains.
7. Write the query to create the views.
8. Perform the queries for triggers.
9. Perform the following operation for demonstrating the insertion , updation and
deletion
10. Using the referential integrity constraints.
11. Write the query for creating the users and their role.
For better understanding students (group of 3-4 students) should design data base
for any data base project, understand the requirement and design methodology of
project by its own.
Syllabus of 2nd Year B. Tech. (IT) for students admitted in Session 2021-22 onwards. Page 10
INDEX
4 VIEWS
7 FORMS
8 TRIGGERS
9 MENU DESIGN
10 REPORTS
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>
);
To change the name of a table, view, sequence, or synonym, execute the rename statement.
Syntax: rename old name to new name;
DROP TABLE
1. All data and structure in the table is deleted
2. Any pending transactions are committed.
3. All indexes are dropped.
4. We can not rollback the drop table statement.
Syntax:drop table <table name>;
Tab l e dropped.
SET UNUSED OPTION:
Table belonging to other users are not in the user’s schema, we should use the owner’s name as
prefix to those tables.
Sample Output
CONSTRAINTS
Table created.
VENCODE VARCHAR2(5)
VENNAME NOT NULL VARCHAR2(7)
Table altered.
1 row created.
1 row created.
SQL> /
Enter value for vencode: v003
Enter value for venname:
Enter value for productprice: 9000
old 1: insert into vendor_master values('&vencode','&venname',
&productprice)
new 1: insert into vendor_master values('v003','',9000)
insert into vendor_master values('v003','',9000)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("USER06"."VENDOR_MASTER".
"VENNAME")
SQL> /
Enter value for vencode: v003
Enter value for venname: Philips
Enter value for productprice: 8000
old 1: insert into vendor_master values('&vencode','&venname',
&productprice)
new 1: insert into vendor_master values('v003','Philips',8000)
1 row created.
SQL> /
Enter value for vencode: v004
Enter value for venname: Akai
Enter value for productprice: 12000
old 1: insert into vendor_master values('&vencode','&venname',
&productprice)
new 1: insert into vendor_master values('v004','Akai',12000)
insert into vendor_master values('v004','Akai',12000)
*
ERROR at line 1:
ORA-02290: check constraint (USER06.SYS_C002809) violated
SQL> /
Enter value for vencode: v005
Enter value for venname: Aiwa
Enter value for productprice: 8500
old 1: insert into vendor_master values('&vencode','&venname',
&productprice)
new 1: insert into vendor_master values('v005','Aiwa',8500)
1 row created.
PRIMARY AND FOREIGN KEY CONSTRAINTS
SQL> create table order_master(orderno varchar(5) constraint order_prim
primary key,odate date,
vencode varchar(5),o_status char(1) not null,deldate date);
Table created.
Table created.
ORDERNO VARCHAR2(5)
ITEMCODE VARCHAR2(3)
QTYORDER NUMBER(3)
1 row created.
SQL> /
Enter value for oredrno: o001
Enter value for odate: 11-nov-2008
Enter value for vencode: v002
Enter value for o_status: p
Enter value for deldate: 14-feb-2010
old 1: insert into order_master values('&oredrno','&odate','&vencode',
'&o_status','&deldate')
new 1: insert into order_master values('o001','11-nov-2008','v002','p',
'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> /
Enter value for orderno: o001
Enter value for itemcode: i01
Enter value for qtyorder: 25
old 1: insert into order_detail values('&orderno','&itemcode',&qtyorder)
new 1: insert into order_detail values('o001','i01',25)
1 row created.
Table dropped.
Table dropped.
Table created.
1 row created.
SQL> /
Enter value for oredrno: o002
Enter value for odate: 24-sep-2008
Enter value for vencode: voo2
Enter value for o_status: p
Enter value for deldate: 16-jan-2010
old 1: insert into order_master values('&oredrno','&odate','&vencode',
'&o_status','&deldate')
new 1: insert into order_master values('o002','24-sep-2008','voo2','p',
'16-jan-2010')
1 row created.
SQL> select * from order_master;
o001 i01 25
o002 i02 50
1 row deleted.
o002 i02 50
RESULT:
Thus the Data Definition Language (DDL) and Data Control Language (DCL) commands in
RDBMS were executed and verified.
EX.NO:2 DATA MANIPULATION AND DATA CONTROL LANGUAGE
(Insert, select, update and delete commands)
AIM:
To execute the Data Manipulation Language (DML) and Data Control Language (DCL) commands in
RDBMS.
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.
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.
Syntax: Select column_name1, …..,column_namen from table name where condition;
Select command with order by clause:
Syntax: Select column_name1, …..,column_namen from table name where condition order
by colmnname;
Select command to create a table:
Syntax: create table tablename as select * from existing_tablename;
Select command to insert records:
Syntax: insert into tablename ( select columns from existing_tablename);
UPDATE - It is used to alter the column values in a table. A single column may be updated or more
than one column could be updated.
DELETE - After inserting row in a table we can also delete them if required. The delete command
consists of a from clause followed by an optional where 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
Table created.
1 row created.
1 row created.
1 row created.
SQL> /
Enter value for pid: 4
Enter value for lastname: kumar
Enter value for firstname: Ashok
Enter value for address: Coimbatore
Enter value for age: 30
old 1: insert into person values(&pid,'&lastname','&firstname','&address',&age)
new 1: insert into person values(4,'kumar','Ashok','Coimbatore',30)
1 row created.
1 row created.
1 row created.
6 rows selected.
1 row updated.
1 row updated.
SQL> /
Enter value for address: Britain
Enter value for age: 55
Enter value for pid: 5
old 1: update person set address ='&address',age=&age where pid=&pid
new 1: update person set address ='Britain',age=55 where pid=5
1 row updated.
6 rows selected.
1 row created.
SQL> select * from person where lastname between 'Kumar' and 'Kumar';
LASTNAME
Benitto
Hinn
Kumar
Prakash
Prettina
Raj
6 rows selected.
1 Anne 14
2 Anish 24
3 Anita 27
4 Ashok 30
6 Bhaskar 40
7 Chander 45
5 Benny 55
7 rows selected.
Table created.
7 rows selected.
7 rows created.
PID
7
SQL> select count(distinct lastname) as pid from person;
PID
6
SQL> select max(age) from person;
MAX(AGE)
55
MIN(AGE)
14
SUM(AGE)
235
7 rows selected.
SQL> commit;
Commit complete.
DELETE COMMAND
2 rows deleted.
SQL> rollback;
Rollback complete.
SQL> select * from person;
7 rows selected.
Savepoint created.
7 rows deleted.
no rows selected
Rollback complete.
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 NESTED QUERIES AND JOINS
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.
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
Table created.
Table created.
SQL> create table work_in(pno number(3),eno number(3),pjob char(12));
Table created.
SQL> desc emp_det;
Name Null? Type
PNO NUMBER(3)
ENO NUMBER(3)
PJOB CHAR(12)
1 row created.
SQL> /
Enter value for eno: 2
Enter value for ename: Mahendran
Enter value for address: RainbowColony
Enter value for basic_sal: 5000
Enter value for job_status: Supervisor
Enter value for dno: 10
old 1: insert into emp_det values(&eno,'&ename','&address',&basic_sal,
'&job_status',&dno)
new 1: insert into emp_det values(2,'Mahendran','RainbowColony',5000,
'Supervisor',10)
1 row 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.
Table altered.
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)
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.
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.
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
Enter value for pjob: Analyst
old 1: insert into work_in values(&pno,&eno,'&pjob')
new 1: insert into work_in values(1,2,'Analyst')
1 row created.
SQL> /
Enter value for pno: 2
Enter value for eno: 2
Enter value for pjob: Programmer
old 1: insert into work_in values(&pno,&eno,'&pjob')
new 1: insert into work_in values(2,2,'Programmer')
1 row created.
1 1 Programmer
2 1 Analyst
1 2 Analyst
2 2 Programmer
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');
(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);
JOINS
Table created.
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.
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.
NAME SALARY
ashu 10000
asma 1200
asif 2000
arif 1000
niyas 3000
Table created.
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> /
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>/
1 row created.
NAME EMPID
fathi 12
sumi 32
priya 11
wahab 10
sweety 9
asma 1200
6 rows selected.
NATURAL JOIN
************
NAME SALARY
asma 1200
LEFT OUTER JOIN
****************
NAME EMPID
asma 1200
sweety 9
sumi 32
wahab 10
fathi 12
priya 11
6 rows selected.
FULL JOIN
***********
10 rows selected.
RESULT:
Thus the nested queries and join operations are executed and verifiedin DBMS.
EX.NO:4 VIEWS
AIM:
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.
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.
1 row created.
SQL> /
Enter value for name: cc
Enter value for number: 55
Enter value for edition: 342
Enter value for price: 76
Enter value for isbn: 687478
old 1: insert into aa values('&name',&number,&edition,&price,&ISBN)
new 1: insert into aa values('cc',55,342,76,687478)
1 row created.
SQL> /
Enter value for name: dd
Enter value for number: 2
Enter value for edition: 1233
Enter value for price: 123
Enter value for isbn: 53616578
old 1: insert into aa values('&name',&number,&edition,&price,&ISBN)
new 1: insert into aa values('dd',2,1233,123,53616578)
1 row created.
SQL> /
Enter value for name: ee
Enter value for number: 21
Enter value for edition: 1111
Enter value for price: 111
Enter value for isbn: 12435798
old 1: insert into aa values('&name',&number,&edition,&price,&ISBN)
new 1: insert into aa values('ee',21,1111,111,12435798)
1 row created.
TABLE 2 CREATION
*****************
SQL> create table qq(name varchar2(20),book number(10),author varchar(20),publisher varchar2(20),
ISBN number(20));
Table created.
1 row created.
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.
bb 21 23 dfd
573568
cc 43 55 fg
65839
ee 44 21 dfd
1235798
View created.
1 row updated.
View created.
cc 65839 fg
ee 1235798 dfd
oo 6358379 gfh
SQL> create view ss as select name,book from aa union select name,book from qq;
View created.
NAME BOOK
bb 21
bb 23
cc 43
cc 55
dd 2
ee 21
ee 44
oo 87
8 rows selected.
COMPLEX VIEW
*************
View created.
21 ee 1235798
34 oo 6358379
NAME
Cc
DROP VIEW
*************
SQL> drop view er;
View dropped
Result
AIM:
FUNCTION:
A function is a subprogram that computes a value. The syntax for creating a function is given
below
PROCEDURE:
Sample Output
Function created.
*********FUNCTION USING WHILE STATEMENT *************
Function created.
SQL>begin
2 dbms_output.put_line('the factorial='||fact(&a));
3* end;
SQL> /
Enter value for a: 4
old 2: dbms_output.put_line('the factorial='||fact(&a))
new 2: dbms_output.put_line('the factorial='||fact(4));
the factorial=24
SQL> declare
2 n number;
3 begin
4 n:=&n;
5 if(mod(n,2)=0)then
6 dbms_output.put_line(n||'is even');
7 else
8 dbms_output.put_line(n||'is odd');
9 end if;
10 end;
11 /
RESULT:
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.
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:
Alignment = how text aligns in the control
BackColor = choose the color of the background
Caption = the text that will appear in the control
Font = choose the font type and size
ForeColor = choose the color of the text (foreground)
As with all Windows applications, We can select multiple controls with (Ctrl)+(Click) and change a
property for all of them at once. For example, if all backgrounds are white, select all controls, change
ForeColor to white and all of them are modified. Change the form to look like the one below. Note that
you do not have to change the Caption for Label4, Label5 and Label6 and that you can't change the color
of the buttons. They insist on being what was called in the old days "IBM grey". Don't forget to save the
project often as you go along!
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:
PROCEDURE:
Table 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.
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
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:
Size
● Large
● Small
Exit
Steps to be followed:
AIM:
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.
Creating a Data Report
Once the Data Environment has been created, we can create a Data Report. We will drag things out of the
Data Environment onto a form created for the Data Report, so make sure your Data Environment window
is still available.
1. On the Project menu, click Add Data Report and one will be added to your project. If this item is not on
the menu, click Components. Click the Designers tab, and choose Data Report and click OK to add the
designer to your menu.
2. Set the following properties for the report:
Name - rptPhone
Caption - Phone Directory
DataSource - denPhone (your phone data environment - choose, don’t type)
DataMember - PhoneList (the table name - choose don’t type)
3. Right-click the Data Report and click Retrieve Structure. This establishes a report format based on
the Data Environment.
4. Note there are five sections to the data report: a Report Header, a Page Header, a Detail section, a Page
Footer, and a Report Footer. The headers and footers contain information you want printed in the report
and on each page. To place information in one of these regions, right-click the selected region, click Add
Control, then choose the control you wish to place. These controls are called data report controls and
properties are established just like you do for usual controls. Try adding some headers.
5. The Detail section is used to layout the information you want printed for each record in your database.
We will place two field listings (Name, Phone) there. Click on the Name tab in the Data Environment
window and drag it to the Detail section of the Data Report. Two items should appear: a text box Name
and a text box Name (PhoneList). The first text box is heading information. Move this text box into the
Page Header section. The second text box is the actual value for Name from the PhoneList table. Line this
text box up under the Name header. Now, drag the Phone tab from the Data Environment to the Data
Report. Adjust the text boxes in the same manner. Our data report will have page headers Name and
Phone. Under these headers, these fields for each record in our database will be displayed. When done, the
form should look something like this:
In this form, We’ve 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.
c) List all the bills for the current date with the customer
names and item numbers
d) List the total Bill details with the quantity sold, price of
the item and the final amount
Additional Programs
1. What is a database?
A DBMS is a complex software system that is used to manage, store and manipulate data and
metadata used to describe the data.
2. What is DBMS?
It is a collection of programs that enables user to create and maintain a database. In other words it
is general-purpose software that provides the users with the processes of defining, constructing and
manipulating the database for various applications.
3. What is a Database system?
The database and DBMS software together is called as Database system.
4. Advantages of DBMS.
Ø Redundancy is controlled.
Ø Unauthorised access is restricted.
Ø Providing multiple user interfaces.
Ø Enforcing integrity constraints.
Ø Providing backup and recovery.
5. Disadvantage in File Processing System
Ø Data redundancy & inconsistency.
Ø Difficult in accessing data.
Ø Data isolation.
Ø Data integrity.
Ø Concurrent access is not possible.
Ø Security Problems.
6. What is a key? what are different keys in database?
A Key is nothing but a attribute or group of attributes. They are used to perform some specific
operation depending on their operation. The keys are classified into primary key, secondary key,
alternative key, super key, candidate key, compound or concatenated or composite key.
7. What is a primary key?
A primary key is an attribute to identify a record uniquely is considered to be primary key. for eg
in the student table student_no is the primary key because it can be used to identify unique record
or unique student.
8. What is a secondary key?
An attribute used to identify a group of records satisfying a given condition is said to be a
secondary key. In the employee table, designation is a secondary key because more than one
employee can have the same designation.
9. What is a candidate key?
Register no usually allotted in the exams is also unique for each student in that case for identifying
a student uniquely either student_no or register_no can be used. Here two different candidates are
contesting for primary key post. Any of them can be selected as primary key.
10. What is an alternate key?
If any one of the candidate keys among the different candidate keys available is selected as
primary key then remaining keys are called alternate key.
11. What is a super key?
With primary key if any other attribute is added then that combination is called super key. In other
words, primary key is the minimum possible super key. In the student table student_no +
student_name is one of the super key.
12. What is a composite key?
If the primary key is combination of more than one key then it is called the composite key. In the
table called marks student_no + subject is the composite key.
13. What is a relation?
A Relation consists of a homogeneous set of tuples.
14. What is a table?
it is the representation of a relation having records as rows and attributes as columns.
15. What is an attribute?
An object or entity is characterized by its properties or attributes. In relational database systems
attributes corresponds to fields.
16. What is a domain?
The set of allowable value for the attribute is the domain of the attribute.
17. What is a tuple?
Tuples are the members of a relation. An entity type having attributes can be represented by set of
these attributes called tuple.
18. What is a selection?
An operation that selects only some of the tuples in the relation is known as selection operation.
The selection operation yields a horizontal subset of a given relation.
19. what is a join operation?
The join operation allows the combination of two relations to form a new relation.
20. What are base operations in relational algebra?
Union: - The term of the relation as performed by combining the tuples from one relation with
those of a second relation to produce a third relation. Duplicate tuples are eliminated. The relation
must be union compatible.
Difference: - The difference of two relations is a third relation having tuples that occur in the first
relation but not in the second relation.
Intersection: - The intersection operation selects the common tuples from the two relations.
cartesian product: - The cartesian product of two relations is the concatenation of tuples
belonging to the two relations. A new resultant scheme is created consisting of concatenation of all
possible combination of tuples.
21. What are different DBMS facilities? How many types of facilities are provided by a DBMS?
1) The data definition facility or data definition language(DDL)
2) The data manipulation facility or data manipulation language(DML)
3)The data control facility(DCL)
22. What is Data Definition Language?
Data scheme is specified by a set of definitions which are expressed b a special language called a
DDL.
23. What is Data Dictionary?
A Data Dictionary is a file that contains metadata i.e data about data. This file is consulted before
actual is read or modified in the database system.
24. What is a DML?
A DML is a language that enables users to access or manipulate data as organized by the
appropriate data model. There are basically two types:
1) procedural DML require a user to specify what data is needed and how to get it.
2) non procedural DML require a user to specify what data is needed without specifying how to get
it.
25. What is a query?
A query is a statement requesting the retrieval of information.
26. What is a query language?
The portion of DML that involves information retrieval is called a query language.
27. What are the advantages of DBMS?
Reduction of redundancies, Integrity, Security, Conflict resolution, Data independence, shared
data, Data quality enhanced.
28. What is a SQL?
Structured query language(sql) originated in 1974 at IBM.SQL is the data definition and
manipulation language.
29. What are the features of SQL?
Portability, client server architecture, dynamic data definition, multiple views of data, complete
data base language, interactive, high level structure and SQL standards.
30. How SQL organizes the data?
SQL organizes data as databases, tables, indexes, views.
31. What is data definition?
SQL lets a user to define the data structure and relationship at the stored data.
32. What is data retrieval?
Allows a user or an application program to retrieve the stored data.
33. What is data sharing?
Data can be shared by more than one user.
34. What is a view?
It is an object of SQL. A query can be defined, stored and named. This is called view.
35. What is normalization?
It is a process of analysing the given relation schemas based on their Functional Dependencies
(FDs) and primary key to achieve the properties
Ø Minimizing redundancy
Ø Minimizing insertion, deletion and update anomalies.
36. What is a first normal form?
A relation which contains no multi valued attributes.
37. What is a second normal form?
A relation is in second normal form for if it is first normal form and every non key attribute is fully
functionally dependent on primary key.
38. What is a third normal form?
A relation is in third normal form if for every functional dependency F :x->y is aDkey.
39. What is BCNF?
Boyce-code normal form.
40. What is fifth normal form?
A relation which eliminates join dependencies.
41. What is Functional Dependency?
A Functional dependency is denoted by X Y between two sets of attributes X and Y that are subsets
of R specifies a constraint on the possible tuple that can form a relation state r of R. The constraint
is for any two tuples t1 and t2 in r if t1[X] = t2[X] then they have t1[Y] = t2[Y]. This means the
value of X component of a tuple uniquely determines the value of component Y.
42. What is Lossless join property?
It guarantees that the spurious tuple generation does not occur with respect to relation schemas
after decomposition.
43. What are the commands to delete, modify and insert a record in the table?
DELETE, UPDATE, INSERT INTO.
44. What is time stamping?
In the time stamping based method, a serial order is created among the concurrent transactions by
assigning to each transaction a unique non decreasing numbers .you will be allocating fixed time
for each transaction.
45. What is data base schema?
It is the description of the database i.e its data structure and not the detail.
46. What is a self join?
Joining the table to the same table.
47. What are the different aggregate functions in SQL?
AVG(), MIN(), MAX(), COUNT(), SUM().
48. What is data integrity?
Data must satisfy the integrity constraints of the system.
49. What is data independence?
Data independence means that “the application is independent of the storage structure and access
strategy of data”. In other words, The ability to modify the schema definition in one level should
not affect the schema definition in the next higher level.
Two types of Data Independence:
Ø Physical Data Independence: Modification in physical level should not affect the logical level.
Ø Logical Data Independence: Modification in logical level should affect the view level.
NOTE: Logical Data Independence is more difficult to achieve
50. What is dead locking?
It is the situation where two transactions are waiting for other to release a lock on an item.
51. What is decryption?
Taking encoded text and converting it into text that you are able to read.
52. What is a distributed database?
A Database in which the datails contained within a number of separate subsystems usually in
different locations.
53. What is an entity?
it represents a real world object.
54. What is a conceptual data model?
A conceptual data model is concerned with the general description of the database without concern
for how the data may be organized.
55. What is two phase locking?
It is a most common mechanism that is used to control concurrency in two phases for achieving the
serializability. The two phases are Growing and Shrinking.
1) A transaction acquires locks on data items it will need to complete the transaction. This is called
growing phase. A transaction may obtain lock but may not release any lock.
2) One lock is released no other lock may be acquired. This is called shrinking process. A
transaction may release locks but may not obtain any new locks.
56. What is projection?
The projection of a relation is defined as projection of all its tuples over a set of attributes. it yields
vertical subset of the relation. The projection operation is used to trim the number of attributes in
the resultant relation or to reorder attributes.
57. What are the different phases of transaction?
Different phases are
Ø Analysis phase
Ø Redo Phase
Ø Undo phase
58. . What is Relational Algebra?
It is procedural query language. It consists of a set of operations that take one or two relations as
input and produce a new relation.
59. What is Relational Calculus?
It is an applied predicate calculus specifically tailored for relational databases proposed by E.F.
Codd. E.g. of languages based on it are DSL ALPHA, QUEL.
60. . How does Tuple-oriented relational calculus differ from domain-oriented relational
calculus The tuple-oriented calculus uses a tuple variables i.e., variable whose only permitted
values are tuples of that relation. E.g. QUEL
The domain-oriented calculus has domain variables i.e., variables that range over the underlying
domains instead of over relation. E.g. ILL, DEDUCE.