Вы находитесь на странице: 1из 18

MSc.I.T.

Part I
Advanced Database Systems

STEP 1: CREATING A DATABASE IN ORACLE9i

Figure 1 – Launching the DB Configuration assistant

Figure 2 – Welcome Screen of DB Configuration Screen

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 3 – Selecting the type of operation.

Figure 4 – Template type for the database

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 5 – Identifying a database

Figure 6 – Selecting the mode

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 7 – Initialization Parameters

Figure 8 – Database Storage

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 9 – Operation Summary

Figure 10 – Creating the Database

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 11 – Entering Database Password

3# create instance for database

Figure 12 – Checking for the presence of created database.

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 13 – instance name

Figure 14 – add protocol

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 15 – add host name or IP and keep default port number.

Figure 16 – same service name as before (instance name)

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Figure 17 - Test connection.

(Note-create instance for database2 i.e db2)

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Practical No.: 1

Aim: Horizontal Fragmentation of Database.

QUESTION:

Create global conceptual schema, ‘Employee (empid, name, addr, desg, salary)’ and insert 10
records. Divide Employee into horizontal fragmented for the condition Salary <= 10000 into
tables ‘Worker(empid, name, addr, desg, salary)’ and Salary > 10000 into tables
‘Officer(empid, name, addr, desg, salary)’ on two different Databases and fire following
queries.
 Display all the records Employee.
 Display all the records of Employee from table Worker.
 Display all the records of Employee from table Officer.
 Display salary of all the Employee.
 Display name & empid of the employee whose salary > 10000.
 Select all records of an employee whose empid is 4.
 Select all records of an employee who are officers.

SCENARIO:

We have created the schema Employee for storing the details of Employee. Details are
empid, name, addr, desg, salary. Then we divided the main schema into two tables, Worker &
Officer and store both of them in different databases, using the Horizontal fragmentation
concept. To make the connectivity link is created between both the databases. Between
Worker & Officer link is db1todb2 and between Officer& Worker link is db2todb1. Using
both the links the queries are being fired.

SETUP:

Computer Name Computer Name

ORACLE 9i

ORACLE 9i db1todb2
db1 db2

db2todb1

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Creating Different Links:

 What is link?
Link is the virtual connection between two services, which help us to get access to the
table present into other service when we are in one service.
 Syntactical format for creating the link is as follows:
SQL> create public database link <link name> connect to <user name>identified by
<password> using <’Service name’>;

1. db1 to db2

SQL> connect scott/tiger@upgdb1 as sysdba;


Connected.

SQL> create public database link db1todb2 connect to scott identified by tiger using
'upgdb2';
Database link created.

2. db2 to db1

SQL> connect scott/tiger@upgdb2 as sysdba;


Connected.

SQL> create public database link db2todb1 connect to scott identified by tiger using
'upgdb1';
Database link created.

Creating Different Tables:

1. Employee in db1

SQL> connect scott/tiger@upgdb1


Connected.

SQL> create table employee_zubair(empid int primary key not null, name varchar2(20) not
null,addr varchar(20) not null,desg varchar2(20) not null,salary number not null);
Table created.

2. Worker in db1

SQL> create table worker_zubair(empid int primary key not null, name varchar2(20) not
null,addr varchar(20) not null,desg varchar2(20) not null,salary number not null);
Table created.

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

3. Officer in db2

SQL> connect scott/tiger@upgdb2;


Connected.

SQL> create table officer_zubair(empid int primary key not null, name varchar2(20) not
null,addr varchar(20) not null,desg varchar2(20) not null,salary number not null);
Table created.

Creating Trigger for inserting values automatically into either Worker or Officer table
when a new record is inserted in Employee:

SQL> connect scott/tiger@upgdb1;


Connected.

SQL> create or replace trigger trigger_zubair


after insert on employee_zubair
for each row
when(new.salary is not null)
begin
if :new.salary<= 10000 then
insert into worker_zubair
values(:new.empid,:new.name,:new.addr,:new.desg,:new.salary);
else
insert into officer_zubair@db1todb2
values(:new.empid,:new.name,:new.addr,:new.desg,:new.salary);
end if;
end;
/
Trigger created.

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Inserting Records in Employee:

insert into employee_zubair values (001,'ankita','virar','officer', 13000);


insert into employee_zubair values (002,'rashid','virar','officer', 15000);
insert into employee_zubair values (003,'ameya','vasai','officer', 12000);
insert into employee_zubair values (004,'neha','virar','worker', 8000);
insert into employee_zubair values (005,'vrunda','vasai', 'officer', 14000);
insert into employee_zubair values (006,'sonu','virar','worker', 8000);
insert into employee_zubair values (007,'nikita','vasai','worker', 7000);
insert into employee_zubair values (008,'veena','virar','worker', 6000);
insert into employee_zubair values (009,'ankit','virar','worker', 9000);
insert into employee_zubair values (010,'shweta','vasai','worker', 7000);

Retrieving Records from Tables (Queries):

1) Display all the records employee_zubair:

SQL> select * from employee_zubair;

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

2) Display all the records of employee_zubair from table worker_zubair:

SQL> select * from worker_zubair;

3) Display all the records of employee_zubair from table officer_zubair:

SQL> connect scott/tiger@upgdb2;


Connected.

SQL> select * from officer_zubair;

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

4) Display salary of all the employee_zubair:

*** Retrieving the records when we are in the database db2 ***

SQL> select empid, salary from employee_zubair@db2todb1;

5) Display name & empid of the employee_zubair whose salary > 10000:

*** Retrieving the records of employee when we are in the database db2 ***

SQL> select empid,name from employee_zubair@db2todb1 where salary>10000;

6) Select all records of an employee whose empid is 4:

*** Retrieving the records when we are in the database db2***

SQL>select * from employee_zubair@db2todb1 where empid=4;

Zubair Qureshi Page No.:


MSc.I.T. Part I
Advanced Database Systems

7) Select all records of an employee who are officers:

*** Retrieving the records when we are in the database db2 ***

SQL> Select * from employee_zubair@db2todb1 where desg='officer';

Zubair Qureshi Page No.:

Вам также может понравиться