Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

DIT1206

DATABASE DEVELOPMENT AND MANAGEMENT


ASSIGNMENT JULY 2021

NAME REGISTRATION NUMBER

1. WILLY WANJAU DIT/2018/31603

2. ALEX MWANGI DIT/2018/35614

3. LAURAN KOFFI DIT/2019/44715

4. RYAN KOGEI DBIT/2017/70750

5. LOGHAN NYAMWEYA DIT/2019/41919


QUESTION 1: ENTITY RELATIONSHIP DIAGRAM (ERD)

 Haas Consult Enterprise company has a number of sales offices in several regions.
Attributes of the Office include: OfficeID (Primary key), Manager, Location. Manager is
assigned to manage the office
 Each office is assigned employees. Attributes of employees include: Employee_ID
(Primary Key), Employee_name, OfficeID. An employee must be assigned to only one
office.
 The company lists property for sale. Attributes of property include PropertyID
(Primary key), Value, location, officeID.
 Each unit of property must be listed with one office. An office can have a number of
properties listed and may have no properties listed.
 Each unit of property can have one or more clients. Clients of the company are owners
of the properties. Attributes of the client are clientID, client_name, Address

OFFICE EMPLOYEE PROPERTY

P.K OfficeID P.K EmpID P.K PropertyID

Value
Manager Emp_Name
Location
Location F.K OfficeID
F.K OfficeID

CLIENT

P.K ClientID

Client_Name

Address
QUESTION 2: DATA DEFINITION LANGUAGE (DDL)
Tables:
1. Product: create table Product (ProductID varchar (7), Description varchar (60), Price int
(15) NOT NULL, Manufacturer varchar (50), Qty_on_Hand int (15) NOT NULL), PRIMARY
KEY(ProductID));

2. Office: create table Office (OfficeID varchar (7), City varchar (20) NOT NULL, Region
varchar (20) NOT NULL, Manager varchar (7), Target decimal (10,2) check (Target >=
5000), Sales decimal (10,2) check (Sales >= 5000), PRIMARY KEY (OfficeID), UNIQUE
KEY(Manager));
3. SalesRep: create table SalesRep (SalRepID varchar (7), SalRepName varchar (60),
OfficeID varchar (7), Hiredate date CHECK (Hiredate >= 2000-01-1), Manager varchar
(7), Quota varchar (15) NOT NULL, Sales decimal (10,2) check (Sales >= 500), Target
decimal (10,2) check (Target >= 500), PRIMARY KEY (SalRepID), FOREIGN KEY (OfficeID)
REFERENCES Office (OfficeID));
Then: Alter table SalesRep add foreign key (Manager) REFERENCES Office(Manager);

4. Customer: create table Customer (CustomerID varchar (7), CustomerName varchar (60),
Company varchar (20), Address varchar (20) NULL, SalRepID varchar (7), CreditLimit
decimal (10,2) CHECK (CreditLimit >= 500), PRIMARY KEY (CustomerID), FOREIGN KEY
(SalRepID) REFERENCES SalesRep (SalRepID));
5. Order: create table 0rder (0rderID varchar (7), CustomerID varchar (7), ProductID
varchar (7), Qty int (15) NOT NULL, Amount int (15) NOT NULL, SalRepID varchar
(7),Date date CHECK (Date >= 2000-01-1), PRIMARY KEY (0rderID), FOREIGN
KEY(CustomerID) REFERENCES Customer (CustomerID));
Then - alter table 0rder add FOREIGN KEY (ProductID) REFERENCES Product (ProductID);
alter table 0rder add FOREIGN KEY (SalRepID) REFERENCES SalesRep (SalRepID);

QUESTION 3: DATA MANIPULATION LANGUAGE (DML)


I. select city, target, sales from office where region = ‘Eastern’ and sales> target order by
city;
II. select salrepname, Hiredate from salesrep where sales > 5000;

iv.

Ix select salrepname, quota, manager from salesrep;

Xi select avg (sales) from salesrep;

You might also like