16
By Sean Boange

By Sean Boange. This Database is modelled on the Computer Hardware Store MSY . At current they display the numerous products they sell

Embed Size (px)

Citation preview

By Sean Boange

This Database is modelled on the Computer Hardware Store MSY www.msy.com.au. At current they display the numerous products they sell in an very inefficient PDF file (As seen on the next Slide). Basically My Database functions in two ways: It stores all the related details of the products in 3-4 Main Tables and it also demonstrates the function of customers to be able to purchase these products.

categoryid | categoryname | hardwaretypeid------------+-----------------------------+---------------- 0101 | Pentium 4 Socket 775pin M/B | 01 0102 | AMD Athlon64 754pin M/B | 01 0103 | AMD Athlon64 939pin M/B | 01 0104 | AMD AM2 940pin M/B | 01(4 rows)

hardwaretypeid | hardwaretypename----------------+-------------------- 01 | Motherboard 02 | CPU 03 | Memory 04 | Hard Disk Drive 05 | VGA Card 06 | DVD-ROM 07 | Flash Memory 08 | LCD Monitor 09 | Notebook Hard Disk(9 rows)

Primary Key

Foreign Keys

cartid | customerid--------+------------ A100 | 1000 A200 | 1000(2 rows)

productid | productname-----------+----------------------------- 080101 | 17inch Viewsonic VA703B-8ms 080102 | 17inch LG L1719S-SF-8ms(2 rows)

cartid | cartitemid--------+------------ A100 | 080101 A100 | 080102 A200 | 080101 A200 | 080102(4 rows)

Primary Key

Primary Key

Foreign Keys

Foreign Keys

Description:Find all customers living in NSW.

Query:

Select FirstName, LastName, State from BOANGE_MSY_Customer where state='NSW';

Result:

FirstName LastName State

Sean Boange NSW

Tyrone Peters NSW

Lali Singh NSW

Zeeshan Yusuf NSW

4 rows)

hardwaretypeid | categoryid | categoryname | hardwaretypename----------------+------------+-------------------------------+------------------ 02 | 0201 | Intel Conroe (Core 2 Duo) | CPU 02 | 0202 | Intel Conroe (Core 2 Quad) | CPU 02 | 0203 | Intel Celeron D (3xx) | CPU 02 | 0204 | Intel P4 (5xx & 6xx) | CPU 02 | 0205 | Intel (D-8xx,D-9xx) Dual Core | CPU 02 | 0206 | AMD Sempron 940pin CPU | CPU 02 | 0207 | AMD Athlon64 AM2 940pin CPU | CPU 02 | 0208 | AMD 754 CPU | CPU(8 rows)

Description:Find all categories for CPU’s in the database.

Query:

SELECT * FROM boange_msy_category NATURAL JOIN boange_msy_hardwaretype Where hardwaretypename='CPU';

Result:

hardwaretypeid | categoryid | categoryname | hardwaretypename----------------+------------+-------------------------------+------------------ 02 | 0201 | Intel Conroe (Core 2 Duo) | CPU 02 | 0202 | Intel Conroe (Core 2 Quad) | CPU 02 | 0203 | Intel Celeron D (3xx) | CPU 02 | 0204 | Intel P4 (5xx & 6xx) | CPU 02 | 0205 | Intel (D-8xx,D-9xx) Dual Core | CPU 02 | 0206 | AMD Sempron 940pin CPU | CPU 02 | 0207 | AMD Athlon64 AM2 940pin CPU | CPU 02 | 0208 | AMD 754 CPU | CPU(8 rows)

Description:Find all categories for CPU in the database using cross product.

Query:

SELECT * FROM BOANGE_MSY_Category, BOANGE_MSY_HardwareType WHERE boange_msy_category.hardwaretypeid = boange_msy_hardwaretype.hardwaretypeid AND hardwaretypename='CPU';

Result:

Description:Find which categories that contain more than 5 products in each of them.

Query:

SELECT CategoryName, count(*) FROM boange_msy_category, boange_msy_product WHERE boange_msy_category.categoryID = boange_msy_product.ProductCategoryID GROUP BY CategoryName HAVING count(*) > 5;

Result:categoryname count

AMD AM2 940pin M/B 10

Pentium 4 Socket 775pin M/B 10

Intel Conroe (Core 2 Duo) 6

(3 rows)

Description:Find the highest price product.

Query:

SELECT ProductID, ProductName, ProductPrice FROM boange_msy_product WHERE productprice >= all (SELECT productprice FROM boange_msy_product);

Result:

ProductID ProductName |ProductPrice

020201 Q6600 (Core 2 Quad) 705.00

(1 row)

Description:Show all Products that have the same price as ‘512M Samsung DDR400’ ($50.00).

Query:Select T1.ProductName, T1.ProductPrice FROM BOANGE_MSY_Product T1, BOANGE_MSY_Product T2WHERE T1.ProductPrice = T2.ProductPriceAND T2.ProductName = ‘512M Samsung DDR400’AND T1.ProductName <> ‘512M Samsung DDR400’;

Result:

ProductName ProductPrice

512M Hyundai DDR400 50.00

512M Kingston DDR400 50.00

Pioneer SATA 18x 212D Beige 50.00

(3 rows)

CONSTRAINT MSY_CartItemQty CHECK (CartItemQty > 0 )

CONSTRAINT MSY_CardType CHECK (CardType IN ('Visa','Mastercard','American Express','Diners Club')),

CONSTRAINT MSY_CardExpiryDate CHECK (CardExpiryDate > 2006)

CONSTRAINT MSY_CustomerPostcode CHECK (Postcode >=1000 and Postcode <= 9999)

CONSTRAINT MSY_CategoryName_NotNull CHECK (CategoryName IS NOT NULL)

CONSTRAINT MSY_CategoryFK FOREIGN KEY (HardwareTypeID) REFERENCES BOANGE_MSY_HardwareType (HardwareTypeID)

ON DELETE CASCADEON UPDATE CASCADE,

CONSTRAINT MSY_CartItemFK FOREIGN KEY (CartID) REFERENCES BOANGE_MSY_Cart(CartID)

ON DELETE RESTRICTON UPDATE CASCADE,

CREATE VIEW MthrBrdMem AS

Select * From BOANGE_MSY_HardwareType natural join

BOANGE_MSY_Category Where HardwareTypeName ='MotherBoard' OR HardwareTypeName ='Memory';

CREATE VIEWSelect CategoryName, HardwareTypeName, From MthrBrdMem Where CategoryID=‘0101’ OR

HardwareTypeName=‘Memory’ Order by HardwareTypeName;

categoryname hardwaretypename

Pentium 4 Socket 775pin M/B Motherboard

DDR 2 Memory 512MB Memory

DDR 2 Memory 1GB Memory

DDR 400 Memory 512MB Memory

DDR 400 Memory 1GB Memory

SDRAM Memory Memory

(6 rows)

This Presentation was Sponsored By Sean Boange Pty Ltd