Introduction to Database Concepts

3,531 views
3,478 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,531
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
337
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • {5 min} Welcome & next slide intro
  • [3]{35} Q: Why should I stay awake for this? A: Campaigning is all about lists. Tables contain lists. Databases are sets of tables. Supporters Volunteers Donors Voters Legislators Others?
  • {10 min} Get the Picture: How it all fits together (TAKE A LONG TIME ON THIS SLIDE, bringing in pieces one at a time.) Server Houses Database Website / Web server Share data back and forth via a Server-side application – e.g. ASP, PHP, CF; Can folks think of others? At MoveOn, we use a scripting language called Mason, which is basically Perl inside packets that let web pages process it. All good fun, but the point is to share data with Personal computers – single; collective is the WWW So you collect data from them using Secure data transfer via forms – e.g. donation form, petition form; What are some other examples? Great, but what do you do with that data? You can publish it back to the public via the website (over the Internet ) – e.g. donation thermometer, blog comments; Other? Or use a database client – e.g. mySQL QB – to really get your hands on the data. Use SQL to ask the database questions, like: Have we raised enough $ today to buy pizza for the volunteers? How many volunteers do we have in that precinct? Or, what’s the ratio of volunteers to residents in that precinct? Are there enough supporters in that DMA to have a successful media event next week?
  • {5 min} Definitions (clarity over accuracy) Database In practice, a set of tables. Relational databases (like the ones that run websites) have tables that are related to each other by common fields. Table A table is a collection of data organized into columns (fields) and rows (records) and related to other tables by common fields. Field A column. A field contains all the same type of data; each cell refers to a different unit. Record A row. A record contains all the different types of data about a unit of analysis (e.g. user, order, letter).
  • {10 min} TELL THEM THIS IS THE MOST IMPORTANT SLIDE TO UNDERSTAND TAKE SOME TIME ON IT {Don’t click yet} In a world without relational database management systems, we might have a person in charge of fundraising with a list of donors. Back 5 years (or today on smaller campaigns) this might be kept in Excel. Back 15, this might have been a little box of index cards. Before that, stone tablets. The volunteer coordinator might have another list, and never the twain shall meet. Today, we keep all our data (I hope) in RDBMS that neatly link together data that all arms of the campaign collect: who gave online, who signed a petition on the street, what fundraising campaigns are we running, and who gave to each of those campaigns, or volunteered for them; which precincts are we canvassing, with which volunteers, etc. The idea of a relational database is that there’s no (or little) duplication of data. Once we collect contact info for a person, we don’t reenter it somewhere else in the database each time she takes an action, we record the action she took and relate it back to her contact info. All this data is related in the database through unique record identifiers called keys . {Click to bring in arrow that shows how users is related to donations}  This “users” table contains supporters’ contact info. User_id is the primary key. Each primary key is unique in this table. That way, if two people named “Jim Smith” sign up, we won’t get them confused. One is user_id = 1 and the other is user_id = 5. Everything Sarah Jones does is linked back to her contact info using her user_id, 2.  If Sarah donates, she shows up in the “volunteers” table, but not as “Sarah Jones” as user_id #2. {Click to bring up Volunteers and Campaigns tables}  If Sarah volunteers, she shows up in the “volunteers” table, but not as “Sarah Jones” as user_id #2.  What other kind of info might we want to record?
  • {5 min} Answer these questions using the tables provided. Go around and make sure people get the right answers. Note and help them if not.
  • {5 min} Review answers in group BE SURE TO DO Q&A BEFORE MOVING ON
  • {5 min for this and next 2 slides – Defining SQL} SQL A standard language for querying and modifying relational databases. Query Using SQL to as the database a question. mySQL MySQL is an Open Source Software relational database management system that uses SQL. mySQL Query Browser One of many available programs that allows you to connect to a database and run queries on it.
  • If you are not the DBA, and you probably won’t be, then you don’t have direct access to the database. Since you don’t have access to the server where the database lives, it is as if it’s in another dimension, “the other side”. You can’t communicate with it directly. You need a medium: an SQL client, like mySQL QB. Use QB to connect to the database and communicate with it, by executing SQL statements.
  • This is mySQL Query Browser, which is a medium for communicating with the database. There are lots of SQL clients – this is just an example. You can see here, you put in info about the server, a username and password (just like FTP, for those familiar with that). The QB brings up a map of the tables, and you can write SQL statements to query the data in those tables. We’re not going to use mySQL QB today, we’re just going to talk about how to create a simple SQL query.
  • {10 min for this + next 4 slides} The most important type of SQL statement is SELECT. In a SELECT statement, you are required to give 2 pieces of info: which fields and which tables… Next screen to show basic query.
  • * = all fields Result would be the entire table.
  • * = all fields Result would be one column, user_id, that contained a row for every record.
  • The next most useful clause is the WHERE clause. Not required, but this is where you limit the results by defining criteria. Go to next slide for example.
  • {8 min} Write SQL queries for as many of these as you can in the next 8 minutes. Turn in to Justin via email by end of session.
  • {2 min}
  • Introduction to Database Concepts

    1. 1. Introduction to Database Concepts
    2. 2. Campaigns Need Data <ul><li>Campaigning depends on lists. </li></ul><ul><ul><li>Supporters </li></ul></ul><ul><ul><li>Volunteers </li></ul></ul><ul><ul><li>Donors </li></ul></ul><ul><ul><li>Voters </li></ul></ul><ul><ul><li>Legislators </li></ul></ul><ul><ul><li>Can you think of others? </li></ul></ul>
    3. 3. The (Internet) Life of Data
    4. 4. Important Data Terms Database In practice, a set of tables. Relational databases (like the ones that underlie websites) have tables that are related to each other by common fields. <ul><ul><li>(clarity over accuracy) </li></ul></ul>Table A table is a collection of data organized into columns (fields) and rows (records) and related to other tables by common fields. Field A column. A field contains all the same type of data; each cell refers to a different unit. Record A row. A record contains all the different types of data about a unit of analysis (e.g. user, order, letter).
    5. 5. Tables Relate to Each Other “Keys” to success Fields that relate tables to each other are called “ keys ”. “ Primary key ” is the field (column) containing a unique id for each record. Keys prevent duplication of info in database. donations volunteers campaigns users
    6. 6. Exercise <ul><li>Which campaign did Mr. Greenburg volunteer for? </li></ul><ul><li>How much money did Sarah raise? </li></ul><ul><li>Who recruited her? </li></ul><ul><li>How much money did the phone bank raise? </li></ul>users volunteers donations campaigns
    7. 7. Tables Relate to Each Other “Keys” to success Fields that relate tables to each other are called “ keys ”. “ Primary key ” is the field (column) containing a unique id for each record. Keys prevent duplication of info in database. donations volunteers campaigns users
    8. 8. Structured Query Language SQL A standard language for querying and modifying relational databases. Query Using SQL to ask the database a question. mySQL An Open Source Software relational database management system that uses SQL. mySQL Query Browser One of many available programs that allows you to connect to a database and run queries on it.
    9. 9. Structured Query Language Use SQL SELECT, UPDATE, INSERT, or DELETE data. SELECT statements ask the database to display data. SQL is the standard language used to speak to databases Use a SQL client to connect to the database and execute SELECT, UPDATE, INSERT, or DELETE statements.
    10. 10. mySQL Query Browser The database has a message for you…
    11. 11. Anatomy a SELECT statement <ul><li>SELECT [fields] </li></ul><ul><li>FROM [tables] </li></ul><ul><li>JOIN [tables] </li></ul><ul><li>WHERE [criteria] </li></ul><ul><li>ORDER BY [sort] </li></ul><ul><li>GROUP BY [field] </li></ul><ul><li>LIMIT [# of results] </li></ul>We’ll focus on SELECT statements today, because they’re the most basic, and what you’ll need most in your work. Leave the UPDATE, DELETE, INSERT to the tech team, if there is one.
    12. 12. Anatomy a SELECT statement <ul><li>The most basic: </li></ul><ul><li>SELECT * </li></ul><ul><li>FROM users; </li></ul>We’ll focus on SELECT statements today, because they’re the most basic, and what you’ll need most in your work. Leave the UPDATE, DELETE, INSERT to the tech team, if there is one.
    13. 13. Anatomy a SELECT statement <ul><li>The second most basic: </li></ul><ul><li>SELECT user_id </li></ul><ul><li>FROM users; </li></ul>We’ll focus on SELECT statements today, because they’re the most basic, and what you’ll need most in your work. Leave the UPDATE, DELETE, INSERT to the tech team, if there is one.
    14. 14. Anatomy a SELECT statement <ul><li>SELECT [fields] </li></ul><ul><li>FROM [tables] </li></ul><ul><li>JOIN [tables] </li></ul><ul><li>WHERE [criteria] </li></ul><ul><li>ORDER BY [sort] </li></ul><ul><li>GROUP BY [field] </li></ul><ul><li>LIMIT [# of results] </li></ul>We’ll focus on SELECT statements today, because they’re the most basic, and what you’ll need most in your work. Leave the UPDATE, DELETE, INSERT to the tech team, if there is one.
    15. 15. Anatomy a SELECT statement <ul><li>SELECT * </li></ul><ul><li>FROM users </li></ul><ul><li>WHERE </li></ul><ul><li>city = ‘Austin’; </li></ul>We’ll focus on SELECT statements today, because they’re the most basic, and what you’ll need most in your work. Leave the UPDATE, DELETE, INSERT to the tech team, if there is one.
    16. 16. Exercise <ul><li>Show all members’ first names </li></ul><ul><li>Show how much Dave Young donated </li></ul><ul><li>Show when Sarah Jones signed up to volunteer </li></ul><ul><li>Show the contact info for everyone from Massachusetts </li></ul><ul><li>List the user_id of everyone who donated to the general fund </li></ul>users volunteers donations campaigns
    17. 17. Try this at home. <ul><li>Install Query Browser: http://dev.mysql.com/downloads/query-browser/index.html </li></ul><ul><li>Connect to the test database: host: 66.226.14.211 username/pw/schema: noi (all 3 the same) </li></ul><ul><li>mySQL Docs: http://dev.mysql.com/doc/refman/5.1/en/index.html </li></ul><ul><li>SQL Tutorial: http://www.w3schools.com/sql/sql_intro.asp </li></ul>

    ×