Databases Using MySQL Creating Tables Queries. Databases  A database is a collection of data organized for efficient access  A relational database is.

Slides:



Advertisements
Similar presentations
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Advertisements

Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
PHP and MySQL. Why Use a Database  Easy access to data  Simultaneous access by multiple users is handled properly  Security - easy to control access.
Introduction to Structured Query Language (SQL)
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Introduction to SQL J.-S. Chou Assistant Professor.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Concepts of Database Management, Fifth Edition
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
ASP.NET Programming with C# and SQL Server First Edition
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 3 Single-Table Queries
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
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.
CSC 2720 Building Web Applications Database and SQL.
Database: SQL and MySQL
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Structured Query Language Chris Nelson CS 157B Spring 2008.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Using Special Operators (LIKE and IN)
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Chapter 8 Databases.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
SQL – Structured Query Language
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
 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 Aggregation Oracle and ANSI Standard SQL Lecture 9.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
CMPT 258 Database Systems The Relationship Model (Chapter 3)
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
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.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Chapter 5 Introduction to SQL.
SQL Implementation & Administration
JDBC.
SQL FUNDAMENTALS CDSE Days 2018.
Chapter 22 - SQL, MySQL, DBI and ADO
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Chapter 4 Summary Query.
Access: SQL Participation Project
MySQL Database System Installation Overview SQL summary
SQL Basics BCHB697.
MySQL Database System Installation Overview SQL summary
Manipulating Data Lesson 3.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Databases Using MySQL Creating Tables Queries

Databases  A database is a collection of data organized for efficient access  A relational database is a collection of tables  Columns represent attributes  Rows represent entities  Usually, want one attribute (primary attribute) to be unique

Sample Table dish_iddish_namepriceis_spicy 1Walnut Bun1.000

Sample Tables fnamelnameunamepasswd unameentrycomments tcoleLearning PHP 5book

Structured Query Language  A language create, query and modify relational databases.  SQL commands are not case-sensitive  table and column names are case sensitive in MySQL  White space is not critical  Strings are delimited by single quotes  SQL is not procedural - you specify what result you want not how to get to that result

MySQL  There are a number of database vendors  MySQL is a free database system  installed on onyx  Interacting with MySQL from a shell mysql -p -u php_user show databases \g use databaseName \g show tables \g source loadTables.sql \q

Programming with MySQL  Many programming languages have modules or libraries that support access to databases  perl has the DBI module  PHP has separate modules for each database type as well as the PEAR module which provides a uniform interface to all of them  Java has the JDBC API (java.sql)

Setting Up a Database  CREATE DATABASE databaseName;  USE databaseName;  CREATE TABLE tableName (col1 type1, col2 type2, …);  DROP DATABASE databaseName;  DROP TABLE tableName

Types for Attributes TypeDescription int(length)integer with maximum of length digits decimal(width[,decimal_digits])width is max digits datetimeYYYY-MM-DD HH:MM:SS timeHH:MM:SS dateYYYY-MM-DD timestampYYYYMMDDHHMMSS varchar(length)variable-length string char(length)fixed-length string blobup to 64K of data

Modifiers and Keys  NOT NULL for attribute that must be given a value  DEFAULT "value" to provide default value  int values can be labeled auto_increment to automatically generate unique numbers  PRIMARY KEY (columnName)  KEY keyName (colName1[,colName2])

Example 1 CREATE TABLE DISHES (dish_id INT, dish_name VARCHAR(255), price DECIMAL(4,2), is_spicy INT);

Modifying the Table Data  INSERT  UPDATE  DELETE

Inserting data  INSERT INTO tableName VALUES (v1, v2, …,vn);  use NULL as placeholder for missing values  can insert multiple rows at a time using comma-separated lists  INSERT INTO tableName SET cola=va, colb = vb;  provide values for all columns that can't be null  INSERT INTO tableName (cola, colb, …) VALUES (va, vb, …)

Deleting Data  DELETE FROM tableName;  removes all data from the table  DELETE FROM tableName WHERE colName=value;

Updating Data  UPDATE tableName SET col = value;  updates value of col for all rows in table  UPDATE tableName SET col = value WHERE col=value;  updates only rows which satisfy WHERE clause

Querying the database  SELECT * FROM tableName  show entire table  SELECT col1, col2 FROM tableName  show listed columns from tableName for all rows  SELECT * from tableName WHERE col=value  show rows that match selection criteria

Ordering and Grouping  SELECT * FROM tableName ORDER BY colName [DESC]  sort the rows  You can group rows with the same value in a particular column so that you can compute aggregate values (count, sum, avg, max, min)  SELECT colName, count(*) FROM tableName GROUP BY col2  Use HAVING with a condition to select groups for which an aggregate function meets a particular requirement

WHERE Clauses  WHERE clause limits the rows retrieved by specifying a condition that must be met  look for a particular value or range of values in some column  Use AND and OR to combine conditions  use LIKE for string matching

Things I left out  JOIN - sometimes you need to combine information from two or more tables in a single query.  You can use LIMIT to restrict the number of rows in the output  SELECT DISTINCT outputs a single copy of identical rows in the output

Sources  MySQL website   MySQL Visual Quickstart Guide by Larry Ullman  PHP and MySQL by Hugh E. Williams and David Lane