yellowpages.com.au By Rosalinda Pritchard
yellowpages.com.au is an Australian business directory. It provides search functions for local or interstate businesses. It allows a search for business types such as electricity or business names such as TRU energy. It is a place where businesses can inform the public of their names, contact details and the nature of their business. Database Description
Entity-Relationship Diagram Customer customerID businessPhoneNo businessName businessAddress businessSuburb businessState businessPostCode businessFax contactPerson contactPhoneNo Listing listingID listingPhoneNo listingBusinessName listingBusinessAddress listingBusinessSuburb listingBusinessState listingBusinessPostCode listingBusinessFax listingBusinessUrl listingBusiness Address listingBusinessmobileNo Category catID description listingID* catID* ListingCategory customerID* listingID* CustomerListing m mm m
Single One-to-Many Relationship Listing listingID listingPhoneNo listingBusinessName listingBusinessAddress listingBusinessSuburb listingBusinessState listingBusinessPostCode listingBusinessFax listingBusinessUrl listingBusiness Address listingBusinessmobileNo listingID* catID* ListingCategory 1 m A listing can be listed in one or more category listing. Primary key Foreign key
Single Many-to-Many Relationship Listing listingID listingPhoneNo listingBusinessName listingBusinessAddress listingBusinessSuburb listingBusinessState listingBusinessPostCode listingBusinessFax listingBusinessUrl listingBusiness Address listingBusinessmobileNo Category catID description listingID* catID* ListingCategory 1 1 m m Primary key Foreign key Primary key Foreign key
Single Many-to-Many Relationship A business such as 'Rhodes Docherty & Co' may list this business name under many business categories such as 'Accountants & Auditors', 'Financial Planning', 'Taxation Consultants' and so on. A business category such as 'Accountants & Auditors' can have many businesses listed under its name, businesses that offers accounting and auditing services. So the relationship between listings and categories is that of many-to-many.
A Simple Query Example: Find all Rhodes Docherty ’ s business listing. SQL Query: select * from listing where listingBusinessName like '%Rhodes Docherty%'; Results:
Natural Join Example: Find all Rhodes Docherty ’ s business listing. SQL Query: SELECT listingBusinessName, description FROM listing NATURAL JOIN listingCategory NATURAL JOIN category; Results: listingbusinessname | description Institute of Chartered Accountants In Australia The | Accountants & Auditors Chartered Accountants In Aust The Institute Of | Accountants & Auditors Rhodes Docherty & Co | Accountants & Auditors A J Rhodes Docherty & Co | Financial Planning A J Rhodes Docherty & Co | Taxation Consultants (5 rows)
Cross Product Example: Find all Rhodes Docherty ’ s business listing using cross product method. SQL Query: SELECT listing.listingBusinessName, category.description FROM listing, listingCategory, category WHERE listing.listingID = listingCategory.listingID AND listingCategory. catID = category.catID; Results: listingbusinessname | description Institute of Chartered Accountants In Australia The | Accountants & Auditors Chartered Accountants In Aust The Institute Of | Accountants & Auditors Rhodes Docherty & Co | Accountants & Auditors A J Rhodes Docherty & Co | Financial Planning A J Rhodes Docherty & Co | Taxation Consultants (5 rows)
Group by with HAVING Example: Show all categories that has more than 1 business listings. SQL Query: SELECT description, count(*) FROM category, ListingCategory WHERE category.catID = ListingCategory.catID GROUP BY description HAVING count(*) > 1; Results: description | count Accountants & Auditors | 3 (1 row)
Query with a Sub-Query Example: Show all categories that has no business listings. SQL Query: SELECT description FROM category WHERE catID NOT IN (select catID from ListingCategory); Results: description Vending Equipment & Services Soft Drink Mfrs &/or Distributors Confectionery--Wsalers & Mfrs Take Away Food Hotel, Restaurant & Club Supplies Confectionery--Wsalers & Mfrs Electricity Retailers Electricity Suppliers Gas Suppliers (9 rows)
Self Join Description: Self join allows you to work in a table, joining it to itself. Example: Display all business names or listings that share a phone number. SQL Query: SELECT l1.listingBusinessName, l1.listingPhoneNo, l2.listingBusinessName, l2.listingPhoneNo FROM listing l1, Listing l2 WHERE l1.listingPhoneNo = l2.listingPhoneNo AND l1.listingBusinessName > l2.listingBusinessName; Results: (see next slide)
Self Join Results: listingbusinessname | listingphoneno | listingbusinessname | listingphoneno Institute of Chartered Accountants In Australia The | | Chartered Accountants In Aust The Institute Of | Rhodes Docherty & Co | | A J Rhodes Docherty & Co | (3 rows) The above results shows Rhodes Docherty & Co twice because it has the same phone number as A J Rhodes Docherty & Co which has two entries in the system.
CHECK Statements Example: Validate or check the postcode to ensure it consist of 4 digits. SQL Statement: CREATE TABLE listing (... CONSTRAINT listing_listingBusinessPostCode CHECK ((listingBusinessPostCode >= 1000) AND (listingBusinessPostCode <= 9999)) );
Action Statements Example: Action statements protects data from being corrupted when a user modifies or deletes records from a table. Action Statement 1: CREATE TABLE customerListing (... CONSTRAINT customerListingPK PRIMARY KEY (customerID, listingID), CONSTRAINT customerListingFK_customer FOREIGN KEY (customerID) REFERENCES customer ON DELETE CASCADE, When a record is deleted from customer’s table, the record that is linked to customerListing is automatically deleted, because of the ‘on delete cascade’ action statement.
Action Statements Action Statement 2: CREATE TABLE listingCategory (... CONSTRAINT listingCategoryFK_category FOREIGN KEY (catID) REFERENCES category ON DELETE CASCADE When a record is deleted from the category’s table, the record that is linked to listingCategory is automatically deleted, because of the ‘on delete cascade’ action statement.
View Create View: CREATE VIEW BusListing AS select Customer.customerID, CustomerListing.listingID,listingPhoneNo, listingBusinessName, listingBusinessAddress, listingBusinessSuburb, listingBusinessState, Category.catID, description FROM customer, customerListing, listing, listingCategory, category WHERE customer.customerID = customerListing.customerID AND customerListing.listingID = listing.listingID AND listing.listingID = listingCategory.listingID AND listingCategory.catID = category.catID;
View View BusListing: select listingBusinessName from BusListing; Results: listingbusinessname Institute of Chartered Accountants In Australia The Chartered Accountants In Aust The Institute Of Rhodes Docherty & Co A J Rhodes Docherty & Co A J Rhodes Docherty & Co (5 rows)