INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.

Slides:



Advertisements
Similar presentations
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
Advertisements

CC SQL Utilities.
BIM211 – Visual Programming Database Operations 1.
Introduction to Structured Query Language (SQL)
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Microsoft Access 2010 Chapter 7 Using SQL.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Database Lecture # 1 By Ubaid Ullah.
ASP.NET Programming with C# and SQL Server First Edition
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
1 Working with MS SQL Server Textbook Chapter 14.
CSC 405: Web Application And Engineering II7.1 Database Programming with SQL Aggregation and grouping with GROUP BY Aggregation and grouping with GROUP.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
SQL 1: GETTING INFORMATION OUT OF A DATABASE MIS2502 Data Analytics.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 What is database 2? What is normalization? What is SQL? What is transaction?
Concepts of Database Management Seventh Edition
Chapter 5 Database Processing. Neil uses software to query a database, but it has about 25 standard queries that don’t give him all he needs. He imports.
M1G Introduction to Database Development 5. Doing more with queries.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Indexes and Views Unit 7.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
Using Structured Query Language (SQL) NCCS Applications –MS Access queries (“show SQL”) –SAS (PROC SQL) –MySQL (the new dataserver) –Visual Foxpro Other.
Introduction to Database Programming with Python Gary Stewart
Marketing Analytics: Database Query with MySQL Disclaimer: All logos, photos, etc. used in this presentation are the property of their respective copyright.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Database Access with SQL
CS320 Web and Internet Programming SQL and MySQL
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
SQL in Oracle.
CS1222 Using Relational Databases and SQL
Using SQL to Prepare Data for Analysis
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Presentation transcript:

INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014

Announcements PA #1 = DUE Monday 4/14. 11PM PST! Questions? Post on forum! I’ll answer there.

Review 3 tier architecture – Database – Logic – Presentation

Disclaimer There are a lot of other database classes (240, 340, etc) and this is a deep topic with a lot of expertise. Here is my “programmer’s guide to databases”, basically everything you need to know until you work on the database itself.

2 Types of Databases Relational Database Non-relational databases (NoSQL)

Relational Database Recognize relationships between stored items For example: – Teacher Table has a teacher ID – Class Table has a teacher ID saying who’s teaching that class, this ID should be a foreign key relationship to the teacher ID in the teacher table – This is a relationship MySQL, Oracle database, Microsoft SQL Server

Non-relational Database No constraints, relationship, it’s a simpler model Think of it as a Key Value Pair Much easier to scale! Relatively new (2000’s) MongoDB, Cassandra, Redis Read more here:

Let’s learn MySQL Open WAMP Go to PHPMyAdmin Username = root Password = (none) Backup:

CREATE TABLE Create table Use INNODB engine

INSERT row INSERT INTO VALUES ()

SELECT Retrieve data from table SELECT * FROM Students; // Returns all 4 students

WHERE Add a condition to SELECT statement SELECT * FROM Students WHERE age = 31; // returns Joe Chen

AND/OR WHERE clauses allow boolean operators SELECT * FROM Students WHERE age = 31 OR name='Amy Lin'; // returns Joe Chen & Amy Lin

DELETE Delete row from table DELETE FROM Students WHERE age=31; // Go to browse tab, Joe is deleted, add him back

How do I change a row?

Order by Sort results from SELECT SELECT * FROM Students ORDER BY name;

SELECT expressions Count – SELECT count(*) from Students; Sum – SELECT sum(age) from Students; Avg – SELECT avg(age) from Students;

Group By Group based on columns SELECT age, count(*) FROM Students GROUP BY age;

LIKE String matching allows fuzzy matching SELECT * FROM Students WHERE name like '%Chen';

JOINS Joins two or more tables via a relationship Create a table for Clubs {name, studentId} Basketball = Kenneth/Patrick Kayak = Patrick/Amy How do I get name of each student in the club? Ex: get all names of students in basketball club

Others Other useful SQL commands I left out – Alter table – Drop table – Update

Best Practices

CREATE TABLE sql file Keep a text file with all your create table queries Do NOT create tables manually It’s common to need to setup multiple machines (test environment, production environment, etc) Just run entire file => entire database is setup

Import Data Do not write code to do this This is a solved problem Your code is probably going to be buggy Use the functionality in phpMyAdmin/other database management tools

Index/Keys Always define a primary key If you’ll search by that column, use INDEX If that column is unique and you’ll search by that column, use UNIQUE INDEX HUGE for performance If you don’t have this, anything over 1000 rows will be super slow O(n) vs. O(1)

Use INNODB engine Other MySQL engines have strange behavior Just use ENGINE=INNODB

Work Load Whenever possible… Off load work to your compute instance Instead of SELECT SUBSTRING(…), do the substring command in EC2 Instead of sorting in the database, sort n the compute instance EC2 = easier to scale. No data replication problems

MySQL Create: – Teacher {id, name, class} – Class {id, name, teacherId, studentId} How do I get all students of a particular class? How do I get the name and #students each teacher is teaching?

PDO Use PDO to connect to MySQL Use the ->prepare() to specify parameters database-access-are-you-doing-it-correctly/ database-access-are-you-doing-it-correctly/

Resources

Questions?