Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.

Slides:



Advertisements
Similar presentations
Structured Query Language (SQL)
Advertisements

A Guide to SQL, Seventh Edition. Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables.
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
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.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Structured Query Language Part I Chapter Three CIS 218.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Concepts of Database Management, 4th Edition, Pratt & Adamski
Introduction to Structured Query Language (SQL)
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Concepts of Database Management, Fifth Edition
Chapter 3 Single-Table Queries
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
With Microsoft Office 2007 Introductory© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Introductory.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Concepts of Database Management Seventh Edition
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Analyzing Data For Effective Decision Making Chapter 3.
A Guide to MySQL 5. 2 Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables Use a subquery.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
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)
Concepts of Database Management Seventh Edition
Querying a Database Access Project 2. 2 What is a Query?  In general, a query is a form of questioning, in a line of inquiry. A query may also refer.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Chapter 4 Multiple-Table Queries
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
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.
Structured Query Language
1 2 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra.
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
1 SQL II CIS*2450 Advanced Programming Concepts. 2 Data Types INTEGER –numbers without a decimal point –range is to SMALLINT –like.
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.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
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.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
3 A Guide to MySQL.
Structured Query Language
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL

Table Creation SQL CREATE TABLE command –Creates a table by describing its layout Typical restrictions placed on table and column names by DBMS –Names cannot exceed 18 characters –Names must start with a letter –Names can contain only letters, numbers, and underscores (_) –Names cannot contain spaces 2

Table Creation (continued) INTEGER –Number without a decimal point SMALLINT –Uses less space than INTEGER DECIMAL(p,q) –P number of digits; q number of decimal places CHAR(n) –Character string n places long DATE –Dates in DD-MON-YYYY or MM/DD/YYYY form 3

Simple Retrieval SELECT-FROM-WHERE: SQL retrieval command –SELECT clause: lists fields to display –FROM clause: lists table or tables that contain data to display in query results –WHERE clause (optional): lists any conditions to be applied to the data to retrieve Simple condition: field name, a comparison operator, and either another field name or a value 4

Simple Retrieval (continued) FIGURE 3-6: SQL query with WHERE condition 5

Simple Retrieval (continued) FIGURE 3-7: Query results 6

Simple Retrieval (continued) FIGURE 3-8: Comparison operators used in SQL commands 7

Compound Conditions Compound condition –Connecting two or more simple conditions using one or both of the following operators: AND and OR –Preceding a single condition with the NOT operator Connecting simple conditions using AND operator –All of the simple conditions must be true for the compound condition to be true Connecting simple conditions using OR operator –Any of the simple conditions must be true for the compound condition to be true 8

Compound Conditions (continued) FIGURE 3-16: Query results FIGURE 3-15: Compound condition that uses the AND operator 9

Compound Conditions (continued) FIGURE 3-18: Query results FIGURE 3-17: Compound condition that uses the OR operator 10

Compound Conditions (continued) Preceding a condition by NOT operator –Reverses the truth or falsity of the original condition BETWEEN operator –Value must be between the listed numbers 11

Computed Fields Computed field or calculated field –Field whose values you derive from existing fields –Can involve: Addition (+) Subtraction (-) Multiplication (*) Division (/) 12

Computed Fields (continued) FIGURE 3-26: Query results FIGURE 3-25: SQL query with a computed field and condition 13

Using Special Operators (LIKE and IN) Wildcards in Access SQL –Asterisk (*): collection of characters –Question mark (?): any individual character Wildcards in MySQL –Percent sign (%): any collection of characters –Underscore (_): any individual character To use a wildcard, include the LIKE operator in the WHERE clause IN operator provides a concise way of phrasing certain conditions 14

Using Special Operators (LIKE and IN) (continued) FIGURE 3-28: Query results FIGURE 3-27: SQL query with a LIKE operator 15

Using Special Operators (LIKE and IN) (continued) FIGURE 3-29: Query results FIGURE 3-28: SQL query with an IN operator 16

Sorting Sort data using the ORDER BY clause Sort key: field on which to sort data When sorting data on two fields: –Major sort key (or primary sort key): more important sort key –Minor sort key (or secondary sort key): less important sort key 17

Sorting (continued) FIGURE 3-34: Query results FIGURE 3-33: SQL query to sort data on multiple fields 18

Built-in Functions Built-in functions (aggregate functions) in SQL –COUNT: calculates number of entries –SUM or AVG: calculates sum or average of all entries in a given column –MAX or MIN: calculates largest or smallest values respectively 19

Built-in Functions (continued) FIGURE 3-36: Query results FIGURE 3-35: SQL query to count records 20

Subqueries Subquery: inner query Subquery is evaluated first Outer query is evaluated after the subquery 21

Subqueries (continued) FIGURE 3-42: Query results FIGURE 3-41: SQL query with a subquery 22

Grouping Create groups of records that share a common characteristic GROUP BY clause indicates grouping in SQL HAVING clause is to groups what the WHERE clause is to rows 23

Grouping (continued) FIGURE 3-46: Query results FIGURE 3-45: SQL query to restrict the groups that are included 24

Joining Tables Queries can locate data from more than one table Enter appropriate conditions in the WHERE clause To join tables, construct the SQL command as: 1.SELECT clause: list all fields you want to display 2.FROM clause: list all tables involved in the query 3.WHERE clause: give the condition that will restrict the data to be retrieved to only those rows from the two tables that match 25

Joining Tables (continued) FIGURE 3-49: SQL query to join tables 26

Joining Tables (continued) FIGURE 3-50: Query results 27

Union Union of two tables is a table containing all rows in the first table, the second table, or both tables Two tables involved must be union compatible –Same number of fields –Corresponding fields must have same data types 28

Union (continued) FIGURE 3-56: Query results FIGURE 3-55: SQL query to perform a union 29

Updating Tables UPDATE command makes changes to existing data INSERT command adds new data to a table DELETE command deletes data from the database 30

Updating Tables (continued) FIGURE 3-58: SQL query to insert a row FIGURE 3-57: SQL query to update data 31

32 Updating Tables (continued) FIGURE 3-59: SQL query to delete rows 32

Creating a Table from a Query INTO clause –Saves the results of a query as a table –Specified before FROM and WHERE clauses MySQL –Create the new table using a CREATE TABLE command –Use an INSERT command to insert the appropriate data into the new table 33

34 Creating a Table from a Query (continued) FIGURE 3-60a: Query to create a new table (Access) 34