Week3 adb

728 views
693 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
728
On SlideShare
0
From Embeds
0
Number of Embeds
502
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Week3 adb

  1. 1. Week 3
  2. 2. Assignment• 2 Part Assignment Patchwork and Narrative• Patchwork: – Somewhere to put it.. • Blogger / Wordpress / whatever – Something to put there • Screenshots, links of things we’ve done in class • Links to cool things you’ve found • And what do you honestly think about it? – Start with your Facebook Gephi diagram?
  3. 3. Relational Databases• Install MySQL – XAMPP, MAMP, WAMP• Last week we created databases from the MySQL command prompt
  4. 4. Relational Databases/Applications/MAMP/Library/bin/mysql --host=localhost -uroot –proot• As many items as possible:• Created a database – create database test’; – Use test; – Create – create table test( ID INT(5), TITLE VARCHAR(100) ); INSERT INTO test VALUES (5, “test”);• I did it in php• I got Bored• Video:
  5. 5. PHP loopset_time_limit(0);error_reporting(E_ALL);ini_set(display_errors, 1);$db = new db();$x = 2;$number = 1;$filename="/usr/share/dict/words";$words=file($filename);while ($x < 10) { shuffle($words); $word=$words[0]; $db->Query("INSERT INTO test (ID, Name) VALUE ($number, $word)"); $number++;}
  6. 6. 94 000 records in a few minutes
  7. 7. indexs• Default index in mysql is a datastructure called a b-tree• When you create a primary key is creates a b- tree• Like an index in a book
  8. 8. BTREE EXAMPLEhttp://www.youtube.com/watch?v=coRJrcIYbF4 Helps to Speed up joins
  9. 9. Joining Tables –Shop DatabaseCreate database shop;use shop;CREATE TABLE suppliers ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, supplier_name VARCHAR(100), supplier_address VARCHAR(100) ); CREATE TABLE products ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, prod_name VARCHAR(100), prod_desc VARCHAR(100), supplier_id INT );
  10. 10. Shop DatabaseINSERT INTO suppliers (supplier_name, supplier_address) VALUES ("Microsoft", "Microsoft Road") , ("Apple", "Apple Lane"); INSERT INTO products (prod_name, prod_desc, supplier_id) VALUES ("iPhone", "Mobile Phone", "2") , ("Xbox 360", "Games Machine", "1"); select * from suppliers select * from products Select supplier_name, prod_name from suppliers, products;SELECT prod_name, supplier_name, supplier_address FROM products, suppliersWHERE (products.supplier_id = suppliers.id);http://www.techotopia.com/index.php/Joining_Tables_in_MySQL
  11. 11. Relational Databasescollection of data items organized as a set of formally described tables
  12. 12. Relationships!
  13. 13. NoSQL databases (Not only SQL• non-adherence to the widely used relational database management system mode – Document Stores • Data stored in encodings such as XML, JSON etc – Graph Database – Key Value Store
  14. 14. Rows and Rows

×