Professional Documents
Culture Documents
CS RDBMS
CS RDBMS
SALEM-636010
………………………………………………………………………….…………………………..
Mrs.T.VIDYA Mr.R.MANIKANDAN,
Practical In-charges Head of the Department
Station : SALEM 1.
Date : 2.
LAB EXERCISE
1
Data Definition of Base Tables
1
5
2 DDL with Primary Key Constraints
3 9
DDL with constraints and verification by insert commands
Write a pl/sql code block that will accept an account number from
6 the user and debit an amount of rs.2000 from the account if the 23
7 Write a pl/sql code block to calculate the area of the circle for a 27
as 4321)
1
EX.NO: 1 USE DDL OF BASE TABLE
PL/SQL Code:
1.CREATE
SQL> create table student(rno varchar2(20),sname varchar2(20),class varchar2(20)
address varchar2(20));
SQL> desc student;
2. ALTER
SQL> ALTER TABLE student ADD phno number(10);
Table altered.
SQL> desc student;
2
SQL> select * from student;
RNO SNAME CLASS ADDRESS PHNO
------------------------------------------------------------------------------------------
01 raju IICS salem 6369690449
3. TRUNCATE
SQL> TRUNCATE TABLE student;
Table truncated.
SQL> select * from student;
no rows selected
4.DROP
SQL> DROP TABLE student;
Table dropped.
SQL> desc student;
ERROR:
ORA-04043: object student does not exist
3
EX.NO: 2.
DDL WITH PRIMARY KEY CONSTRAINTS.
PL/SQL Code:
4
SQL> create table student(rno int not null,sname varchar2(20),class varchar2(20),address
varchar2(20),primary key(rno),CONSTRAINT regno PRIMARY KEY(class));
*
ERROR at line 1:
ORA-02260: table can have only one primary key
5
EX.NO: 3.
USE DDL WITH CONSTRAINTS AND VERIFICATION BY INSERT
COMMAND
PL/SQL Code:
6
Ex. No: 4.
DATA MANIPULATION OF BASE TABLES AND VIEWS.
PL/SQL Code:
2.UPDATE
3.DELETE
8
Ex. No: 5.
DEMONSTRATE THE QUERY COMMANDS.
PL/SQL Code:
3. INNERJOIN
10
SQL> SELECT ID, LASTNAME, FIRSTNAME FROM persons1 INNER JOIN
student1 ON persons1.ID = student1.RNO;
ID LASTNAME FIRSTNAME
---------- -------------------- --------------------
2 k ajay
5.BETWEEN
11
1 sathish IIcs attur
2 ravi IIcs omlur
3 raj IIcs erode
4 prabhu IIBCA namakkal
12
Ex.NO: 6.
Write a PL/SQL code block that will accept an account number from the user and
debit an amount of Rs. 2000 from the account if the account has a minimum balance of
500after the amount is debited. The Process is to find on the Accounts table.
PL/SQL Code:
13
AC001 Anuj 5000
AC002 Robert 10000
AC003 Mita 3000
AC004 Sunita 15000
AC005 Melba 10000
14
Ex.No: 7.
Write a PL/SQL code block to calculate the area of the circle for a value of radius
varying from 3 to 7. Store the radius and the corresponding values of calculated area in a
table Areas. Areas – radius, area.
PL/SQL Code:
SQL> CREATE TABLE areas (Radius number (5), area number (14,2));
Table created.
SQL> SET SERVEROUTPUT ON;
SQL> start d:\s2.sql;
RADIUS AREA
---------- ----------
3 28.26
4 50.24
5 78.5
6 113.04
7 153.86
15
Ex.No: 8.
WRITE A PL/SQL BLOCK OF CODE FOR REVERSING ANUMBER.
(EXAMPLE: 1234 AS 4321).
PL/SQL Code:
SQL> set serveroutput on;
SQL> start d:\s3.sql;
The Given Number is102345
The Inverted Number is543201
PL/SQL procedure successfully completed.
16
Ex.NO: 9.
Create a transparent audit system for a table Client_master (client_no, name,
address, Bal_due). The system must keep track of the records that are being deleted or
updated. The functionality being when a record is deleted or modified the original record
details and the date of operation are stored in the audit client (client_no, name,
bal_due,operation,user id, opdate) table, then the delete or update is allowed to go
through.
PL/SQL Code:
17
CLIENT NAME ADDRESS CITY STATE PINCODE BAL_DUE
------------------------------ --------------- ---------- ----------------------------------------------
1 rahul salem salem tamilnadu 645221 1000
18