Q (1) - Draw Data Models For The Following Entities. in Case, Make Certain That You Show The

You might also like

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

Q(1). Draw data models for the following entities.

In case, make certain that you show the


attributes and identifiers:

Answer:

Introduction to Data Modeling:

Data modeling helps us to understand the structure and meaning of data, which is necessary
before a database can be created. A data model is a graphical description of the components of
a database. One of these components is an Entity, Entities are things in the environment about
which we wish to store information. An Entity has characteristics or attributes. An Attribute
describe an entity contains the entity’s data we want to store. An entity must have a unique
Identifier, an attribute that uniquely identifies an instance of an entity is called an Identifier.
Conventions for drawing a Data model are :

 Should use an uppercase for entity name where as attributes should be in lowercases
 Identifiers is marked with * symbol

Q(1)a. Aircraft: An aircraft has a manufacturer, model number, call sign(e.g., N123ID), payload,
and a year of construction. Aircraft are classified as civilian or military.

Data Model:

AIRCRAFT

*callsign
manufacturer
modelnum
payload
manufactyear
aircrafttype

Entity: AIRCRAFT

Attributes: callsign, manufacturer, modelnum, payload, manufactyear, aircrafttype.

Identifier: callsign

Q(b). Car: A car has a manufacturer , range name, and style code (e.g., Honda Accord Dx, where
Honda is the manufacturer, Accord is the range, and DX is the style). A car also has a vehicle
identification code, registration code, and color.

Data model:
CAR

*vin
car rangename
car stylecode
car registrationcode
car color

Entity: CAR

Attributes:, vin, car rangename, car stylecode, car registrationcode, car color.

Identifier: vin(vehicle identification number)

Q(c). Restaurant: A restaurant has an address, seating capacity, phone number, and style of
food(e.g., French, Russian, Chinese).

Data model:

RESTAURANT

*restid
restname
resttype
restcap
restphone
reststreet
restcity
reststate
restzip

Entity: RESTARANT

Attributes: rested, restname, resttype, restcap, restphone, restcity, reststate, restzip.

Identifier: restid
Q(d). Cow: A dairy cow has a name, date of birth, breed(e.g., Holstein), and a numbered plastic
ear tag.

Data Model:

COW

*cow eartagnum
cow name
cow dob
cow breed

Entity: COW

Attributes: cow gartagnum, cow name, cow dob, cow breed.

Identifier: cow eartagnum

Q(2). Do the following queries using SQL:

(a). List a share’s name and its code.

SELECT shrfirm, shrcode FROM shr;


(b). List full details for all shares with a price less than $1.

SELECT * FROM shr WHERE shrpe < 1;

(c). List the names and prices of all shares with a price of at least $10.

SELECT shrfirm, shrprice FROM shr WHERE shrprice >= 10;

(d). Create a report showing firm name, share price, share holding. And total value of shares
held.( Value of shares held is price times quantity.)

SELECT shrfirm, shrprice, shrqty, shrprice*shrqty AS shares held FROM shr;

(e). List the names of all shares with a yield exceeding 5 percent.

SELECT shrfirm, shrdiv/shrprice*100 FROM shr


WHERE shrdiv/shrprice*100 > 5;

(f). Report the total dividend payment of Patagonian Tea. (the total dividend payment is
dividend times quantity).

SELECT shrfirm ,shrdiv, shrqty, shrdiv*shrqty AS total div payment FROM shr
WHERE shrcode = ‘PT’;

(g). Find all the shares where the price is less than 20 times the dividend.

SELECT shrcode, shrfirm FROM shr


WHERE shrprice < 20*shrdiv;

(h). Find the share with minimum yield.

SELECT shrfirm, MIN(shrdiv/shrprice*100) FROM shr;

(i). Find the total value of all shares with a PE ratio > 10.

SELECT SUM (shrprice*shrqty) FROM shr WHERE shrpe > 10;

(j). Find the share with the maximum total dividend payment.

SELECT shrfirm , MAX(shrdiv*shrqty) FROM shr;


(k). Find the value of the holdings in Abyssinian Ruby and Sri Lankan Gold.

SELECT shrfirm, shrprice*shrqty FROM shr


WHERE shrcode IN (‘AR’ , ‘SLG’);

(l). Find the yield of all firms except Bolivian Sheep and Canadian Sugar.

SELECT shrfirm, shrdiv/shrprice*100 FROM shr


WHERE shrcode NOT IN (‘BS’ , ‘CS’);

(m). Find the total value of the portfolio.

SELECT SUM (shrprice*shrqty) FROM shr;

(n) List firm name and value in descending order of value.

SELECT shrfirm shrprice FROM shr


ORDER BY shrprice DESC, shrfirm;

(o). List shares with a firm name containing "Gold."

SELECT shrcode, shrfirm FROM shr


WHERE shrfirm LIKE ' %Gold% ' ;

(p). Find the shares with a code starting with “B”.


SELECT shrfirm FROM shr

WHERE shrfirm LIKE ‘ B% ‘ ;

You might also like