SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle, INGRES, SYBASE, SQL Server, dBase/Win, Paradox,

Slides:



Advertisements
Similar presentations
Structured Query Language (SQL)
Advertisements

Structured Query Language b Querying a Single Table b Querying Multiple Tables b EXISTS and NOT EXISTS b Changing Data.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Database Management Systems & Programming Faculty of Information & Media Studies Summer 2000 LIS Week 6 Structured Query Language.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
1 Query Languages: How to build or interrogate a relational database Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Structured Query Language Part I Chapter Three CIS 218.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
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.
Introduction to SQL Structured Query Language Martin Egerhill.
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
Chapter 3 Single-Table Queries
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.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) Structured Query Language Introduction to SQL Structured Query Language.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Relational Algebra CS420. Relation A relation is a two dimensional table that Rows contain data about an entity Columns contains data about attributes.
Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Copyright © Curt Hill Queries in SQL More options.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Structured Query Language (SQL) Ask and ye shall receive. The Bible.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
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.
(C) 2000, The University of Michigan 1 Database Application Design Handout #5 February 4, 2000.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  Basic SQL syntax  Data retrieve  Data query  Data conditions  Arithmetic operations on data  Data transactions.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
© 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.
WEEK# 12 Haifa Abulaiha November 02,
MIS2502: Data Analytics SQL – Getting Information Out of a Database.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Structured Query Language (SQL) IBM RESEARCH PROJECT (SEQUEL) –E.F. CODD, JUNE 70, ACM –CONTINUED RESEARCH THROUGH 70S –CLONE MAKER BANDWAGON AMERICAN.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Structured Query Language
CH 9 SQL 9.1 Querying A Single Table 9.2 Querying Multiple Tables
SQL FUNDAMENTALS CDSE Days 2018.
Structured Query Language
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
SQL – Entire Select.
Access: SQL Participation Project
Chapter 7 Introduction to Structured Query Language (SQL)
Structured Query Language
M1G Introduction to Database Development
Introduction To Structured Query Language (SQL)
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle, INGRES, SYBASE, SQL Server, dBase/Win, Paradox, Access, and others all rely upon SQL

Introduction to SQL IBM in the mid-1970s as SEQUEL SQ92 = 1992 ANSI standard [a newer standard exists for SQL to extend it to object- oriented languages] data access language that is embedded in application programs result of an SQL statement is a relation

many vendors go beyond the ANSI standards for SQL because they want to better position their product in relation to their competitors consequently there are minor variations among vendors

stand-alone –SQL can be used by itself to retrieve and report information embedded –SQL is frequently embedded in application programs SQL is not a programming language

Sample Data STUDENT Relation ENROLLMENT Relation CLASS Relation

Simple Select SELECT SID, Name, Major FROM STUDENT STUDENT Relation

SELECT Major FROM STUDENT SELECT DISINCT Major FROM STUDENT STUDENT Relation as opposed to

SELECT DISINCT Major FROM STUDENT

Selection SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE Major = ‘MATH’ STUDENT Relation

SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE Major = ‘MATH’

Selection SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE Major = ‘MATH’ AND Age>21 STUDENT Relation

SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE Major = ‘MATH’ AND Age>21

Selection SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE GradeLevel IN [‘FR’, ‘SO’] STUDENT Relation What about NOT IN ?

SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE GradeLevel IN [‘FR’, ‘SO’]

Selection SELECT Name FROM STUDENT WHERE Name LIKE ‘R%’ STUDENT Relation % is a wildcard match, like * is a wildcard match _ (the underscore symbol) is for a character-by-character match

Sorting SELECT Name, Major, Age FROM STUDENT WHERE Major = ‘ACCOUNTING’ ORDER BY Name STUDENT Relation

SELECT Name, Major, Age FROM STUDENT WHERE Major = ‘ACCOUNTING’ ORDER BY Name

Sorting SELECT Name, Major, Age FROM STUDENT WHERE Major = ‘ACCOUNTING’ ORDER BY Name DESC STUDENT Relation ASC is for ascending

SQL Built-In Functions there are five –COUNT –SUM [only applies to numeric fields] –AVG [only applies to numeric fields] –MIN –MAX

SQL Built-In Functions SELECT COUNT(Major) FROM STUDENT SELECT COUNT(DISTINCT Major) FROM STUDENT yields 8 as the answer yields 3 as the answer

SELECT COUNT(DISTINCT Major) FROM STUDENT

Grouping SELECT Major, COUNT(*) FROM STUDENT GROUP BY Major HAVING COUNT(*) > 1 FROM and WHERE go together and GROUP BY and HAVING go together

Querying Multiple Tables Retrieval Using Subquery Joining with SQL

what are the names of students in BD445? ENROLLMENT Relation CLASS Relation STUDENT Relation

Subquery (the second SELECT) SELECT Name FROM STUDENT WHERE SID IN (SELECT StudentNumber FROM ENROLLMENT WHERE ClassName = ‘BD445’) this SELECT yields 100 and 200 so this SELECT yields Jones and Baker

Joining with SQL SELECT STUDENT.SID, STUDENT.Name, ENROLLMENT.ClassName FROM STUDENT, ENROLLMENT WHERE STUDENT.SID = ENROLLMENT.StudentNumber column names are unique within a table but it helps to ‘fully qualify’ a column name when more than one table is targeted by the FROM parameter students not in a class don’t get reported, why? in a JOIN always look to match the common column values

SELECT STUDENT.SID, STUDENT.Name, ENROLLMENT.ClassName FROM STUDENT, ENROLLMENT WHERE STUDENT.SID = ENROLLMENT.StudentNumber

What Is The Answer To This Query? SELECT SID, Name FROM STUDENT WHERE SID NOT IN (SELECT DISTINCT StudentNumber FROM ENROLLMENT) what is this query really asking? why is DISTINCT used?

Inserting Data INSERT INTO ENROLLMENT VALUES (400, ‘BD445’, 44) you must know both the field order and field type; text fields require surrounding apostrophes to insert a STUDENT record where you don’t know the Major or GradeLevel INSERT INTO STUDENT VALUES (500, ‘Hamilton’,,, 45) notice the empty positions will place null values in the table key values must always be entered

Modifying Data UPDATE ENROLLMENT SET PositionNumber = 44 WHERE SID = 400 be careful of wildcard matches

Deleting Data DELETE STUDENT WHERE STUDENT.SID = 100 probably the most dangerous SQL statement