PA1 Solution
PA1 Solution
PA1 Solution
Fall 2022
Course Project Assignment #1
(ER & Relational Models for Online
Trading System)
Solution
1. ER Diagram
First
Last
Name Address
SSN Name Telephone
Email
CreditCard#
Rating Person LivesAt Location
Client
State
Id IsA ZipCode
City
HasAccount
DateOpened
Id
Account
Start
Fee Date Id
Date Hourly
Id Time Rate
PricePerShare Employee
HasStock
Transaction
NumShares
Date
Order
Trade Time
Id
NumShares IsA
Stock
Hidden
CompanyName Market Stop
PricePerShare BuySellType
Market
On Close Trailing
StockSymbol PricePerShare
Stop
Type
BuySellType
Percentage
Rationale for E-R Model
Trading information is primarily specified using three entities: Account, Stock, and
Transaction. These entities are linked through the relationship HasStock, which relates
stocks with the accounts they are held in, and the relationship Trade, which represents
the actual buying and selling of stocks. Notice that the roles Transaction and Order are
keys of the relationship Trade and that every transaction and order must be involved in
some Trade relationship. Thus, there is a one-to-one correspondence between
Transaction entities and Trade relationships, and Order entities and Trade relationships.
Also notice that an order is placed at a certain date/time and a transaction occurs at
certain, presumably different, date/time. Furthermore, the number of shares traded is
encapsulated in the Order entity. As for the price per share, this information resides in
both the Transaction and Order entities: a hidden-stop order dictates the sale price of a
share of stock; for all other types of orders, the price per share will be determined at
runtime, that is, when the transaction occurs. Finally, hidden- and trailing-stop
conditional orders are, by definition, sell orders, while market and market-on-close
orders may be buy or sell orders.
Please see Figure 4.31 (p. 109) of the course textbook for a similar E-R perspective of a
stock-trading system.
2. Relational Model (1)
CREATE TABLE Person (
SSN INTEGER,
LastName CHAR(20) NOT NULL,
FirstName CHAR(20) NOT NULL,
Address CHAR(20),
ZipCode INTEGER,
Telephone INTEGER,
PRIMARY KEY (SSN),
FOREIGN KEY (ZipCode) REFERENCES Location (ZipCode)
ON DELETE NO ACTION
ON UPDATE CASCADE )