0% found this document useful (0 votes)
49 views16 pages

Ads - 1 To 7

The document describes creating structured data types and tables in Oracle to store employee and department data, including defining object types for employees and departments and creating tables based on these types while applying constraints. It also demonstrates populating the tables with sample data and describing the tables.
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)
49 views16 pages

Ads - 1 To 7

The document describes creating structured data types and tables in Oracle to store employee and department data, including defining object types for employees and departments and creating tables based on these types while applying constraints. It also demonstrates populating the tables with sample data and describing the tables.
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/ 16

Expt NO.

: 01

Title: Create structured data types of ORDBMS and perform operations- create table using
Structured data types, insert data and solve queries.

CREATE TYPE employee1_Type AS OBJECT(


empno char(6),
firstname varchar(12),
lastname varchar(15),
workDept REF dept_Type,
sex char(1),
birthDate date,salary number(8,2)
)/

CREATE TYPE deptartment_Type AS OBJECT(


deptNo char(3),
deptName varchar(36),
mgrNo REF employee_Type,
admrDept REF dept_Type
)
/

CREATE TABLE EMPLOYEE_TBLE OF employee1_Type(

CONSTRAINT tblemp_primarykey PRIMARY KEY ( empno ), CONSTRAINT tblemp_fname


firstname NOT NULL, CONSTRAINT tblemp_lname lastname NOT NULL,
CONSTRAINT tblemp_check_sex CHECK (sex = 'M' OR sex = 'm' OR sex = 'F' OR sex =
'f')
)
/

CREATE TYPE employee_Type1 AS OBJECT(


empno char(6),
firstname varchar(12),
lastname varchar(15),
sex char(1),
birthDate date,salary number(8,2)
)/

CREATE TABLE EMPLOYEE_TABLE OF employee_Type1(

CONSTRAINT tblemp_primarykey PRIMARY KEY ( empno ), CONSTRAINT tblemp_fname


firstname NOT NULL, CONSTRAINT tblemp_lname lastname NOT NULL,
CONSTRAINT tblemp_check_sex CHECK (sex = 'M' OR sex = 'm' OR sex = 'F' OR sex =
'f')
)
/

ALTER TYPE employee_Type1 ADD workDept REF dept_Type2/

ALTER TABLE EMPLOYEE_TABLE ADD CONSTRAINT tblemp_workdept FOREIGN


KEY
(workDept)REFERENCES DEPARTMENT_TABLE
/

CREATE TYPE dept_Type2 AS OBJECT(


deptNo char(3),
deptName varchar(36),
mgrNo REF employee_Type1,
admrDept REF dept_Type2
)
/

CREATE TABLE DEPARTMENT_TABLE OF dept_Type2 ( CONSTRAINT


tbldept_prinarykey PRIMARY KEY (deptno),

CONSTRAINT tbldept_mgrno_fk FOREIGN KEY (mgrNo) REFERENCES


EMPLOYEE_TABLE,
CONSTRAINT tbldept_admin_fk FOREIGN KEY (admrDept) REFERENCES
DEPARTMENT_TABLE,
CONSTRAINT tbldept_deptno deptNo NOT NULL, CONSTRAINT tbldept_deptname
deptName NOT NULL
)
/

INSERT INTO DEPARTMENT_TABLE VALUES (dept_Type('A01','CSE',NULL,NULL))

CREATE TYPE employee_Type1 AS OBJECT(


empno char(6),
firstname varchar(12),
lastname varchar(15),
sex char(1),
birthDate date,salary number(8,2)
)/

CREATE TABLE EMPLOYEE_TABLE OF employee_Type1(


CONSTRAINT tblemp_primarykey PRIMARY KEY ( empno ), CONSTRAINT tblemp_fname
firstname NOT NULL, CONSTRAINT tblemp_lname lastname NOT NULL,
CONSTRAINT tblemp_check_sex CHECK (sex = 'M' OR sex = 'm' OR sex = 'F' OR sex = 'f')
)
/
desc EMPLOYEE_TABLE

desc DEPARTMENT_TABLE

ALTER TYPE employee_Type1 ADD workDept REF dept_Type2/

ALTER TABLE EMPLOYEE_TABLE ADD CONSTRAINT tblemp_workdept FOREIGN


KEY
(workDept)REFERENCES DEPARTMENT_TABLE
/

CREATE TYPE dept_Type2 AS OBJECT(


deptNo char(3),
deptName varchar(36),
mgrNo REF employee_Type1,
admrDept REF dept_Type2
)
/

CREATE TABLE DEPARTMENT_TABLE OF dept_Type2 ( CONSTRAINT


tbldept_prinarykey PRIMARY KEY (deptno),

CONSTRAINT tbldept_mgrno_fk FOREIGN KEY (mgrNo) REFERENCES


EMPLOYEE_TABLE,
CONSTRAINT tbldept_admin_fk FOREIGN KEY (admrDept) REFERENCES
DEPARTMENT_TABLE,
CONSTRAINT tbldept_deptno deptNo NOT NULL, CONSTRAINT tbldept_deptname
deptName NOT NULL
)
/

INSERT INTO DEPARTMENT_TABLE VALUES (dept_Type('A01','CSE',NULL,NULL))


INSERT INTO DEPARTMENT_TABLE VALUES (dept_Type('A02','ELE',NULL,NULL))

desc DEPARTMENT_TABLE

Expt NO.: 02
Title: Implement vertical and horizontal fragmentation in
distributed DBMS

create type acc_type as object(account_num number(12),


acc_holder_nm varchar(100),
account_type varchar(30),
branch varchar(50),
balance number(10))

create table bank_details of acc_type


(constraint c1 primary key(account_num),
acc_holder_nm not null,
account_type not null,
branch not null,
balance not null);

desc bank_details

insert into bank_details values(123456, 'aaa','saving',


'sangli', 400000);
insert into bank_details values(123457, 'bbb','saving',
'sangli', 500000);
insert into bank_details values(123458, 'aaa','current',
'ashta', 450000);
insert into bank_details values(123459, 'ccc', 'saving',
'sangli', 44000);
insert into bank_details values(123460, 'ddd','saving',
'sangli', 400000);
insert into bank_details values(123461, 'ddd','saving',
'ashta', 100000);
insert into bank_details values(123462, 'fff','current', 'sangli',
900000);
insert into bank_details values(123463, 'iii', 'current', 'sangli',
200000);
insert into bank_details values(123464, 'jjj','saving', 'sangli',
100000);

select * from bank_details;

create table Savings as


select * from bank_details
where account_type='saving';

create table Currentt as


select * from bank_details
where account_type='current';

select * from Savings


select * from Currentt
#acc holder in both table

select acc_holder_nm from Savings


intersect
select acc_holder_nm from Currentt

#Identify customer max balance


create table Max_bal as
select max(balance)as bal
from Savings
Union
select max(balance) as bal
from Currentt;

select max(bal)
from Max_bal;

Exp 3

Title: Implementation of Centralized Database Architecture.


import java.sql.*;
class EmployeeRecord
{
public static final String
DBURL="jdbc:oracle:thin:@localhost:1521:xe";
public static final String DBUSER="system";
public static final String DBPASS="root";
public static void main(String args[])
{
try
{
//Loading Driver

Class.forName("oracle.jdbc.driver.OracleDriver");
//Create the connection object
Connection con =
DriverManager.getConnection(DBURL,DBUSER,DBPASS);
//Insert Record
String sql="Insert into emp1
(emp_id,empname,email,city) values (?,?,?,?)";
PreparedStatement
statement=con.prepareStatement(sql);
statement.setInt(1,100);
statement.setString(2,"Prashant");

statement.setString(3,"[email protected]");
statement.setString(4,"Pune");

int rowInserted=statement.executeUpdate();
if(rowInserted>0)
{
System.out.println("A new employee
was inserted successfully!\n");
}
//Display the record
String sql1="select * from emp1";
Statement stmt=con.createStatement();
ResultSet result =stmt.executeQuery(sql1);

while(result.next())
{

System.out.println(result.getInt(1)+""+result.getString(2)+""+
result.getString(3)+""+result.getString(4));
}

//Update the record


String sql2="Update emp1 set email=? where
empname=?";
PreparedStatement
pstmt=con.prepareStatement(sql2);
pstmt.setString(1,"[email protected]");
pstmt.setString(2,"Jaya");
int rowUpdate=pstmt.executeUpdate();
if(rowUpdate>0)
{
System.out.println("\nRecord updated
seccessfully!!\n");
}
//Delete the record
String sql3="delete from emp1 where
empname=?";
PreparedStatement
statement1=con.prepareStatement(sql3);
statement1.setString(1,"Prashant");

int
rowsDeleted=statement1.executeUpdate();
if(rowsDeleted>0)
{
System.out.println("A Employee was
deleted successfully!\n");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}

Exp 4
Title: Implement two phase commit in distributed DBMS.
Coordinate
import java.io.*;
import java.net.*;
class CoOrdinate
{
public static void main(String [] args)throws Exception
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
ServerSocket ss=new ServerSocket(4545);
System.out.println("\nEnter No. of Subordinate:");
int cnt=Integer.parseInt(br.readLine());
Socket []s=new Socket[cnt];
DataInputStream []dis=new DataInputStream[cnt];
DataOutputStream []dos=new DataOutputStream[cnt];
for(int i=0;i<cnt;i++)
{
s[i]=ss.accept();
dis[i]=new DataInputStream(s[i].getInputStream());
dos[i]=new DataOutputStream(s[i].getOutputStream());
}
String pr=new String("prepare");
System.out.println("Sending prepare message");
for(int i=0;i<cnt;i++){
dos[i].writeUTF(pr);
}
String []in=new String[cnt];
boolean flg=true;
for(int i=0;i<cnt;i++)
{
in[i]=dis[i].readUTF();
if(in[i].equals("no"))
flg=false;
}
if(flg==false)
{
pr="abort";
System.out.println("Sending abort msg");
for(int i=0;i<cnt;i++)
{
dos[i].writeUTF(pr);
}
}
else
{
pr="commit";
System.out.println("Sending commit msg");
for(int i=0;i<cnt;i++)
{
dos[i].writeUTF(pr);
}
for(int i=0;i<cnt;i++)
{
System.out.println("Receiving ack");
}
}}}
Subordinate
import java.io.*;
import java.net.*;
class SubOrdinate
{
public static void main(String [] args)throws Exception
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
Socket s=new Socket("localhost",4545);
DataInputStream dis =new
DataInputStream(s.getInputStream());
DataOutputStream dos=new
DataOutputStream(s.getOutputStream());
String out=new String();
String in=dis.readUTF();
System.out.println("Receiving "+in+" msg.");
System.out.println("SubOrdinate ready:'yes' or 'no':");
out=br.readLine();
System.out.println("Sending "+out);
dos.writeUTF(out);
in=dis.readUTF();
System.out.println("Reciving "+in+" msg");
if(in.equals("commit"))
{
out="ack";
System.out.println("Sending Ack");
}
}
}

Exp 5

create type stud_type as object(URN number(8) , roll


number(4), fname char(20), lname char(20))
desc stud_type
create table stud of stud_type(constraint c1 primary
key(URN), constraint c2 roll not null, constraint c3 fname
not null, constraint c4 lname not null)
insert into stud values(20031021,3006, ‘fds’, 'jjj')
insert into stud values(20031040,3017, 'shf','kkk')
insert into stud values(20031033,3023, 'aaa', 'lll')
insert into stud values(20031044,3021, 'hhh', 'vvv')
CREATE TABLE STD_nme AS
SELECT URN,fname, lname
FROM stud;
desc STD_nme;
select * from STD_nme;
CREATE TABLE STD_info1 AS
SELECT URN,roll
FROM stud;
desc STD_info1;
select * from STD_info1;
select * from STD_info1 NATURAL JOIN STD_nme;
select * from STD_nme LEFT JOIN STD_info1 ON
STD_nme.URN=STD_info1.URN
select * from STD_nme RIGHT JOIN STD_info1 ON
STD_nme.URN=STD_info1.URN

Exp 6

Title: Implement vertical and horizontal fragmentation in


distributed DBMS
create type acc_type as object(account_num number(12),
acc_holder_nm varchar(100),
account_type varchar(30),
branch varchar(50),
balance number(10))

create table bank_details of acc_type


(constraint c1 primary key(account_num),
acc_holder_nm not null,
account_type not null,
branch not null,
balance not null);

desc bank_details

insert into bank_details values(123456, 'aaa','saving',


'sangli', 400000);
insert into bank_details values(123457, 'bbb','saving',
'sangli', 500000);
insert into bank_details values(123458, 'aaa','current',
'ashta', 450000);
insert into bank_details values(123459, 'ccc', 'saving',
'sangli', 44000);
insert into bank_details values(123460, 'ddd','saving',
'sangli', 400000);
insert into bank_details values(123461, 'ddd','saving',
'ashta', 100000);
insert into bank_details values(123462, 'fff','current', 'sangli',
900000);
insert into bank_details values(123463, 'iii', 'current', 'sangli',
200000);
insert into bank_details values(123464, 'jjj','saving', 'sangli',
100000);

select * from bank_details;

create table Savings as


select * from bank_details
where account_type='saving';

create table Currentt as


select * from bank_details
where account_type='current';

select * from Savings


select * from Currentt
#acc holder in both table

select acc_holder_nm from Savings


intersect
select acc_holder_nm from Currentt

#Identify customer max balance


create table Max_bal as
select max(balance)as bal
from Savings
Union
select max(balance) as bal
from Currentt;
select max(bal)
from Max_bal;

Exp 7

Title: Queries on PL/SQL Commands.


PL/SQL for Even or odd number.
DECLARE
x NUMBER:=2;
r NUMBER:=3;
BEGIN
if mod(x,2)=0 then
dbms_output.put_line('Even number x='||x);
else
dbms_output.put_line('Odd number x='||x);
end if;
if mod(r,2)=0 then
dbms_output.put_line('Even number r='||r);
else
dbms_output.put_line('Odd number r='||r);
end if;
end;
PL/SQL for finding greatest number.
DECLARE
a NUMBER := 468;
b NUMBER := 6;
c NUMBER := 201;
BEGIN
IF a > b
AND a > c THEN

dbms_output.Put_line('Greatest number is '||a);


ELSIF b > a
AND b > c THEN
dbms_output.Put_line('Greatest number is '||b);
ELSE
dbms_output.Put_line('Greatest number is '||c);
END IF;
END;

CREATE OR REPLACE PROCEDURE greetings


AS
BEGIN
dbms_output.put_line('Hello World!');
END;

BEGIN
greetings;
END;
/

Exp 8

You might also like