Mdst 3559-02-22-sql1

319 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
319
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mdst 3559-02-22-sql1

  1. 1. SQL 1<br />MDST 3559: DataestheticsProf. Alvarado02/22/2011<br />
  2. 2. Business<br />If you are still having problems with VPN, call the Help Desk<br />Anyone interested in an extra session on PHP?<br /> Thursday (2/24) from 1:30 to 3:30<br />
  3. 3. Review<br />PHP as a language<br />Meanings<br />Nouns and Verbs<br />Grammatical words (prepositions, conjunctions)<br />Clauses and sentences<br />Stories<br />How to import a file and transform it using conditional logic<br />See 02-17/rex.php<br />
  4. 4. Overview<br />This week we view another language devoted to working with data <br />Data are like “meanings”<br />Data are what values are made of<br />Works in tandem with PHP<br />Lives at the “bottom” of the stack<br />The foundation …<br />
  5. 5. The Stack<br />CSS<br />HTML<br />JavaScript<br />INTERACTION<br />HTML (DOM)<br />PHP<br />Local files<br />Remote files<br />ALGORITHM<br />SQL<br />DATA<br />
  6. 6. What does data look like?<br />How is it organized?<br />
  7. 7. Basic Data Structures<br />Tables<br />CSV<br />Excel<br />Arrays<br />PHP<br />JavaScript<br />Trees<br />XML and the “Document Object Model”(DOM)<br />Implied by CSS selectors, e.g. .part p {}<br />Arrays of arrays, e.g. <br />$foo[0] = array();<br />$foo[5][2] = “bar”;<br />
  8. 8. What do these structures have in common?<br />
  9. 9. Data Structures<br />All have addressableelements<br />Elements with unique names<br />Row C, Column A<br />DIV.section[1]/DIV.part[2]/P[5]<br />Alll have an implicit template of categories<br />CSV has a header of column names<br />XML has element types and classes<br />Arrays have indexes<br />All consist of repeated instances of the template<br />E.g. rows<br />
  10. 10. Categories, Instances, Values<br />
  11. 11. Example<br />What are the categories? Instances? Values?<br />
  12. 12. Implicit Data Models<br />All data structures have a data model<br />May be implicit<br />More or less coherent<br />May not be “true”<br />A data model is a schematic representation of how the categories in the template are related to each other<br />
  13. 13. COUNTRY<br />owns<br />uses<br />SOCIAL NETWORK<br />US Debt<br />Country X uses social network Y<br />Country X owns US Debt Z (in billions of $)<br />
  14. 14. SQL<br />SQL stands for “Structured Query Language”<br />Pronounced S-Q-L or as “sequel”<br />NOT invented by Microsoft<br />Invented in the 1970s and commercialized in the 1980s<br />Probably responsible for new business models<br />Built on Codd’s relational model (1970)<br />Implements set theory<br />Around the time of SGML<br />
  15. 15. SQL<br />A language used by relational databases<br />Oracle, SQL Server, Access, etc.<br />
  16. 16. MySQL<br />A very fast, simplified, and easy to use relational database<br />A client/server app<br />Runs on the internet<br />Not a desktop app like Access<br />Created by Monty Widenius in the mid 1990s<br />Open Source<br />A Finn living in Sweden <br />Same time as PHP<br />Powered the Web 2.0 revolution<br />
  17. 17. phpMyAdmin<br />A PHP interface to MySQL<br />Relatively easy to use<br />No need to know SQL<br />Great to manage databases that your PHP programs will use<br />Today you will get started using UVA’s free MySQL server <br />
  18. 18. Exercise<br />Create a MySQL account<br />Create a database called MDST2559<br />Go to phpMyAdmin<br />Import the file into a table called ‘demo’<br />
  19. 19. Some SQL Commands<br />From the SQL box, enter<br />SELECT * FROM demo<br />SELECT country, network FROM demo<br />SELECT DISTINCT network FROM demo<br />SELECT country, debt FROM demo WHERE network = ‘Facebook’<br />SELECT country, debt FROM demo ORDER BY ‘debt’ DESC<br />

×