Lab Manual
Lab Manual
Lab Manual
ENGINEERING COLLEGE
EXNO :1A
DATE :
CREATION OF A DATA DEFINITION COMMANDS
AIM:
To create a database and to write SQL queries to retrieve information from the database in
RDBMS.
CREATE TABLE
Rules:
1. Oracle reserved words cannot be used.
2. Underscore, numerals, letters are allowed but not blank space.
3. Maximum length for the table name is 30 characters.
4. Different tables should not have same name.
5. We should specify a unique column name.
6. We should specify proper data type along with width.
Syntax:
SQL>Create table tablename (column_name1 data_ type constraints, column_name2 data_ type
constraints …)
Example:
SQL>Create table emp( empno number(5), ename VarChar(15), job VarChar(10), deptno
number(3) ,sal number(5));
SQL>Create table stud(sname varchar(20) , rollno number(10) not null,dob date);
DESC
1
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Insert more than a record into emp table using a single insert command.
2
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
ENAME JOB
----------- -------------
Mathi AP
Arjun ASP
Gugan ASP
Karthik Prof
Akalya AP
5 rows selected.
RESULT
Thus the database is created and the information is retrieved using SQL queries in RDBMS.
3
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO :1B
DATE:
PERFORMING INSERTION, DELETION, MODIFYING, ALTERING, UPDATING
AND VIEWING RECORDS BASED ON CONDITIONS.
AIM:
Create table:
INSERT COMMAND
Insert more than a record into emp table using a single insert command.
ALTER COMMAND
ADD COMMAND
Syntax:
5
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Example:
MODIFY COMMAND
Example:
UPDATE COMMAND
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.
Syntax:
SQL>update tablename set field=values where condition;
Example:
SQL>update persons set phoneno = 999999999 where empno=100;
Select Commands
It is used to retrieve information from the table.it is generally referred to as querying the
table.We can either display all columns in a table or only specify column from the table.
Syntax:
SQL> Select * from tablename; // This query selects all rows from the table.
Example:
6
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
PID FIRSTNAME
---------- --------------------
001 nelson
100 niranjan
102 arjun
300 gugan
500 prabhu
Example:
SQL>Select DISTINCT lastname from persons;
LASTNAME
---------------------
raj
kumar
chand
To select specific rows from a table we include ‘where’ clause in the select command. It
can appear only after the ‘from’ clause.
7
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
FIRSTNAME LASTNAME
----------------------------------------------
nelson raj
niranjan kumar
arjun kumar
gugan chand
prabhu
Example:
FIRSTNAME LASTNAME
-------------------- -----------------------
nelson raj
niranjan kumar
arjun kumar
gugan chand
prabhu
Syntax:
Example:
SQL>create table persons1 as select * from persons;
Table created
8
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Example: SQL>Select * from persons where pid between 100 and 500;
9
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
PERSONID
-----------------
001
100
DROP TABLE
TRUNCATE TABLE
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.
DELETE COMMAND
10
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
TCL COMMANDS:
Syntax:
Example:
1 row created.
11
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
SQL> COMMIT;
Commit complete.
Grant :
Syntax:
GRANT privilege_name ON object_name TO {user_name |PUBLIC |role_name} [WITH
GRANT OPTION];
Example :
Revoke :
Syntax :
SQL> revoke privilege_name on object_name from {user_name|public|role_name}
Example:
RESULT:
Thus the database has been created and the data has been inserted, deleted, modified, altered,
updated and records are viewed based on conditions.
12
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO :2
DATE:
SIMPLE QUERIES, NESTED QUERIES, SUB QUERIES AND JOINS
AIM:
Nested Queries:
Example:
SQL> select empno,ename,job from emp where sal>(select sal from emp where ename=
'arjun');
The query within another is known as a subquery. A statement containing subquery is called
parent statement. The rows returned by subquery are used by the parent statement.
SQL> select ename,sal from emp where sal>(select min(sal) from emp where job like 'A%');
ENAME SAL
--------------- ----------
mathi 12000
arjun 12000
yuva 20000
ganesh 30000
13
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Example:
SQL> select ename, eno, from employee where salary <any (select salary from employee where
deptno =1);
Correlated subquery
A subquery is evaluated once for the entire parent statement whereas a correlated subquery is
evaluated once per row processed by the parent statement.
Example:
select * from emp x where x.salary > (select avg(salary) from emp where deptno =x.deptno);
The purpose of a join concept is to combine data spread across tables. A join is actually
performed by the ‘where’ clause which combines specified rows of tables.
Syntax:
Types of Joins
1. Simple Join
2. Self Join
3. Outer Join
1.Simple Join
It is the most common type of join. It retrieves the rows from 2 tables having a common
column and is further classified into
14
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
a) Equi-join
Example:
In the above statement, item-id = cust-id performs the join statement. It retrieves rows from both
the tables provided they both have the same id as specified by the where clause. Since the where
clause uses the comparison operator (=) to perform a join, it is said to be equijoin. It combines
the matched rows of tables.
b) Non Equi-join
It specifies the relationship between columns belonging to different tables by making use of
relational operators other than’=’.
Example:
Table Aliases
Table aliases are used to make multiple table queries shorted and more readable. We give an
alias name to the table in the ‘from’ clause and use it instead of the name throughout the query.
15
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
2.Self join
Joining of a table to itself is known as self-join. It joins one row in a table to another. It can
compare each row of the table to itself and also with other rows of the same table.
Example:
select * from emp x ,emp y where x.salary >= (select avg(salary) from x.emp where x. deptno
=y.deptno);
3.Outer Join
It extends the result of a simple join. An outer join returns all the rows returned by simple join as
well as those rows from one table that do not match any row from the table. The symbol(+)
represents outer join.
Example:
select ename, job, dname from emp, dept where emp.deptno (+) =dept.deptno;
Before we continue with examples, we will list the types the different SQL JOINs you can use:
INNER JOIN: Returns all rows when there is at least one match in BOTH tables
LEFT JOIN: Return all rows from the left table, and the matched rows from the right
table
RIGHT JOIN: Return all rows from the right table, and the matched rows from the left
table
FULL JOIN: Return all rows when there is a match in ONE of the tables
The INNER JOIN keyword selects all rows from both tables as long as there is a match between
the columns in both tables.
Syntax:
Outer Join
It extends the result of a simple join. An outer join returns all the rows returned by simple join as
well as those rows from one table that do not match any row from the table. The symbol(+)
represents outer join.
The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no
matches in the right table (table_name2)
(OR)
17
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are
no matches in the left table (table_name1).
(OR)
FULL JOIN
The FULL JOIN keyword return rows when there is a match in one of the tables.
UNION OPERATOR
The union operator is used to combine the result set of two or more select statements.
1) Union
2) Union all
SYNTAX:
SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2.
EXAMPLE
Name
--------
Sara
Meena
Raji
Roja
Name
--------
Sara
Meena
Meera
Raji
19
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Roja
Sabari
Name
--------
Sara
Meera
Meena
Sabari
Sara
Meena
Raji
Roja
MINUS
Name
--------
Meera
Sabari
INTERSECT
Name
--------
Meena
Sara
RESULT:
Thus the creating relationship between the databases have be done successfully.
20
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO :3
DATE:
AIM:
To create Views ,Synonyms ,sequences commands in database using SQL queries in RDBMS.
CREATING VIEWS:
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.
Syntax
Example:
Updating a View
View can be updated. If view is already created with same name it will be replaced by create or
replace statement (or) if view already doesn’t exist, it will be created.
21
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Syntax
SQL> create or replace view emp1 as select * from emp where salary>10000;
View created
Dropping a View
CREATING SYNONYMS
Syntax :
Drop synonym
Syntax :
example:
22
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
SEQUENCES
In Oracle, you can create an auto number field by using sequences. A sequence is an
object in Oracle that is used to generate a number sequence. This can be useful when you need to
create a unique number to act as a primary key.
CREATING SEQUENCES
Syntax
Example:
CREATE SEQUENCE emp_seq
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
This would create a sequence object called supplier_seq. The first sequence number that it would
use is 1 and each subsequent number would increment by 1 (ie: 2,3,4,...}. It will cache up to 20
values for performance.
Drop Sequence
Once you have created your sequence in Oracle, you might find that you need to remove it from
the database.
23
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Syntax
Example
CREATING INDEX
An index can be created in a table to find data more quickly and efficiently.The users cannot see
the indexes, they are just used to speed up searches/queries.Creates an index on a table.
Duplicate values are allowed
Example
The SQL statement below creates an index named "PIndex" on the "LastName" column in the
"Persons" table:
SQL>create index PIndex ON Persons (LastName);
If you want to create an index on a combination of columns, you can list the column names
within the parentheses, separated by commas:
SQL>create index PIndex ON Persons (LastName, FirstName);
RESULT:
Thus Views, Synonyms, Sequence have been created and updated in RDBMS.
24
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO :4
DATE:
IMPLICIT AND EXPLICIT CURSORS
AIM:
To study and execute the Implicit and Explicit Cursors using PL/SQL.
PL/SQL Cursor
When an SQL statement is processed, Oracle creates a memory area known as context area. A
cursor is a pointer to this context area. It contains all information needed for processing the
statement. In PL/SQL, the context area is controlled by Cursor. A cursor contains information on
a select statement and the rows of data accessed by it.
A cursor is used to referred to a program to fetch and process the rows returned by the SQL
statement, one at a time. There are two types of cursors:
Implicit Cursors
Explicit Cursors
The implicit cursors are automatically generated by Oracle while an SQL statement is executed,
if you don't use an explicit cursor for the statement.
These are created by default to process the statements when DML statements like INSERT,
UPDATE, DELETE etc. are executed.
Orcale provides some attributes known as Implicit cursor's attributes to check the status of DML
operations. Some of them are: %FOUND, %NOTFOUND, %ROWCOUNT and %ISOPEN.
For example: When you execute the SQL statements like INSERT, UPDATE, DELETE then
the cursor attributes tell whether any rows are affected and how many have been affected. If you
run a SELECT INTO statement in PL/SQL block, the implicit cursor attribute can be used to find
out whether any row has been returned by the SELECT statement. It will return an error if there
no data is selected.
The following table soecifies the status of the cursor with each of its attribute.
Attribute Description
Its return value is TRUE if DML statements like INSERT, DELETE and
%FOUND UPDATE affect at least one row or more rows or a SELECT INTO statement
returned one or more rows. Otherwise it returns FALSE.
Its return value is TRUE if DML statements like INSERT, DELETE and
%NOTFOUND
UPDATE affect no row, or a SELECT INTO statement return no rows.
25
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Example
Let's execute the following program to update the table and increase salary of each customer by
5000. Here, SQL%ROWCOUNT attribute is used to determine the number of rows affected:
Create procedure:
DECLARE
total_rows number(2);
BEGIN
UPDATE customers
SET salary = salary + 5000;
IF sql%notfound THEN
dbms_output.put_line('no customers updated');
ELSIF sql%found THEN
total_rows := sql%rowcount;
dbms_output.put_line( total_rows || ' customers updated ');
26
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
END IF;
END;
/
Output:
6 customers updated
PL/SQL procedure successfully completed.
Explicit Cursors
The Explicit cursors are defined by the programmers to gain more control over the context area.
These cursors should be defined in the declaration section of the PL/SQL block. It is created on a
SELECT statement which returns more than one row.
Following is the syntax to create an explicit cursor:
Syntax of explicit cursor
Steps:
You must follow these steps while working with an explicit cursor.
It defines the cursor with a name and the associated SELECT statement.
CURSOR name IS
SELECT statement;
It is used to allocate memory for the cursor and make it easy to fetch the rows returned by the
SQL statements into it.
OPEN cursor_name;
It is used to access one row at a time. You can fetch rows from the above-opened cursor as
follows:
It is used to release the allocated memory. The following syntax is used to close the above-
opened cursors.
Close cursor_name;
Explicit cursors are defined by programmers to gain more control over the context area. It is
defined in the declaration section of the PL/SQL block. It is created on a SELECT statement
which returns more than one row.
28
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Let's take an example to demonstrate the use of explicit cursor. In this example, we are using the
already created CUSTOMERS table.
Create procedure:
Execute the following program to retrieve the customer name and address.
DECLARE
c_id customers.id%type;
c_name customers.name%type;
c_addr customers.address%type;
CURSOR c_customers is
SELECT id, name, address FROM customers;
BEGIN
OPEN c_customers;
LOOP
FETCH c_customers into c_id, c_name, c_addr;
EXIT WHEN c_customers%notfound;
dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);
END LOOP;
CLOSE c_customers;
END;
/
Output:
1 Ramesh Allahabad
2 Suresh Kanpur
3 Mahesh Ghaziabad
4 Chandan Noida
5 Alex Paris
6 Sunita Delhi
PL/SQL procedure successfully completed.
29
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO :5
DATE:
CREATION OF PROCEDURES AND FUNCTIONS
AIM:
To study and execute the procedures and functions using control structures in PL/SQL.
PL/SQL :
A procedure is a block that can take parameters (sometimes referred to as arguments) and be
invoked. Procedures promote reusability and maintainability. Once validated, they can be used in
number of applications. If the definition changes, only the procedure are affected, this greatly
simplifies maintenance. Modularized program development: · Group logically related statements
within blocks. · Nest sub-blocks inside larger blocks to build powerful programs. · Break down a
complex problem into a set of manageable well defined logical modules and implement the
modules with blocks.
SYNTAX:
PROCEDURES :
create or replace procedure <procedure name> (argument {in,out,inout} datatype ) {is,as}
variable declaration;
constant declaration;
begin PL/SQL subprogram body;
30
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Tables used:
SQL> select * from ititems;
Procedure created.
SQL> exec itsum(101, 500);
PL/SQL procedure successfully completed.
31
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Procedure created.
Procedure created.
SQL> declare
2 a number;
3 b number;
4 begin
5 zzz(101,b);
6 dbms_output.put_line('The value of b is '|| b);
7 end;
8/
32
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
SQL> declare
2 a number:=7;
3 begin
4 itit(a);
5 dbms_output.put_line(„The updated value is „||a);
6 end;
7/
FUNCTIONS:
SYNTAX:
create or replace function <function name> (argument in datatype,……) return datatype {is,as}
variable declaration;
constant declaration;
begin PL/SQL subprogram body;
exception exception PL/SQL block;
end;
Function created.
SQL> declare
33
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
2 total number;
3 begin
4 total:=trainfn (1001);
5 dbms_output.put_line('Train fare is Rs. '||total);
6 end;
7/
Function created.
SQL> declare
2 a number:=7;
3 f number(10);
4 begin
5 f:=itfact(a);
6 dbms_output.put_line(„The factorial of the given number is‟||f);
7 end;
8/
The factorial of the given number is 5040
RESULT:
Thus the procedures and functions using control structures were studied and executed in
PL/SQL.
34
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO : 6
DATE:
CREATION OF DATABASE TRIGGERS
AIM:
To study and execute Triggers in RDBMS
TRIGGER
A Trigger is a stored procedure that defines an action that the database automatically take when
some database-related event such as Insert, Update or Delete occur.
35
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
These are used for generating/checking the These are used for generated the summary
values begin inserted or updated. information.
Create a trigger that insert current user into a username column of an existing table
SQL> create table itstudent4(name varchar2(15),username varchar2(15));
Table created.
SQL> create or replace trigger itstudent4 before insert on itstudent4 for each row
2 declare
3 name varchar2(20);
4 begin
5 select user into name from dual;
6 :new.username:=name;
7 end;
8/
Trigger created.
Output:
SQL> insert into itstudent4 values('&name','&username');
Enter value for name: akbar
Enter value for username: ranjani
old 1: insert into itstudent4 values('&name','&username')
new 1: insert into itstudent4 values('akbar','ranjani')
1 row created.
SQL> /
Enter value for name: suji
Enter value for username: priya
old 1: insert into itstudent4 values('&name','&username')
36
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
NAME USERNAME
--------------- ---------------
akbar SCOTT
suji SCOTT
Create a Simple Trigger that does not allow Insert Update and Delete Operations on the
Table
Table used:
SQL> select * from itempls;
Trigger:
SQL> create trigger ittrigg before insert or update or delete on itempls for each row
2 begin
3 raise_application_error(-20010,'You cannot do manipulation');
4 end;
5/
Trigger created.
Output:
SQL> insert into itempls values('aaa',14,34000);
insert into itempls values('aaa',14,34000)
*
ERROR at line 1:
ORA-20010: You cannot do manipulation ORA-06512:at"STUDENT.ITTRIGG", line 2
ORA-04088: error during execution of trigger 'STUDENT.ITTRIGG'
SQL> delete from itempls where ename='xxx';
delete from itempls where ename='xxx'
*
ERROR at line 1:
ORA-20010: You cannot do manipulation
37
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
RESULT:
Thus the creation of triggers for various events such as insertion, updation, etc., was created,
performed and executed successfully.
38
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO :7
DATE:
PL/SQL BLOCK HANDLES ALL TYPES OF EXCEPTIONS
AIM:
PL/SQL - EXCEPTIONS
System-defined exceptions
User-defined exceptions
The General Syntax for exception handling is as follows. Here you can list down as many as
exceptions you want to handle. The default exception will be handled using WHEN others
THEN:
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
WHEN exception3 THEN
exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements
END;
39
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Example
SQL> create table customer(custid number(5),name varchar(20),address varchar(30));
DECLARE
c_id customer.custid%type := 10;
c_name customer.name%type;
c_addr customer.address%type;
BEGIN
SELECT name, address INTO c_name, c_addr
FROM customer
WHERE custid = c_id;
OUTPUT
No such customer!
PL/SQL procedure successfully completed.
Raising Exceptions
Exceptions are raised by the database server automatically whenever there is any internal
database error, but exceptions can be raised explicitly by the programmer by using the command
RAISE. Following is the simple syntax of raising an exception:
DECLARE
exception_name EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;
40
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
User-defined Exceptions
PL/SQL allows you to define your own exceptions according to the need of your program. A
user-defined exception must be declared and then raised explicitly, using either a RAISE
statement or the procedure DBMS_STANDARD.RAISE_APPLICATION_ERROR.
DECLARE
my-exception EXCEPTION;
Example:
This program asks for a customer ID, when the user enters an invalid ID, the exception
invalid_id is raised.
DECLARE
c_id customer.custid%type :=&cc_id;
c_name customer.name%type;
c_addr customer.address%type;
41
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
OUTPUT:
RESULT:
Thus the PL/SQL block is created to handle all types of exceptions and are well executed.
42
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO : 8
DATE:
Normalization
minimizing redundancy
A normal form is a state of a table that results from applying simple rules regarding functional
dependencies to that table.The various types of normal form are:
First Normal Form(1NF): The multi-valued should be removed i.e elimination of redundant
groups.
Second Normal Form(2NF): The partial functional dependencies have to be removed i.e
elimination of redundant data.
Third Normal Form(3NF): The transitive dependencies have to be removed i.e elimination of
columns not dependent on the key.
Boyce-Codd Normal Form(BCNF): The remaining anomalies that result from functional
dependencies are removed.
43
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Fifth Normal Form(5NF): Any remaining anomalies are removed.Here we isolate semantically
related multiple relationships.
1NF states that the domain of an attribute must include only atomic
(simple,indivisible) values and that value of any attribute in a tuple must be a single value from the
domain of that attribute.Hence 1NF disallows multi-valued attributes,composite attributes.It disallows
“relations
within relations”.
A relation is said to be in 2NF if it is already in 1NF and it has no partial dependency. 2NF is
based on the concept of full functional dependency.
A functional dependency(FD) XY is full functional dependency if (X-(A))Y does not hold
dependency any more if AX.
A functional dependency XY is partial dependency if A can be removed which does not affect the
dependency i.e. (X-(A))Y holds.
A relation is in 2NF if it is in 1NF and every non-primary key attribute is fully and functionally
dependent on primary key.
A relation in the 1NF will be in the 2NF if one of the following conditions is satisfied:
The primary key consist of only one attribute.
No non-key attribute exist in relation i.e. all the attributes in the relation are components of the primary
key.
44
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Procedure:
To convert a table to 1NF removes all the multi valued & composite attributes
from the table.
i) Find and remove attributes that are functionally dependent on only a part
of the key and not on the whole key. Place them in a different
table.Group the remaining attributes.
FIRST NORMAL FORM:
Type created.
45
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
SQL> /
Table created.
1 row created.
SQL> /
Enter value for eno: 002
Enter value for enmae: balu
Enter value for sno: 13
Enter value for sname: car street
Enter value for city: madurai
Enter value for state: tamilnadu
Enter value for sal: 10000
old 1: insert into employees values(&eno,'&enmae',address(&sno,'&sname','&city','&state'),&sal)
new 1: insert into employees values(002,'balu',address(13,'car street','madurai','tamilnadu'),10000)
1 row created.
SQL> /
Enter value for eno: 003
Enter value for enmae: chiru
Enter value for sno: 10
Enter value for sname: 9th street
46
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
1 row created.
SQL> create table en1 as select eno, ename ,sal from employees;
Table created.
Table altered.
Table created.
Table altered.
47
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Normalizing to 1NF:
employee
1NF
Emp1 emp2
Eno eadd
Eno Ename Sal
Table created.
48
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
1 row created.
SQL> /
Enter value for eno: 102
Enter value for ename: ragu
Enter value for pno: 13
Enter value for pname: atm
Enter value for hours: 24
old 1: insert into empproject values(&eno,'&ename',&pno,'&pname',&hours)
new 1: insert into empproject values(102,'ragu',13,'atm',24)
1 row created.
SQL> /
Enter value for eno: 103
Enter value for ename: sunil
Enter value for pno: 14
Enter value for pname: robotics
Enter value for hours: 15
old 1: insert into empproject values(&eno,'&ename',&pno,'&pname',&hours)
new 1: insert into empproject values(103,'sunil',14,'robotics',15)
1 row created.
49
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Table created.
Table altered.
Table created.
Table altered.
Table created.
50
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Table altered.
Table altered.
Normalizing to 2NF:
2NF
Ep1
eno Ename
Ep2
Pname
pno
Ep3
pno Hours
eno
Table created.
51
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
1 row created.
SQL> /
Enter value for eno: 102
Enter value for ename: ragu
Enter value for sal: 20000
Enter value for dno: 2
Enter value for dname: eee
old 1: insert into empdept values(&eno,'&ename',&sal,&dno,'&dname')
new 1: insert into empdept values(102,'ragu',20000,2,'eee')
1 row created.
52
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Table created.
Table altered.
Table altered.
53
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Normalizing to 3NF:
Empdept
3NF
Ed1
eno sal dno
ename
Ed2
Dname
Dno
Result:
54
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO : 9
DATE:
AIM:
To Create Document, column and graph based data using NOSQL database tools.
{
"_id": 1,
"first_name": "Tom",
"email": "tom@example.com",
"cell": "765-555-5555",
"likes": [
"fashion",
"spas",
"shopping"
],
"businesses": [
{
"name": "Entertainment 1080",
"partner": "Jean",
"status": "Bankrupt",
"date_founded": {
"$date": "2012-05-19T04:00:00Z"
}
},
{
"name": "Swag for Tweens",
"date_founded": {
"$date": "2012-11-01T04:00:00Z"
}
}
]
}
"_id": 2,
"first_name": "Donna",
"email": "donna@example.com",
"spouse": "Joe",
"likes": [
55
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
"spas",
"shopping",
"live tweeting"
],
"businesses": [
{
"name": "Castle Realty",
"status": "Thriving",
"date_founded": {
"$date": "2013-11-21T04:00:00Z"
}
}
]
}
Users
Likes
ID user_id like
10 1 fashion
11 1 spas
12 1 shopping
Businesses
RESULT:
Thus the Document, column and graph based data using NOSQL database tools is successfully
completed.
56
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO : 10 a)
DATE:
AIM:
To develop a personal information system using Oracle as a back end (data base) and
Microsoft Visual Basic 6.0 as a Front end.
PROCEDURE:
TABLE DESIGN:
Name Type
----------------------------------- ---------------------------
EMPNO NUMBER(6)
EMPNAME VARCHAR2(30)
ADDRESS VARCHAR2(20)
BASIC NUMBER(8,2)
57
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Form :
Dim db As Database
Dim rs As Recordset
58
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
59
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
End Sub
Private Sub NEXT_Click()
rs.MoveNext
If rs.EOF Then
MsgBox "NO MORE RECORDS"
Else
Text1.Text = rs(0)
Text2.Text = rs(1)
Text3.Text = rs(2)
Text4.Text = rs(3)
End If
End Sub
Private Sub PREVIOUS_Click()
rs.MovePrevious
If rs.BOF Then
MsgBox ("No more records")
Else
Text1.Text = rs(0)
Text2.Text = rs(1)
Text3.Text = rs(2)
Text4.Text = rs(3)
End If
End Sub
Private Sub UPDATE_Click()
rs.Edit
rs(0) = Text1.Text
rs(1) = Text2.Text
rs(2) = Text3.Text
rs(3) = Text4.Text
rs(4) = Text5.Text
rs.UPDATE
End Sub
60
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Form :
RESULT:
Thus personal information system was developed using Visual Basic as front end and
ORACLE as back end.
61
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO : 10 b)
PROCEDURE:
1. Create a bank database with the following fields in MS Access namely acno, name,
address, balance and insert some record into the database.
2. Design the corresponding form with labels ,text boxes and command buttons.
3. Connect the back end with the front end using DAO method by creating a dsn as follows
a) Select control panel ->system and security - > choose Administrative Tools option
b) Then double click on Data Sources (ODBC), which displays a dialog box named
ODBC Data Source Administrator in which click Add button.
c) In Create New Data Source dialog box, select “Microsoft Access Driver
(*.mdb,*.accdb) click finish button.
d) Give a suitable DataSourceName =bankdsn, and click on select option choose
your database location “c:\users\secit10\documents” and choose your table which
appearsOKOK
4. And then click OK and now move to visual basic 6.0
5. Go to ‘Project’ then click ’reference’ in menu bar and select “Microsoft DAO 3.6 Object
Library” and then give OK.
6. Go to ‘Project’ then click ’components’ in menu bar and select “Microsoft ADO Data
Control 6.0 (OLEDB) ” and also choose Microsoft Data Grid Control 6.0(OLEDB)
ApplyOK.
7. Choose adodc and place on form2 and also choose datagrid control and place it on form2
8. Now click on adodc1 goto property window choose connection stringclick 2nd option use
connection string click buildby default Microsoft OLEDB provider for ODBC Driver will be
choosedclick nextchoose machine datasourceclick newclick user datasourcenext
Microsoft access driver(*.md,*.accdb) nextfinish
9. Click testconnectiontest connection succeedok3.enter the initial catalog to use-choose
your tableokapply
10. Choose 3rd option recordsource in cmd text of SQLtype “select * from bank;” ok
11. Click text1.text properties will be openeddatasourceadodc1 and also in data
fieldchoose the appropriate field.
12. Now give coding and execute the program
62
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
FORM 1:
FORM 2:
FORM 3:
63
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
FORM 4:
64
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
FORM 1:
65
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
FORM 2:
FORM 3:
66
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
FORM 4:
RESULT:
Thus the application banking system has been designed and implemented in visual basic.
67
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
EXNO : 10 C
DATE:
To design and implement the application, ‘Hospital management system’ using MS Access as a
back end (data base) and Microsoft Visual Basic 6.0 as a Front end.
PROCEDURE:
68
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
FORM 1:
FORM 2:
FORM 3:
Dim DB As Database
Dim RS As Recordset
FORM 4 :
Dim DB As Database
Dim RS As Recordset
Set db = OpenDatabase("C:\Users\Administrator\Documents\staff.mdb")
Set rs = db.OpenRecordset("staff", dbOpenDynaset)
End Sub
End Sub
71
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Form 1:
Form 2:
72
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Form 3:
73
IT1402 DBMS LAB S.A.ENGINEERING COLLEGE
Form 4 :
RESULT:
Thus the application hospital management system has been designed and implemented in visual
basic.
74