You are on page 1of 5

1.

Identify the relations and attributes of the Gojo schema and create the
physical database design for each relation having the following elements.
Column Name Data Type Size Constraint

The identified relations and their attributes are as follows:

1. Staff
 staff_id INT PK
 name VARCHAR(50) NOT NULL
 salary DECIMAL(10,2) NOT NULL
2. Kifle_Ketema
 kifle_ketema_id INT PK
 staff_id INT FK (Staff)
 location VARCHAR(50) NOT NULL
3. Property_Type
 property_type_id INT PK
 property_type_name VARCHAR(50) NOT NULL
4. Landlord
 landlord_id INT PK
 name VARCHAR(50) NOT NULL
 address VARCHAR(50) NOT NULL
 phone_number VARCHAR(20) NOT NULL
5. Property
 property_id INT PK
 address VARCHAR(50) NOT NULL
 property_type_id INT FK (Property_Type)
 monthly_rent DECIMAL(10,2) NOT NULL
 deposit DECIMAL(10,2) NOT NULL
 landlord_id INT FK (Landlord)
6. Tenant
 tenant_id INT PK
 current_address VARCHAR(50) NOT NULL
 phone_number VARCHAR(20) NOT NULL
7. Lease
 lease_id INT PK
 property_id INT FK (Property)
 tenant_id INT FK (Tenant)
 start_date DATE NOT NULL
 duration INT NOT NULL
2. Create the appropriate tables and implement the tables’ appropriate indexes,
keys according to the Physical Database Design.

The appropriate SQL commands to create the tables and implement the
indexes and keys are as follows:

CREATE TABLE Staff (

staff_id INT PRIMARY KEY,

name VARCHAR(50) NOT NULL,

salary DECIMAL(10,2) NOT NULL

);

CREATE TABLE Kifle_Ketema (

kifle_ketema_id INT PRIMARY KEY,

staff_id INT NOT NULL,

location VARCHAR(50) NOT NULL,

FOREIGN KEY (staff_id) REFERENCES Staff(staff_id)

);

CREATE TABLE Property_Type (


property_type_id INT PRIMARY KEY,

property_type_name VARCHAR(50) NOT NULL

);

CREATE TABLE Landlord (

landlord_id INT PRIMARY KEY,

name VARCHAR(50) NOT NULL,

address VARCHAR(50) NOT NULL,

phone_number VARCHAR(20) NOT NULL

);

CREATE TABLE Property (

property_id INT PRIMARY KEY,

address VARCHAR(50) NOT NULL,

property_type_id INT NOT NULL,

monthly_rent DECIMAL(10,2) NOT NULL,

deposit DECIMAL(10,2) NOT NULL,

landlord_id INT NOT NULL,

FOREIGN KEY (property_type_id) REFERENCES


Property_Type(property_type_id),
FOREIGN KEY (landlord_id) REFERENCES Landlord(landlord_id)

);

CREATE TABLE Tenant (

tenant_id INT PRIMARY KEY,

current_address VARCHAR(50) NOT NULL,

phone_number VARCHAR(20) NOT NULL

);

CREATE TABLE Lease (

lease_id INT PRIMARY KEY,

property_id INT NOT NULL,

tenant_id INT NOT NULL,

start_date DATE NOT NULL,

duration INT NOT NULL,

FOREIGN KEY (property_id) REFERENCES Property(property_id),

FOREIGN KEY (tenant_id) REFERENCES Tenant(tenant_id)

);

CREATE UNIQUE INDEX unique_lease ON Lease(property_id, start_date);


3. Write the appropriate DML statement to insert data into the gojo database
based on the following business scenario.

INSERT INTO Staff (staff_id, name, salary) VALUES (1, 'Marta Yohannes', 10000);

INSERT INTO Kifle_Ketema (kifle_ketema_id, staff_id, location

You might also like