0% found this document useful (0 votes)
10 views12 pages

DBMS Lab MANUAL

The document discusses creating and manipulating databases and tables in Oracle using SQL commands. It covers topics like CREATE, INSERT, SELECT, UPDATE, DELETE commands and creating relationships between tables. It also discusses PL/SQL including blocks, procedures, functions, triggers and exception handling.

Uploaded by

hariab5641
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

DBMS Lab MANUAL

The document discusses creating and manipulating databases and tables in Oracle using SQL commands. It covers topics like CREATE, INSERT, SELECT, UPDATE, DELETE commands and creating relationships between tables. It also discusses PL/SQL including blocks, procedures, functions, triggers and exception handling.

Uploaded by

hariab5641
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Ex.No.

1 CREATION OF A DATABASE AND WRITING SQL QUERIES TO RETRIEVE


INFORMATION FROM THE DATABASE.

AIM:

To design and implement a database in Oracle using Structured Query Language commands

SYNTAX:

CREATE:

Create table <table name> (column name1 datatype1 constraints, column2 datatype2 . . .);

PROBLEM STATEMENT:

 A branch contain many account holder

 A branch provide more than one Loan

 A Loan can be availed by more than customer.

 A customer can get more than one Loan.

 A customer can have more than one account

 A account can have more than one customer

TABLE FROM THE PROBLEM STATEMENT

1) Branch

2) Account

3) Loan

4) Customer
Ex.No.2 PERFORMING INSERTION, DELETION, MODIFYING, ALTERING, UPDATING AND
VIEWING RECORDS BASED ON CONDITIONS.

AIM:

To implement and execute a query for manipulating & storing data items in a Oracle database using
Structured Query Language commands

DDL COMMANDS:
 Create
 Alter
 Add
 Modify
 Drop
 Rename
 Drop
ALTER:
ADD:
Alter table <table name> add(column name1 datatype1);
MODIFY:
Alter table <table name> modify(column name1 datatype1);
DROP:
Alter table <table name> drop (column name);
RENAME:
Rename <old table name> to <new table name>;
DROP:
Drop table <table name>;
DML Commands:
 Insert
 Select
 Update
 Delete
INSERT:
Insert into <table name> values (‘attributes1’, ’attributes2’……);
SELECT:
Select <column name> from <table name>;
UPDATE:
Update <table name> set <column name>=’values’;
DELETE:
Delete from <table name>;
Ex.No.3 CREATION OF VIEWS, SYNONYMS, SEQUENCE, INDEXES, SAVE POINT.

AIM:

To implement and execute view, synonyms, sequence, indexes, savepoint in Oracle using Structured
Query Language commands

SYNTAX:

VIEWS:

CREATE VIEW <VIEWNAME> AS SELECT * FROM <TABLENAME> WHERE <CONDITION>;

SYNONYMS

CREATE SYNONYM <SYNONYMS NAME> FOR <TABLENAME>;

SEQUENCE

CREATE SEQUENCE<SEQUENCENAME> START WITH <VALUE> MINVALUE <VALUE>


INCREMENT BY <VALUE>;

INDEXES

CREATE [UNIQUE] INDEX INDEX_NAME ONTABLE_NAME(COLUMN_NAME[, COLUMN_NAM


E...]) TABLESPACE TABLE_SPACE;

SAVE POINT

SAVEPOINT <SAVEPOINT NAME>;


Ex.No.4 CREATING A STUDENT DATABASE TO SET VARIOUS CONSTRAINTS.

AIM:

To Creating a Student database to set various constraints in Oracle using Structured Query Language
commands

VARIOUS CONSTRAINTS

Constraint
Constraint Meaning
Type
CHECK C Specifies a certain condition for a column, or group of columns.
NOT NULL C Not null column
PRIMARY KEY P primary key
FOREIGN KEY R foreign key
UNIQUE U unique
CHECK Specifies that DML operations on a view must satisfy the sub
V
OPTION query.
READ ONLY O Specifies that a view may only be read from.

TABLE NAME: STDUDENTDB

Column name Data Type Constraint


STUDENT_NO NUMBER PRIMARY KEY
STUDENT_NAME VARCHAR2(30) NOT NULL
STUDENT_EMAIL VARCHAR2(30) UNIQUE
STUDENT_PERCENTAGE NUMBER CHECK
Ex.No.5 CREATING RELATIONSHIP BETWEEN THE DATABASES.

AIM:

To Creating relationship between the databases in Oracle using Structured Query Language
commands
RULES FOR CREATING RELATIONSHIP BETWEEN THE DATABASES

BINARY 1:N & N:1

TERNARY

BINARY N:M

UNARY 1:1 UNARY 1:N &N:1 UNARY N:M


PROBLEM STATEMENT:

 A branch contain many account holder

 A branch provide more than one Loan

 A Loan can be availed by more than customer.

 A customer can get more than one Loan.

 A customer can have more than one account

 A account can have more than one customer


Ex.No.6 STUDY OF PL/SQL BLOCK

AIM:

TO STUDY THE WORKING PRINCIPLES OF PL/SQL BLOCK


PL/SQL Block consists of three sections:

 The Declaration section (optional).


 The Execution section (mandatory).
 The Exception (or Error) Handling section (optional).

Declaration Section:
The Declaration section of a PL/SQL Block starts with the reserved keyword DECLARE. This
section is optional and is used to declare any placeholders like variables, constants, records and cursors,
which are used to manipulate data in the execution section. Placeholders may be any of Variables, Constants
and Records, which stores data temporarily. Cursors are also declared in this section.

Execution Section:
The Execution section of a PL/SQL Block starts with the reserved keyword BEGIN and ends with
END. This is a mandatory section and is the section where the program logic is written to perform any task.
The programmatic constructs like loops, conditional statement and SQL statements form the part of
executionsection.

Exception Section:
The Exception section of a PL/SQL Block starts with the reserved keyword EXCEPTION. This
section is optional. Any errors in the program can be handled in this section, so that the PL/SQL Blocks
terminates gracefully. If the PL/SQL Block contains exceptions that cannot be handled, the Block terminates
abruptly with errors. Every statement in the above three sections must end with a semicolon; PL/SQL
blocks can be nested within other PL/SQL blocks. Comments can be used to document code.
Ex.No.7 WRITE A PL/SQL BLOCK TO SATISFY SOME CONDITIONS BY ACCEPTING
INPUT FROM THE USER.

AIM:

Write a PL/SQL block to satisfy some conditions by accepting input from the user using oracle

SYNTAX

DECLARE
Variable declaration
BEGIN
Program Execution
EXCEPTION
Exception handling
END;
Ex.No.8 WRITE A PL/SQL BLOCK THAT HANDLES ALL TYPES OF EXCEPTIONS.

AIM:

To implement and execute PL/SQL Block that handles all types of exceptions in Oracle Database
using Procedural Language concepts.

EXCEPTIONS:

In PL/SQL, the user can catch certain runtime errors. Exceptions can be internally defined by Oracle
or the user. Exceptions are used to handle errors that occur in your PL/SQL code. A PL/SQL block contains
an EXCEPTION block to handle exception.

There are three types of exceptions:

1. Predefined Oracle errors


2. Undefined Oracle errors
3. User-defined errors

The different parts of the exception.

1. Declare the exception.


2. Raise an exception.
3. Handle the exception.

An exception has four attributes:

1. Name provides a short description of the problem.


2. Type identifies the area of the error.
3. Exception Code gives a numeric representation of the exception.
4. Error message provides additional information about the exception.

The predefined divide-by-zero exception has the following values for the attributes:

1. Name = ZERO_DIVIDE
2. Type = ORA (from the Oracle engine)
3. Exception Code = C01476

Error message = divisor is equal to zero


Ex.No.9 CREATION OF PROCEDURES

AIM:

To implement and execute Procedures in Oracle Database using Procedural Language concepts.

PROCEDURES:
1) Procedure is a sub program used to perform an action.

2) Replace-recreates the procedure if it already exists.

3 MODES:
1) IN – Means you must specify a value for the argument at the time execution of the procedure.

2) OUT-passes back a value to its calling program.

3) INOUT – When calling the procedure, yu must specify the value and that procedures passes value
back to the calling procedure.

SYNTAX:

Create or replace procedure <procedure_name> (argument {in, out, in out} data type) {is, as}

Variable declaration

Begin

Pl/SQL Subprogram body.

Exception

Exception PL/SQL Block.

End;
Ex.No.10 CREATION OF DATABASE TRIGGERS AND FUNCTIONS

AIM:

To implement and execute triggers and functions in Oracle Database using Procedural Language
concepts.

TRIGGERS:
1) Trigger is a special type of procedure that the oracle executes when an insert, modify or
delete operation is performed against a given table.
2) It is a stored sub program associated with a table.
3) It is used to keep an audit trial of a table, to prevent invalid transaction, enforce complex
security authorization, to generate data automatically.

SYNTAX:

CREATE OR REPLACE TRIGGER <TRIGGER NAME>


{BEFORE/AFTER/INSTEAD OF}
{INSERT/UPDATE/DELETE}
ON <TABLENAME/VIEWNAME>
REFRENCECING {OLD AS OLD /NEW AS NEW}
[FOR EACH STATEMENT /FOR EACH ROW [WHEN <CONDITION>]]
DECLARE
Variable declaration
Constant declaration
BEGIN
PL/SQL Sub program body.
EXCEPTION
Exception PL/SQL Block (or) user defined exception.
END;

FUNCTION:
1) A function is a sub program that accepts argument and returns a unique value to the caller.

FUNTION SYNTAX:

Create or replace function <function_name> (parameter{in, out, in out}) return <data type> is
Variable declaration
Begin
Pl/SQL Subprogram body.
Exception
Exception PL/SQL Block.
Return statement
End;
EX.NO.11 AIRLINE RESERVATION SYSTEM

AIM:

To implement and execute Airline Reservation System using cardinality function, relationship and
DDL query functions.

PROBLEM STATEMENT

 Airlines have many flights.

 Airlines operates many number of routes.

 Airlines provides many number of tickets.

 A passenger can avail many tickets.

 Airlines adopt many passengers in a single flight.

 A passenger can travel in many flights.

 A ticket has information about a single filght.

 Reserved tickets can be cancelled by customers.

BACK END DESIGN

IDENTIFICATION OF ENTITY:

 PASSENGER
 FLIGHT_INFORMATION
 FLEET_INFORMATION
 TICKET_DETAILS

You might also like