Creating Databases for web applications [Complete presentations] More SQL Class time: discuss final projects. Do posting if you have not done it.

Slides:



Advertisements
Similar presentations
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Concepts of Database Management Seventh Edition
Chapter 4 5 6_ SQL SQL Is: Structured Query Language
Introduction to Structured Query Language (SQL)
CSE 1561 A Brief MySQL Primer Stephen Scott. CSE 1562 Introduction Once you’ve designed and implemented your database, you obviously want to add data.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
Chapter Physical Database Design Methodology Software & Hardware Mapping Logical Design to DBMS Physical Implementation Security Implementation Monitoring.
Introduction to Structured Query Language (SQL)
1 SQL-Structured Query Language SQL is the most common language used for creating and querying relational databases. Many users can access a database applications.
Week 2 Normalization and Queries
1 IS 4420 Database Fundamentals Chapter 7: Introduction to SQL Leon Chen.
Concepts of Database Management Sixth Edition
1 Creating a Non-Conditional List A- What are you going to do? You will “list” “all of the records” in a database. (it means you will not use any condition!)
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
Microsoft Access 2010 Chapter 7 Using SQL.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
Creating databases for web applications
Creating Databases for Web Applications SQL Select extras Listing [names of] tables generalized display of recordset simple password handling php and other.
Chapter 3 Single-Table Queries
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
PHP meets MySQL.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Creating Databases More SQL. Design. Original Project Assignment Homework: Post proposal. Continue with planning.
Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Using Special Operators (LIKE and IN)
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Lec 3- B Database Integrity 1. Overview Define a database using SQL data definition language Work with Views Write single table queries Establish referential.
Maintaining a Database Access Project 3. 2 What is Database Maintenance ?  Maintaining a database means modifying the data to keep it up-to-date. This.
1 CSE 2337 Introduction to Data Management Access Book – Ch 1.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
SQL Overview Structured Query Language
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Querying Single Tables with SQL.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
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.
Creating Databases for Web applications Making a table of table information. Reprise on database design. SQL. Classwork/Homework: Projects! Postings.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
SQL Query Getting to the data ……..
Creating Databases More SQL. Design. Original Project Assignment
Structured Query Language
Chapter 8 Working with Databases and MySQL
Contents Preface I Introduction Lesson Objectives I-2
Presentation transcript:

Creating Databases for web applications [Complete presentations] More SQL Class time: discuss final projects. Do posting if you have not done it.

Relationships, etc. Can specify relationships (e.g., foreign keys) and the DBMS will check and throw an error if not met. My assumption: the php code does the checking so my examples generally don't set relationships. Similarly, the DBMS checks for required fields and for unique primary keys (when key is not set by DBMS)

Database multi-user DBMS are built to handle multiple users at a time! Need rules to prevent updating of same field –Example: two people sharing a bank account make withdrawals at the same time. Default can be to freeze access to database / table / record while transaction is in process. LOCK/UNLOCK SQL commands This is something to focus on when doing production systems!

Performance considerations The CREATE table statement can specify one or more fields to be INDEX. This forces the DBMS to build an index (!) for improved speed. Trade off: more space and slightly more time when records added but shorter times during SELECT operations. OPTIMIZE table. Assumption that tables become less efficient over time. Similar to disk defrag EXPLAIN SELECT gives information on how this SELECT works. May lead you to revising the statement OR defining an INDEX (use ALTER table) Other techniques…. Some DBMSs have stored procedures…

INSERT Multiple formats INSERT INTO tablename VALUES (all the values in order specified at create time) –Use 0 for an auto increment field(s) INSERT INTO tablename (fieldnamea, fieldnameb, …) VALUES (fields corresponding to those field names) –Better include all required fields.

INSERT, continued INSERT INTO tablename SET fieldaname=valuea, fieldbname=valueb, etc. –Better set all required values INSERT INTO tablename1 (fieldaname, fieldbname, …) SELECT fa, fb, … FROM tablename2 WHERE … –Has to be same number of field names and types must match.

Select operators =, >, =, < IS NOT NULL, IS NULL BETWEEN IN, NOT IN LIKE (has wild card character: %, others) REGEXP

DISTINCT SELECT DISTINCT category FROM questions; –Examines all the values in the category fields and returns a recordset of just those SELECT category, COUNT(*) FROM questions GROUP BY category –returns a recordset with a row for each category. Each row has 2 fields: category and a number representing the number of times each value of category occurred in the table.

Select aggregate functions AVG, COUNT, MIN, MAX, STD, SUM SELECT AVG(score) in players; SELECT COUNT(*) in players WHERE score > 100; Get these as 0 th field, 0 th row of recordset SELECT AVG(score), MIN(score), MAX(score), STD(score), COUNT(score) in players; Get these as 0 th, 1 st, 2 nd, 3 rd, 4 th, 5 th fields of 0 th row of recordset

Select control grouping SELECT order_id, SUM(quantity) FROM ordereditems GROUP BY order_id; limit: SELECT product_id, quantity FROM ordereditems LIMIT 10; limit: starting from 1 st record fitting conditions and returning 10 records SELECT product_name, product_description, product_cost FROM catalog LIMIT 1, 10; For paging, repeat with variables indicating 1 st and last entries: "SELECT product_name, product_description, product_cost FROM catalog LIMIT $FIRST, 10"

SELECT order_id, SUM(quantity) FROM ordereditems GROUP BY order_id; Query result: Original data

Multiple tables Consider songs, featuresinsongs, features application. 1 This land is your land 2 Where have … 3 Thriller Folk/political 2 Michael Jackson This land is your land and Where have are each tagged as Folk/political. Thriller is tagged Michael Jackson.

Single table select SELECT sid, fid from featuresinsongs would produce not too interesting, though might be good for debugging

Multiple tables conditions List the name of the song with the name of the tag feature. One row for each tagging… SELECT s.sname as a, f.fname as b FROM songs as s, featuresinsongs as t, features as f WHERE s.sid=t.sid AND t.fid=f.fid

Alternate Use INNER JOIN and ON Note: the, between tables is equivalent to INNER JOIN BUT The way the operation is done is different and probably more efficient: this way doesn't create as many records. The WHERE way creates records for each row in one table with ALL rows of other table and then removes the ones not matching the WHERE conditions!

INNER JOIN ON SELECT s.sname as a, f.fname as b FROM songs as s INNER JOIN featuresinsongs as t ON s.sid=t.sid INNER JOIN features as f ON t.fid=f.fid NOTE: can say simply JOIN and not INNER JOIN SELECT s.sname as a, f.fname as b FROM songs as s JOIN featuresinsongs as t ON s.sid=t.sid JOIN features as f ON t.fid=f.fid

Results in all cases This land is your land Folk/political Where have …Folk/political ThrillerMichael Jackson

UPDATE Change one or more fields in [certain] records in a table. Assume certain names for fields. UPDATE products SET price=price*1.1 increases all prices by 10% UPDATE products SET price=price*1.1 WHERE price <100 increases all prices that were under 100

UPDATE (simple) To change a specific person's address. Assume that previous php obtained the pid field as $pidx and entered the new address as $naddress $query = "UPDATE people SET address='$naddress' WHERE pid=$pidx"

UPDATE The address probably came in separate fields, so the UPDATE would be $query = "UPDATE people SET address1='$naddress1', address2='$naddress2', state='$state', zip='$zip' WHERE pid=$pidx"

Project assignment Design and develop your own database php project –work individually and then gather team to determine general idea Make posting to moodle with idea and names of people on team YOU MAY WORK BY YOURSELF. From more, more is expected. –Develop database design (ER diagram) and Data flow diagram Presentations on 11/16 –Complete project Presentations on 12/7