CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
Advertisements

Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
Introduction to Structured Query Language (SQL)
1 Introduction to Web Application Introduction to Data Base.
5 Chapter 5 Structured Query Language (SQL1) Revision.
Introduction to Structured Query Language (SQL)
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Exercise SELECT authorID, lastName FROM authors AuthorID FirstName
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 25 – Database: SQL, ADO and RDS Outline 25.1Introduction 25.2Relational Database Model 25.3Relational.
ASP.NET Programming with C# and SQL Server First Edition
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Database: SQL and MySQL
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
Relational Database. Database Management System (DBMS)
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 CSE 2337 Introduction to Data Management Access Book – Ch 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved. 2 Revised by Dr. T. Tran for CSI3140.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
Sql DDL queries CS 260 Database Systems.
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
 2009 Pearson Education, Inc. All rights reserved Databases and LINQ to SQL.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
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.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
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.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Introduction to Database Programming with Python Gary Stewart
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Fundamentals of DBMS Notes-1.
Database, SQL and ADO.NET
 2012 Pearson Education, Inc. All rights reserved.
JDBC.
Databases Intro (from Deitel)
Databases - בסיסי נתונים
Chapter 22 - SQL, MySQL, DBI and ADO
MySQL Database System Installation Overview SQL summary
MySQL Database System Installation Overview SQL summary
Manipulating Data Lesson 3.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

CHAPTER 8 Database: SQL, MySQL

Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured Query Language)Basic SELECT Query  WHERE Clause  ORDER BY Clause  Merging Data from Multiple Tables: INNER JOIN  Joining Data from Tables Authors, AuthorISBN, Titles and Publishers  INSERT Statement  UPDATE Statement  DELETE Statement

Introduction Database –Integrated collection of data –Database management system (DBMS) Store and organize data consistent with database’s format Relational database –SQL (Structured Query Language) »Queries »Manipulate data

Relational Database Model Composed of tables Row –Number column –Primary key Reference data in the table A column or set of columns in table contains unique data

Relational Database Model 5 Fig. 22.1Relational database structure of an Employee table.

6 Relational Database Model departmentlocation 413New Jersey 642Los Angeles 611Orlando Fig. 22.2Table formed by selecting department and location data from the Employee table.

Relational Database Model Primary key uniquely identifies each row –Rule of Entity Integrity Composite primary key Lines connecting tables –Relationships One-to-many relationship Foreign key –Join multiple tables –Rule of Referential Integrity

8 Employee Staff_IDNameDepartment 123AhmadGraphic 456ArdenHR 789ZikryEngineering 222SafiaEngineering 111HendraFinance Department Graphic HR Engineering Finance Primary Key Foreign Key When these two tables are linked, Department is a foreign key in table Employee. Data in Department column may be repeatable. Department is a primary key in table Department. Data in Department column must be unique.

MySQL Data Types When creating a MySQL table, specifying a data type for every field is necessary. This data type plays an important role in enforcing the integrity of the data in a MySQL database, and in making this data easier to use and manipulate.

MySQL Data Types TypeUsed For TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT Integer values FLOATSingle-precision floating-point values DOUBLEDouble-precision floating-point values DECIMALDecimal values CHARFixed-length strings up to 255 characters VARCHARVariable-length strings up to 255 characters TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB Large blocks of binary data TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT Longer blocks of text data DATEDate values TIMETime values or durations YEARYear values DATETIMECombined date and time values TIMESTAMPTimestamps ENUM Fields that must contain one of a set of predefined mutually exclusive values SETFields that can contain zero, one, or more of a set of predefined values

MySQL Data Types If you try to use a value that’s too big for the filed you’re placing it in, MySQL will automatically truncate or round the value down to the maximum allowed value for that field. The data types different with each others in term of size of values that they can store.

12 Relational Database Overview: Books.mdb Database

13 Relational Database Overview: Books.mdb Database

14 Relational Database Overview: Books.mdb Database

15 Relational Database Overview: Books.mdb Database

16 Relational Database Overview: Books.mdb Database

17 Relational Database Overview: Books.mdb Database

18 Relational Database Overview: Books.mdb Database Fig Table relationships in Books.mdb Foreign key- can appears many times in its own table Appears exactly once as primary key of other table

19 SQL (Structured Query Language)

20 Basic SELECT Query SELECT * FROM tableName –SELECT * FROM Authors –SELECT authorID, lastName FROM Authors

21 Basic SELECT Query

22 WHERE Clause Specify selection criteria for query –SELECT columnName1, columnName2, … FROM tableName WHERE criteria SELECT title, editionNumber, copyright FROM Titles WHERE copyright > 1999 –LIKE Pattern matching –Asterisk ( * ) »SELECT authorID, firstName, lastName FROM Authors WHERE lastName LIKE ‘D*’ –Question mark ( ? ) »SELECT authorID, firstName, lastName FROM Authors WHERE lastName LIKE ‘?I*’

23 WHERE Clause

24 WHERE Clause

25 WHERE Clause

26 ORDER BY Clause Arranged in ascending or descending order –SELECT columnName1, columnName2, … FROM tableName ORDER BY column ASC SELECT authorID, firstName, lastName FROM Authors ORDER BY lastName ASC –SELECT columnName1, columnName2, … FROM tableName ORDER BY column DESC SELECT authorID, firstName, lastName FROM Authors ORDER BY lastName DESC

27 ORDER BY Clause

28 ORDER BY Clause

29 ORDER BY Clause SELECT authorID, firstName, lastName FROM Authors ORDER BY lastName, firstName

30 ORDER BY Clause

31 ORDER BY Clause SELECT isbn, title, editionNumber, copyright, price FROM Titles WHERE title LIKE ‘*How to Program’ ORDER BY title ASC

32 Merging Data from Multiple Tables: INNER JOIN Normalize databases –Ensure database does not store data redundantly –SELECT columnName1, columnName2, … FROM table1 INNER JOIN table2 ON table1, columnName = table2.columnName

<?php // Make a MySQL Connection // Construct our join query $query = "SELECT family.Position, food.Meal ". "FROM family, food ". "WHERE family.Position = food.Position"; $result = mysql_query($query) or die(mysql_error()); // Print out the contents of each row into a table while($row = mysql_fetch_array($result)){ echo $row['Position']. " - ". $row['Meal']; echo " "; }?> Merging Data from Multiple Tables: INNER JOIN family Table food Table Output: Dad - Steak Mom - Salad Dad - Tacos

34 Merging Data from Multiple Tables: INNER JOIN –SELECT firstName, lastName, isbn FROM Authors INNER JOIN AuthorISBN ON Authors.authorID = AuthorISBN.authorID ORDER BY lastName, firstName

35 Merging Data from Multiple Tables: INNER JOIN

36 Fig (1 of 1)

37 Joining Data from Tables Authors, AuthorISBN, Titles and Publishers

38 Joining Data from Tables Authors, AuthorISBN, Titles and Publishers

39 INSERT Statement Inserts new row in table –INSERT INTO tableName ( columnName1, columnName2, …, columnNameN ) VALUES ( value1, value2, …, valueN ) –INSERT INTO Authors ( firstName, lastName ) VALUES ( ‘Sue’, ‘Smith’ )

40 INSERT Statement

41 UPDATE Statement Modifies data in a table –UPDATE tableName SET columnName1 = value1, columnName2 = value2, …, columnNameN = valueN WHERE criteria –UPDATE Authors SET lastName = ‘Jones’ WHERE lastName= ‘Smith’ AND firstName=‘Sue’

42 UPDATE Statement

43 DELETE Statement Removes data from a table –DELETE FROM tableName WHERE criteria –DELETE FROM Authors WHERE lastName=‘Jones’ AND firstName=‘Sue’

44 DELETE Statement

45 MySQL Multi-user and multi-threaded RDBMS server Uses SQL to interact with and manipulate data Supports various programming languages Access tables from different databases Handle large databases The next chapter explains the usage of MySQL with PHP.