Australian Electoral Commission Database By: Jason Murphy.

Slides:



Advertisements
Similar presentations
Advanced SQL Topics Edward Wu.
Advertisements

All Powder Board and Ski Microsoft Access Workbook Chapter 3: Database Tables Jerry Post Copyright © 2007.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
BASIC SKILLS AND TOOLS USING ACCESS
Relational data integrity
DT FMA Planning Guide. Task For your FMA you are required to implement the database that you designed for your TMA –Create the appropriate tables –Import.
Advanced SQL (part 1) CS263 Lecture 7.
Using DDL Statements to Create and Manage Tables
CS 3630 Database Design and Implementation. Where Clause and Aggregate Functions -- List all rooms whose price is greater than the -- average room price.
© Abdou Illia MIS Spring 2014
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? Page 97 in Course.
R ELATIONAL M ODEL TO SQL Data Model. 22 C ONCEPTUAL D ESIGN : ER TO R ELATIONAL TO SQL How to represent Entity sets, Relationship sets, Attributes, Key.
© Paradigm Publishing, Inc Access 2010 Level 1 Unit 1Creating Tables and Queries Chapter 2Creating Relationships between Tables.
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
Database design by Sarah Huynh.
Chapter 15 A Table with a View: Database Queries.
SQL-week5-1 In-Class Exercise Answer IST 210 Organization of Data IST2101.
Introduction to Structured Query Language (SQL)
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Normalization Queries (contd)
Introduction to Structured Query Language (SQL)
U:/msu/course/cse/103 Day 16, Slide 1 CSE 103 Day 16 Students: Read Day 10. If you are logged in, add records to your contacts.
Week 2 Normalization and Queries
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
Introduction to Structured Query Language (SQL)
LSP 121 Week 2 Normalization and Queries. Normalization The Old Car Club database presented a problem – what if one person owns multiple cars? (One owner.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Database Relationships Objective 5.01 Understand database tables used in business.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Working with Queries in Microsoft Access The Access Workbench: Section Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
The 2 nd Hand Student Book Database Jon Havier High Distinction Assignment, Autumn 2007.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Component 4/Unit 6f Topic VI: Create simple querying statements for the database The SELECT statement Clauses Functions Joins Subqueries Data manipulation.
ABC Insurance Co. Paul Barry Steve Randolph Jing Zhou CSC8490 Database Systems & File Management Dr. Goelman Villanova University August 2, 2004.
SQL Server 7.0 Maintaining Referential Integrity.
“National Electoral Division Profiles” Case Study Vincent Tang High Distinction Assignment, Autumn 2007.
1 Intro to JOINs SQL INNER JOIN SQL OUTER JOIN SQL FULL JOIN SQL CROSS JOIN Intro to VIEWs Simple VIEWs Considerations about VIEWs VIEWs as filters ALTER.
Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.
DATABASE TRANSACTION. Transaction It is a logical unit of work that must succeed or fail in its entirety. A transaction is an atomic operation which may.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Design. Referential Integrity : data in a table that links to data in another table must always work in such a way that following the link will.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Microsoft Access Intro Class 6 Relationships.
SQL for Data Retrieval. Review Questions of Previous Class Q1. Show the sum of hours worked for project with ID 1200 (use ASSIGNMENT table) – Use “SUM”
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
This is the first screen you will encounter. Select Blank Database.
© 2002 by Prentice Hall 1 Database Processing with Microsoft Access David M. Kroenke Database Concepts 1e Appendix A.
Database Processing with Microsoft Access Appendix DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
Chapter 3: Relational Databases
DAY 14: ACCESS CHAPTER 1 RAHUL KAVI October 8,
FEN Introduction to the database field: The development process Seminar: Introduction to relational databases Development process: Analyse.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
1 All Powder Board and Ski SQL Server Workbook Chapter 5: Advanced Queries Jerry Post Copyright © 2003.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Decision Analysis Fall Term 2015 Marymount University School of Business Administration Professor Suydam Week 10 Access Basics – Tutorial B; Introduction.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
SQL Relational Database Project
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
All Powder Board and Ski
Structured Query Language (Data definition Language)
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Teaching slides Chapter 8.
PHP and MySQL.
Presentation transcript:

Australian Electoral Commission Database By: Jason Murphy

What is the AEC Database It records all former and present Federal Members of parliament It records all former and present Federal Members of parliament It shows the results of each electorate and the relevant member who achieved such results It shows the results of each electorate and the relevant member who achieved such results Lists all political parties Lists all political parties Provides contact information for constituents Provides contact information for constituents

AEC Database ER Diagram

One to Many relationship One party has many members One party has many members jmurphy=> select memberid, partyid, firstname, lastname from AEC_Member where partyid = 'LP'; memberid | partyid | firstname | lastname memberid | partyid | firstname | lastname | LP | Tony | Abott | LP | Tony | Abott | LP | Phillip | Ruddock | LP | Phillip | Ruddock

Many to many relationship Many party’s have many election results as they vary from electorate to electorate Many party’s have many election results as they vary from electorate to electorate TABLE 1 :AEC_Electorate electorateid | electionresultsid | state | landsize | age18 | age30 | age50 electorateid | electionresultsid | state | landsize | age18 | age30 | age Lowe | | NSW | | 10 | 20 | 68 Lowe | | NSW | | 10 | 20 | 68 Sydney | | NSW | | 1 | 67 | 5 Sydney | | NSW | | 1 | 67 | 5 Berowra | | NSW | | 25 | 25 | 30 Berowra | | NSW | | 25 | 25 | 30 Flinders | | TAS | | 25 | 25 | 30 Flinders | | TAS | | 25 | 25 | 30 (4 rows)

Many to Many Linked By TABLE THAT LINKS THE PREVIOUS AND THE NEXT SLIDE: AEC_ER erid | electionresultsid| electorateid | | Lowe | | Lowe | | Lowe | | Lowe (2 rows)

Many to Many Cont’d AEC_ElectionResults electionresultsid | liberal | labor | noinformal | totalvotes | year electionresultsid | liberal | labor | noinformal | totalvotes | year | 60.2 | 10.8 | 25 | | | 60.2 | 10.8 | 25 | | | 30.2 | 30.9 | 5 | | | 30.2 | 30.9 | 5 | | | 18.2 | 5 | 1 | | | 18.2 | 5 | 1 | | | | | 30 | | | | | 30 | | | 5.98 | 10 | 60 | | | 5.98 | 10 | 60 | | 2001 (5 rows)

Simple query of a single table Show all election results where labor achieved greater than 30% on a two party preferred basis jmurphy=> Select * from AEC_ElectionResults where labor > 30; electionresultsid | liberal | labor | noinformal | totalvotes | year electionresultsid | liberal | labor | noinformal | totalvotes | year | 30.2 | 30.9 | 5 | | | 30.2 | 30.9 | 5 | | | | | 30 | | | | | 30 | | 2004 (2 rows)

Natural Join Query When you want to join two tables together the automatic way is a natural join statement. The below query joins the AEC_Member and AEC_Electorate table together jmurphy=> Select electorateid, firstname, lastname, landsize from AEC_Member natural join AEC_Electorate; from AEC_Member natural join AEC_Electorate; electorateid | firstname | lastname | landsize electorateid | firstname | lastname | landsize Lowe | John | Murphy | Lowe | John | Murphy | Sydney | Tony | Abott | Sydney | Tony | Abott | Flinders | Sarah | Stevens | Flinders | Sarah | Stevens | Berowra | Phillip | Ruddock | Berowra | Phillip | Ruddock | (4 rows)

Cross Product Natural Join  This is the same query but the extended version where in the SQL the links between the tables i.e the primary and foreign keys need to be manually correlated select AEC_Electorate.electorateid, firstname, lastname, landsize from AEC_Member, AEC_Electorate where AEC_Member.electorateid = AEC_Electorate.electorateid; electorateid | firstname | lastname | landsize electorateid | firstname | lastname | landsize Lowe | John | Murphy | Lowe | John | Murphy | Sydney | Tony | Abott | Sydney | Tony | Abott | Flinders | Sarah | Stevens | Flinders | Sarah | Stevens | Berowra | Phillip | Ruddock | Berowra | Phillip | Ruddock | (4 rows)

Group By When trying to find the number of electorates in each state a group by function is needed When trying to find the number of electorates in each state a group by function is needed jmurphy=> select state, count (*) as Number from AEC_Electorate group by state order by state; state | number state | number NSW | 3 NSW | 3 TAS | 1 TAS | 1 (2 rows)

Subquery Show the electorate, the state in which the electorate is when the land is greater than average jmurphy=> select electorateid, state, landsize from AEC_Electorate where landsize > (select AVG(landsize) from AEC_Electorate); electorateid | state | landsize electorateid | state | landsize Berowra | NSW | Berowra | NSW | Flinders | TAS | Flinders | TAS | (2 rows)

Self Join query When you want to ensure that the electorateid is correct. This is just in case a member changes electorates and the database wasn’t changed. jmurphy=> select ass1.electorateid, ass2.electorateid, mstate from AEC_Member ass1, AEC_Electorate ass2 where ass1.electorateid = ass2.electorateid; electorateid | electorateid | mstate electorateid | electorateid | mstate Lowe | Lowe | NSW Lowe | Lowe | NSW Sydney | Sydney | NSW Sydney | Sydney | NSW Flinders | Flinders | TAS Flinders | Flinders | TAS Berowra | Berowra | NSW Berowra | Berowra | NSW (4 rows)

CHECK statements It is important to ensure that the data entered is correct. The following check statement ensures that the number of informal votes entered is It is important to ensure that the data entered is correct. The following check statement ensures that the number of informal votes entered is (a) not negative (a) not negative (b) doesn’t exceed the total number of votes (b) doesn’t exceed the total number of votes CONSTRAINT AEC_ElectionResults_Invalid_Informals CHECK ((NoInformal >= 0) AND (NoInformal = 0) AND (NoInformal <= TotalVotes))

Another CHECK constraint The following CHECK constraint ensures that the member has a starting date greater than or in The following CHECK constraint ensures that the member has a starting date greater than or in This is because Australia was not federated until 1901 and that is the first possible year within the database This is because Australia was not federated until 1901 and that is the first possible year within the database CONSTRAINT AEC_Member_Invalid_StartYear CHECK (StartYear >= 1901) CONSTRAINT AEC_Member_Invalid_StartYear CHECK (StartYear >= 1901)

Delete Cascade When PartyID is deleted this will flow throuhgh the AEC_Member table CONSTRAINT AEC_Member1_Party_FK FOREIGN KEY (PartyID) REFERENCES AEC_Party ON DELETE CASCADE ON DELETE CASCADE

Delete cascade When Electorate ID is deleted this will flow throuhgh the AEC_Electorate table When Electorate ID is deleted this will flow throuhgh the AEC_Electorate table CONSTRAINT AEC_Member2_Electorate_FK FOREIGN KEY (ElectorateID) REFERENCES AEC_Electorate ON DELETE CASCADE ON DELETE CASCADE

Views in the AEC database Views allow us to have the data on hand without having to constantly re type the same sql. Views allow us to have the data on hand without having to constantly re type the same sql. The view is stored within the database and can be easily used again with a view name set by the user The view is stored within the database and can be easily used again with a view name set by the user CREATE VIEW name AS query CREATE VIEW name AS query

Views Say we want to have the following data shown: electorateid, firstname, lastname, contactnumber where there is no finish date Say we want to have the following data shown: electorateid, firstname, lastname, contactnumber where there is no finish date This could be used by the AEC to issue a phone number for people trying to get in contact with their member of parliament This could be used by the AEC to issue a phone number for people trying to get in contact with their member of parliament Output: Output: | firstname | lastname | contactnumber | | firstname | lastname | contactnumber | | John | Murphy | | | John | Murphy | | | Tony | Abott | | | Tony | Abott | | | Sarah | Stevens | | | Sarah | Stevens | | | Phillip | Ruddock | | | Phillip | Ruddock | | CREATE VIEW contact AS firstname, lastname, contactnumber from AEC_Member where finishdate = null;

How to use a view once saved \dv checks to see the views that have been stored, this is a user shortcut \dv checks to see the views that have been stored, this is a user shortcut List of relations Name | Type | Owner contact | view | jmurphy

The End Thank you for listening about the AEC database