Creating Databases More SQL. Design. Original Project Assignment Homework: Post proposal. Continue with planning.

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Normalization Queries (contd)
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Week 2 Normalization and Queries
Concepts of Database Management Sixth Edition
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
LSP 121 Week 2 Normalization and Queries. Normalization The Old Car Club database presented a problem – what if one person owns multiple cars? (One owner.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Creating Databases SELECT. UPDATE. Demonstrate projects. Classwork / Homework: Prepare to choose teams & projects.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
CS2008/CS5035 Exam Preparation. Dept. of Computing Science, University of Aberdeen2 Organization of Lecture Notes Group 1 - SQL –L1 – Introduction –L2.
Creating databases for web applications
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.
Creating databases for web applications Walk before run? Songs with features example. Retrieve information from database. Recordsets. Arrays. Loops. Homework:
Server-side Scripting Powering the webs favourite services.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
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.
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.
1 Intro to JOINs SQL INNER JOIN SQL OUTER JOIN SQL FULL JOIN SQL CROSS JOIN Intro to VIEWs Simple VIEWs Considerations about VIEWs VIEWs as filters ALTER.
ITCS373: Internet Technology Lecture 5: More HTML.
Views Lesson 7.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Information Technologies and Microsoft SQL Server Day 2 by Alper Özpınar
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
Creating Databases for web applications [Complete presentations] More SQL Class time: discuss final projects. Do posting if you have not done it.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Creating databases for web applications Library. New example: student database. Homework: Complete class example. Catch up on source postings. Do creation.
1 Introduction to Oracle Chapter 1. 2 Before Databases Information was kept in files: Each field describes one piece of information about student Fields.
Copyright © Curt Hill Queries in SQL More options.
Copyright © Curt Hill Joins Revisited What is there beyond Natural Joins?
Creating Web Documents catch-up JavaScript slide show tools redirection.
Creating databases for web applications Report on using sources, getting examples working. Retrieve information from database. Recordsets. Arrays. Loops.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Creating Databases for Web applications SQL. XML. Linked Lists. NoSQL. Homework: Keep working on projects. Post constructive feedback on other projects.
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
Entity Relationship Diagram (ERD). Objectives Define terms related to entity relationship modeling, including entity, entity instance, attribute, relationship.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
For more course tutorials visit CIS 336 All iLabs Week 1 to Week 7 Devry University CIS 336: All iLabs Week 1 to Week 7: Devry University.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Creating Databases for Web applications Making a table of table information. Reprise on database design. SQL. Classwork/Homework: Projects! Postings.
Creating Databases for Web applications
Confirm teams. Review of diagrams. SELECT problems.
View Integration and Implementation Compromises
Creating Databases Local storage. join & split
Creating databases for web applications
Creating Databases for Web Applications
Creating Databases More SQL. Design. Original Project Assignment
How does a Requirements Package Vary from Project to Project?
Structured Query Language (SQL) William Klingelsmith
Creating Databases SELECT. UPDATE. Demonstrate projects. Do not track.
Presentation transcript:

Creating Databases More SQL. Design. Original Project Assignment Homework: Post proposal. Continue with planning.

MySQL or most DBMS products can specify fields in records as FOREIGN KEY and do the work of checking. My examples do not use this but instead do the checking in the php.

LOCK and UNLOCK Most database applications are for use by multiple users. You don't want two or more users updating the same record –WHY NOT? Most DBMS products have ways to support lengthy transactions. POSTING OPPORTUNITY

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…

Recall songs, features, featuresinsongs

Multiple tables conditions SELECT from multiple tables (use commas) 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 This land is your landPolitical I told you soPolitical somethingPop something elseClassical

More SQL Assuming the simple student database (id, sname, department, gpa) Produce a list of departments, with number of students, average, maximum, and minimum gpa Produce a list of departments, number of students with gpa at least 2 (not on academic probation?) Produce a list of departments, number of students on academic probation, limit to the 5 with the most on academic probation

Students in clubs Assume the student table (sid, sname, dept, gpa) plus 2 more tables –clubs: clubid, clubname, clubdesc –clubmemberships: mid, sid, clubid Usual technique, similar to tags, ordered items.

Generate list of students in club named Hiking SELECT s.sname FROM students as s, clubs as c, clubmemberships as m WHERE c.clubname='Hiking' AND m.clubid=c.clubid AND s.sid=m.sid ALTERNATIVE (may need parentheses) SELECT s.sname FROM students as s JOIN clubmemberships as m ON m.sid = s.sid JOIN clubs as c WHERE clubname='Hiking' ON m.clubid=c.clubid

Left Join Matches rows of two tables using the ON condition, but if something on the LEFT does not have a match, generate a row with null values. Used in the quiz show to find questions that haven't been answered or asked recently. NOTE: can have SELECT within a SELECT

Students not in any club SELECT sname FROM SELECT * FROM students as s LEFT JOIN clubmemberships as m ON s.sid=m.sid WHERE m.sid=null

php to php One way to acquire and pass information from one php script to another is to use the query string. In the store application, html is produced that has tags with href=makeorder.php?3 for example, where 3 represents a product id.

Select product: <?php $query="Select * from catalog"; $result=mysql_db_query($DBname, $query, $link); while ($row=mysql_fetch_array($result)) { print (" <a href=makeorder.php"); print ("?p_id="); print($row['id']); print(">"); print($row['p_name']); print(" "); print(" <img src=\""); $picture=$row['picture']; print("$picture"); print("\" width='200'> "); } print (" ");

General principles for SQL You need to build the Select statement –pencil in hand, work in steps Decide the tables needed Decide on logical conditions for records contributing to the result –WHERE Decide on conditions connecting tables –JOIN ON

General principles, cont. The GROUP BY command combines / aggregates records based on common values, using aggregate operations such as COUNT, AVG, SUM,etc. If you want to maintain individual records but bunch them together, use ORDER Remember order high to low requires DESC

General principles, cont. For condition on which individual records to use: WHERE For condition on aggregated (GROUP BY) records: HAVING DISTINCT will extract [just] one from a table for the specified field

Operational definition … is what you call the definition of something that is used in a process. For example: –freshmen, sophomores, juniors, seniors –Dean's list, academic probation –???

Aside Last week, we had meeting for rising seniors I/we gave up on sending invitation to just that group and invited everyone. –We used . –We believe some rising seniors did not attend!

Generate a list of names of clubs Just need one table SELECT clubname FROM clubs But what if I wanted clubs with members? need the clubs table and the clubmemberships table Join on cid

List of names of clubs with actual members SELECT DISTINCT clubname FROM clubs as c JOIN clubmemberships as m ON c.cid=m.cid could write c.clubname, but not needed since there is no ambiguity. Don't worry about this.

List names of clubs with at least 5 members SELECT c.cid, c.clubname, COUNT(*) as n FROM clubs as c JOIN clubmemberships as m ON c.cid=m.cid GROUP BY c.cid HAVING n>=5 This produces more information than requested. Could probably leave out the c.cid and instead GROUP by clubname. This would be better if there is a chance of ambiguity.

List names of any club with at least one freshmen SELECT DISTINCT clubname FROM clubs as c JOIN clubmemberships as m ON c.cid=m.cid JOIN students as s ON m.sid=s.sid WHERE s.credits <30 Creating a table using the clubmembership table with information added from other tables. Records only go into the table if the student's record has credits<30. Use DISTINCT to get the distinct club names. Don't need other information.

List all clubs by name with number of sophomores Need to use all 3 tables Need to use WHERE clause to get sophomores –Operational definition: sophomore means between 30 and 60 credits. Use LEFT JOIN to pick up clubs with no matches since for this example, I want clubs with no sophomores to show up! –Use COUNT(m.id) to NOT count any NULL fields!

[should check use of ( ) ] SELECT clubname, COUNT(m.mid) as num from CLUBS as c LEFT JOIN (clubmemberships as m JOIN students as s ON m.sid = s.sid WHERE s.credits BETWEEN 30 AND 60) ON c.cid=m.cid GROUP BY clubname

Possible result Young Dems40 Young Repubs 3 Origami10 Hiking 0

Generate list of students with the clubs each one belongs to… CurleyCircus Hiking PTV LarryCircus Origami MoeHiking

Planning Will need SQL and then php Need 3 tables (need club names and student names) Need to place all records for each student together, but not aggregated. Use ORDER BY

SQL SELECT s.sid, s.sname as a,c.clubname as b FROM students as s JOIN clubmemberships as m ON s.sid=m.sid JOIN clubs as c ON m.cid=c.cid ORDER BY s.sid s.sname Note: information just in the clubmembership table isn't part of the resultset BUT those records are the only ones represented in the resultset.

php … // assume $result is the result of query $curstudent=""; print(" Student Club "); while ($row=mysql_fetch_array($result)) { print(" "); if ($curstudent!=$row['a']) { $curstudent=$row['a']; print("$curstudent "); } else { print (" "); } print(" ".$row['b']." "); } print(" ");

Misc. Can order using multiple fields ….. ORDER BY lname, fname WHERE or HAVING condition can use –IN …. WHERE clubname IN ('Hiking', 'Origami') –BETWEEN … WHERE gpa BETWEEN 3 AND 4 ALSO can use BETWEEN for dates and times NOTE: other ways to do these. EXTRA CREDIT: look up & report on ROLLUP

Planning Planning (system design where design has broad meaning, not specifically the look) –comes first! –can change Document the structure of database using ER diagram and the potential tasks (processes) of the application using the DFD –ER: entities and relationships –recall DFD: agents, processes, data stores

Database table design Don't have same information in more than one table. For example: –The records in an orders table points to a customer table. A customer's address is not in each order.

Data flow diagram place to specify Processes: actions/tasks/operations of your application. Agents: Who is doing what with/to information. Data stores –This is an attempt to not be specific about how data kept. Don't get bogged down in details of the information right now.

Presentation What is the application? Show the information structure using an ER diagram. Show the processes/operations/tasks using a Data flow diagram. No storyboard (not yet) May show a sketch of one or more screens. Time for constructive comments from audience

Team work …. is not always smooth. That is part of the reason for the assignments. Do post names of everyone on the team. Everyone should understand everything! People do have different talents but EVERYONE can participate!

Comment Large[r] organizations have elaborate tools for project proposals. –proposals –communication –testing –documentation –deployment. Most work is incremental: fixing bugs and making enhancements.

Classwork/homework/classwork Start/continue: –ideas, teams, planning Next class: work session on planning Following class: 4/20: Present plans using diagrams