0% found this document useful (0 votes)
16 views

Database Design

Uploaded by

alabidinzein570
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Database Design

Uploaded by

alabidinzein570
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Database Design Project

Zein Al Abidin Kashakesh and Hassan Al Mojtaba Daoun


Group 8
Entities:
Owner:
Keeps track of the owner’s name and percentage of ownership and his phone number
Primary key: owner_ID
Asset:
Keeps track of assets owned has attributes (Asset type, value, and date of purchase, and id)
Primary key: Asset_ID
Customer:
Keeps track of the customers’ details has attributes (Name, phone number, address, credit, and
id)
Primary key: id
Suppliers:
Keeps track of suppliers has attributes (name, phone number, credit, and id)
Primary key: Supplier_Id
Tax:
Has two attributes tax rate and type where the type is the primary key
Liabilities:
Has attributes type (loan…) amount, due date, creditor, currency
Primary key: Liability_id
Financial institution
Has attributes name and contact method
Primary key Institution_ID
Account:
Has attributes account type balance currency
Primary key: Account_Id
Ledger:
Has attributes start date and end date (keeps track of sum of financial statements over time)
Primary key: Id
Financial statement:
Has attributes start and end date profit net profit and tax
Primary key: statement-Id
Transaction:
Connects suppliers and customers to accounts and has a tax type that helps calculate tax on
transactions
Of Attributes: type, date, value
Primary key: Id
These tables can help a company manage its financial records.

Logical Model:

Relational Model:
SQL queries:
1. To add an owner:
Insert into owners
values ('Zein Al Abidin',1,0.53,'70809010');
2. To add a liability:
Insert into liabilities
values (1,'Loan',85000,'2024-05-30','Daher co.','dollar');

3. Update an already set value:


update owners
set percentage_of_ownership=0.55
where name='Zein Al Abidin'

4. Delete a liability of id=1

delete from liabilities


where liability_id=1;
5. Show all financial statements in 2024:
select * from financial_statement
where start_date>'2024-01-01';

6. Show all transactions that involve a value higher than 15000


select t.id from transactions t ,account a
where a.transaction_id=t.id and t.value>15000;
--this displays any asset that has been into a ledger
select o.owner_id , a.asset_id,l.* from owners o,assets a,ledger
l,owns
where a.asset_id=l.asset_asset_id and a.asset_id=owns.asset_asset_id
and owns.owner_owner_id=o.owner_id
and o.owner_id in (1,2);

--displays the maximum transaction value in each financial statement


select max(t.value),f.statement_id,t.* from transactions t,
financial_statement f
where t.statement_id=f.statement_id
group by f.statement_id;

--display payed tax in a financial st


select sum(t.value)*tax.tax_rate from transactions t,
financial_statement f, tax
where t.tax_type=tax.tax_type and t.fin_id=f.statement_id;
--displays the suppliers with the total value of purchases greater
than 100,000
select s.name,sum(t.value) from transactions t, suppliers s
where s.suppllier_id=t.suppllier_id
group by s.suppllier_id
having sum(t.value)>100000;
Create a table:
CREATE TABLE Account (
account_id INTEGER NOT NULL,
account_type VARCHAR(255) NOT NULL,
balance float NOT NULL,
transaction_id INTEGER NOT NULL,
currency VARCHAR(255),
CONSTRAINT account_pk PRIMARY KEY (account_id, transaction_id ),
CONSTRAINT account_transaction_fk FOREIGN KEY ( transaction_id )
REFERENCES transactions ( id ),
);

You might also like