You are on page 1of 5

School of Computing

Department of Computer Science and Engineering


Academic Year: 2019-20
Winter Semester
Course: 1151CS303 DBMS Lab Slot: L7

TASK PLAN

Database system selected: Stock Management System

Mr. Ram runs a business on stock advisory service. Some of his clients trade stocks at a
loss by buying at a high price and selling at a low price. So he is in need of very simple
trading models with comparative results to show clients how they can grow the value of
their investment accounts with his stock picks.
The following are the attributes.

Task1: CO1, S3
1. Create the table using the following schemas.

Investor Table:

Allow null
Column name Data type Description Size
value
The serial number of the
AccountID int default no
account. (PK)
Name Varchar Name of account holder 15 no
Fund account associated with
Fund char 10 no
the account

Exchange Table:

Allow null
Column name Data type Description Size
value
The serial number of the
ExchangeID int default No
exchange (PK)
Name varchar Name of exchange 15 No
Market _Day Table:

Allow null
Column name Data type Description Size
value
Time when orders are
Day_Date timestamp default No
executed (PK)

Event:Table:

Allow null
Column name Data type Description Size
value
The serial number of the stock
StockID int default No
(PK)
The time when event is
Time timestamp default No
released
Event varchar Description of event 100 yes

Company Table:

Allow null
Column name Data type Description Size
value
The serial number of the stock
StockID int default No
(PK)
Name of the stock/company's
Name varchar 15 No
name
Ticker varchar Stock symbol 15 No
Limit int The stock can be traded default No
Percentage change of the
Valid float 10 No
stock

Price _Open Table:

Allow null
Column name Data type Description Size
value
OpeningPrice decimal The price today at open (PK) (10,3) No
Time when orders are
Day_Date timestamp Default No
executed (FK)

Price _Close Table:

Allow null
Column name Data type Description Size
value
ClosingPrice decimal The price today at close (PK) (10,3) No
Time when orders are
Day_Date timestamp Default No
executed (FK)

Market_Quote Table:

Allow null
Column name Data type Description Size
value
The serial number of the
StockID int Default No
stock (PK)
The serial number of the
MarketQuoteID int Default No
market quote ( FK)
OpeningPrice decimal The price today at open ( FK) (10, 2) No

ClosingPrice decimal The price today at close ( FK) (10, 2) No

CurrentPrice decimal Current price (10,2) No

HighestPrice decimal Highest price in the day (10,2) No

LowestPrice decimal Lowest price in the day (10,2) No


Number of all trades of the No
ExchangeQuantity int Default
stock
OpenInterest decimal Open Interest (10, 2) No

Trade Table:

Allow null
Column name Data type Description Size
value
The serial number of the
StockID int Default No
market quote (PK)
The serial number of the
AccountID int Default No
account (FK)
The serial number of the No
ExchangeID int Default
exchange (FK)
TradingVolume int Number of stock being traded Default No

Price decimal Price at trading (10, 2) No

Type boolean 0=Buy or 1=Sell 1 No


2. Devise ER Diagram for the above Stock database schema

Task 02: Queries to Retrieve Records CO2, S3


Find all the possibilities of the database system updating from descriptive to prescriptive
analytics supporting databases or relational either. To help in either, as a sophisticated
programmer, answer the following queries.
Write SQL queries for the following:
1. Find all investors who has highest investment.
2. Find all StockID’s and names and validity date for company schema.
3. Find all StockID’s with highest price and lowest price.
4. List all AccountID and ExchangeID for StockID with type=1.
5. Find all StockID’s with opening date on same day.
6. Count all StockID’s based on time when orders are executed.
7. Find all MarketID’s and Name based on Trading volume
8. Find all AccountID’s who buy stocks.
9. Find all AccountID’s who sells stocks.
10. Arrange all StockID’s in ascending order.
11. Arrange all StockID’s in descending order.
12. Provide user access privileges to database.
13. Commit database.
14. Rollback a transaction in case of any errors.
15. Set save point for a transaction.
16. Add key constraints for all schemas.
17. Delete a row of record where there is StockID with no TradingVolume.
Sample Input:
Inputs are preloaded as per task-01.
Sample Output:
Delete StockID from Trade where TradingVolume =0

You might also like