0% found this document useful (1 vote)
851 views

Normalization

The document describes the design and implementation of a database to track real estate properties, owners, clients, and rentals. It includes normalization of data models from UNF to 3NF, mapping relationships between tables, creating the database and tables, populating with sample data, assigning access privileges to different users, and providing scripts to generate the full database schema and a query joining multiple tables.

Uploaded by

Daniel Kerandi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
851 views

Normalization

The document describes the design and implementation of a database to track real estate properties, owners, clients, and rentals. It includes normalization of data models from UNF to 3NF, mapping relationships between tables, creating the database and tables, populating with sample data, assigning access privileges to different users, and providing scripts to generate the full database schema and a query joining multiple tables.

Uploaded by

Daniel Kerandi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1) Description of the operations and the actors

A real estate management company keeps track of the properties it manages, owners of the
properties, and clients (tenants in the properties). Each owner of a property has a name and a
unique number. An owner can own a number of properties, each of which has a unique number,
and address (physical location). The company keeps record of each clients name, client ID
(national ID number), rent amount, and tenancy period (rent_start and rent_finish). A client may
rent one or more properties. A property can be rented by only one client at any given time period.
2) Normalization
Unnormalized Form (UNF)
Client_ID, Client_Name, Property_ID, Property_Address, Rent_Start, Rent_Finish, Rent,
Owner_ID, Owner_Name.
First Normal Form (1NF) (Remove the repeating groups)
Client_ID, Client_Name,
Client_ID, Property_ID, Property_Address, Rent_Start, Rent_Finish, Rent, Owner_ID,
Owner_Name.
Second Normal Form (2NF) (Based on the concept of full functional dependency)
Client_ID, Client_Name,
Client_ID, Property_ID, Rent_Start, Rent_Finish,
Property_ID, Property_Address Rent, Owner_ID, Owner_Name.
Third Normal Form (3NF) (Remove transitive dependencies)
Clients (Client_ID, Client_Name)
Rentals (Client_ID, Property_ID, Rent_Start, Rent_Finish)
Properties (Property_ID, _Address, Rent, Owner_ID)
Owners (Owner_ID, Owner_Name)

1|Page

3) Mapping the relationships


Rentals

Clients
Client_ID
Client_Name

Rentals
Client_ID
Property_ID
Rent_start
Rent_finish

Properties
Property_ID
Property_Address
Rent
Owner_ID

Properties
Property_ID
Property_Address
Rent
Owner_ID

Client_ID
Property_ID
Rent_start
Rent_finish

Owners

Owner_ID
Owner_Name

4) Creating the database and tables and populating the tables with 10 records
Creating the database
CREATE DATABASE RealEstatedb
datafile /u01/oracle/oradata/RealEstate/sys.dbf size 500M
sysaux datafile /u01/oracle/oradata/RealEstate/sysaux.dbf size 100m
undo tablespace undotbs
datafile /u01/oracle/oradata/RealEstate/undo.dbf size 100m
default temporary tablespace temp
tempfile /u01/oracle/oradata/RealEstate/tmp.dbf size 100m
logfile
group 1 /u01/oracle/oradata/RealEstate/log1.ora size 50m,
group 2 /u01/oracle/oradata/RealEstate/log2.ora size 50m;

2|Page

3|Page

Creating the tables


CREATE TABLE clients
( client_ID number(10) NOT NULL,
client_name varchar2(50) NOT NULL,
CONSTRAINT clients_pk PRIMARY KEY (client_ID)
TABLESPACE EstateMgt_tbs
STORAGE (INITIAL 50K)
);
CREATE TABLE rentals
( client_ID number(10) NOT NULL,
property_ID number(10) NOT NULL,
rent_start date,
rent_finish date,
CONSTRAINT rental_pk PRIMARY KEY (client_ID, property_ID)
TABLESPACE EstateMgt_tbs
STORAGE (INITIAL 50K)
);
CREATE TABLE properties
( property_ID number(10) NOT NULL,
property_Address varchar2(50) NOT NULL,
rent number(10),
owner_ID number(10) NOT NULL,
CONSTRAINT rental_pk PRIMARY KEY (property_ID)
TABLESPACE EstateMgt_tbs
STORAGE (INITIAL 50K)
);
CREATE TABLE owners
( owner_ID number(10) NOT NULL,
owner_name varchar2(50) NOT NULL,
CONSTRAINT owners_pk PRIMARY KEY (owner_ID)
TABLESPACE EstateMgt_tbs
STORAGE ( INITIAL 50K);
);

4|Page

Populating the tables


Insert into clients values (c001, Jack);
Insert into clients values (c002, Tom);
Insert into clients values (c003, John);
Insert into clients values (c004, Jane);
Insert into clients values (c005, James);
Insert into clients values (c006, Steve);
Insert into clients values (c007, Joe);
Insert into clients values (c008, Mary);
Insert into clients values (c009, Gladys);
Insert into clients values (c010, Jared);
Insert into rentals values (c001, p0010, 01-jul-04, 31-Aug-05);
Insert into rentals values (c002, p0009, 01-feb-05, 01-feb-06);
Insert into rentals values (c003, p0008, 01-sep-03, 10-Jun-04);
Insert into rentals values (c004, p0007, 10-oct-04, 01-Dec-05);
Insert into rentals values (c005, p0006, 01-Nov-05, 10-Jan-06);
Insert into rentals values (c005, p0005, 01-jul-04, 31-Aug-05);
Insert into rentals values (c005, p0004, 01-feb-05, 01-feb-06);
Insert into rentals values (c005, p0003, 01-sep-03, 10-Jun-04);
Insert into rentals values (c005, p0002, 10-oct-04, 01-Dec-05);
Insert into rentals values (c010, p0001, 01-Nov-05, 10-Jan-06);
Insert into properties values (p0001, Kikuyu, 30000, o010);
Insert into properties values (p0002, Muthiga, 20000, o009);
Insert into properties values (p0003, Kinoo, 18000, o008);
Insert into properties values (p0004, Kikuyu, 35000, o007);
Insert into properties values (p0005, Gitaru, 15000, o006);
Insert into properties values (p0006, Kikuyu, 34000, o005);
Insert into properties values (p0007, Kikuyu, 28000, o004);
Insert into properties values (p0008, Uthiru, 22000, o003);
Insert into properties values (p0009, Uthiru, 24000, o002);
Insert into properties values (p0010, Kikuyu, 38000, o001);

5|Page

Insert into owners values (o001, Macharia);


Insert into owners values (o002, Manyara);
Insert into owners values (o003, Wairire);
Insert into owners values (o004, Ndungu);
Insert into owners values (o005, Ngugi);
Insert into owners values (o005, Kamau);
Insert into owners values (o005, Wanyama);
Insert into owners values (o005, wangeci);
Insert into owners values (o005, Makokha);
Insert into owners values (o010, Momanyi);

5) Creating database users and assigning them different rights to different tables
CREATE USER User1 IDENTIFIED BY pwrd1;
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;
GRANT CONNECT, UPDATE, INSERT ON clients TO User1;
CREATE USER User2 IDENTIFIED BY pwrd2;
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;
GRANT SELECT ON rentals TO User2;
CREATE USER User3 IDENTIFIED BY pwrd3;
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;
GRANT SELECT, INSERT, UPDATE, DELETE ON properties TO User3;
CREATE USER User4 IDENTIFIED BY pwrd4;
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;
GRANT CONNECT, RESOURCE ON owners TO User4;

6|Page

6) Generating Script for entire database


set pagesize 0
set long 90000
set feedback off
set echo off
spool RealEstatedb_schema.sql
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
FROM USER_TABLES u;
SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name)
FROM USER_INDEXES u;
spool off;

7) Database query linking at least three tables and using mathematical operators
SELECT * FROM clients, rentals, properties,
WHERE clients.client_ID = rentals.client_ID(+)
AND rentals.property_ID = properties.property_ID(+);

7|Page

You might also like