Structured Query Language b Querying a Single Table b Querying Multiple Tables b EXISTS and NOT EXISTS b Changing Data.

Slides:



Advertisements
Similar presentations
Structured Query Language (SQL)
Advertisements

1 Query-by-Example (QBE). 2 v A “GUI” for expressing queries. –Based on the Domain Relational Calulus (DRC)! –Actually invented before GUIs. –Very convenient.
Database Management Systems 3ed, Online chapter, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Online Chapter Example is the school of mankind,
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Chapter 6 Example is the school of mankind, and they will learn at no.
SQL (2).
Information Resources Management February 27, 2001.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 8 Foundations of Relational Implementation.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
SQL Basics Based on the relational algebra we just learned. Nonprocedural language – what to be done not how Simple, powerful language Used for both data.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
--The SQL Query Language DML--1 LIKE  LIKE allows to select character strings which have some element in common by using wild cards:  Wild cards:  “%”
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
1/2/20101 Lecture 4 on Structural Query Language To study Structural Query Language (SQL) as a non-procedural computer language to access relational database.
© 2002 by Prentice Hall 1 SI 654 Database Application Design Winter 2003 Dragomir R. Radev.
Microsoft Access 2010 Chapter 7 Using SQL.
Computer Science 101 Web Access to Databases SQL – Extended Form.
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
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.
PROC SQL Phil Vecchione. SQL Structured Query Language Developed by IBM in the early 1970’s From the 70’s to the late 80’s there were different types.
Association of Computing Activities Computer Science and Engineering Indian Institute of Technology Kanpur.
Using Special Operators (LIKE and IN)
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Getting to Know SQL. © Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM.
Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle, INGRES, SYBASE, SQL Server, dBase/Win, Paradox,
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
STRUCTURED QUERY LANGUAGE SQL-III IST 210 Organization of Data IST210 1.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
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.
1 IT420: Database Management and Organization SQL part 3 7 February 2006 Adina Crăiniceanu
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.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
WEEK# 12 Haifa Abulaiha November 02,
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
MIDTERM REVIEW IST 210 Organization of Data IST210 1.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
Advanced Accounting Information Systems Day 12 Understanding the SQL Language September 21, 2009.
SQL Reminder Jiankang Yuan Martin Lemke. SQL Reminder - SELECT SELECT column_name1, column_name2, … FROM table_name SELECT * FROM table_name.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Structured Query Language
Structured Query Language
CH 9 SQL 9.1 Querying A Single Table 9.2 Querying Multiple Tables
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
SQL in Oracle.
CS580 Advanced Database Topics
The Database Exercises Fall, 2009.
آزمایشگاه پایگاه داده ها دستورات مهم SQL در SQL Server
SQL FUNDAMENTALS CDSE Days 2018.
SQL – Entire Select.
Chapter 4 Summary Query.
Database systems Lecture 3 – SQL + CRUD
Access: SQL Participation Project
Database Design and Development
Structured Query Language
Structured Query Language – The Fundamentals
Query Functions.
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Structured Query Language b Querying a Single Table b Querying Multiple Tables b EXISTS and NOT EXISTS b Changing Data

Querying a Single Table b Projections Using SQL SELECT MajorSELECT Major FROM STUDENT FROM STUDENTand SELECT DISTINCT Major SELECT DISTINCT Major FROM STUDENT FROM STUDENT

Querying a Single Table (Cont.) b Selections Using SQL SELECT Name, AgeSELECT Name, Age FROM STUDENT FROM STUDENT WHERE Major=MATH AND Age>21 WHERE Major=MATH AND Age>21and SELECT Name SELECT Name FROM STUDENT FROM STUDENT WHERE Major IN [MATH,HISTORY] WHERE Major IN [MATH,HISTORY]

Querying a Single Table (Cont.) b Sorting SELECT Name, Major, AgeSELECT Name, Major, Age FROM STUDENT FROM STUDENT WHERE GradeLevel IN [FR,SO,SN] WHERE GradeLevel IN [FR,SO,SN] ORDER BY Major ASC, Age DESC ORDER BY Major ASC, Age DESC

Querying a Single Table (Cont.) b SQL Built-In Functions COUNT, SUM, AVG, MAX, MINCOUNT, SUM, AVG, MAX, MIN e.g. SELECT COUNT(DISTINCT Major)e.g. SELECT COUNT(DISTINCT Major) FROM STUDENT FROM STUDENTand SELECT Major, COUNT(*) SELECT Major, COUNT(*) FROM STUDENT WHERE Major IN [MATH,HISTORY] GROUP BY Major HAVING COUNT(*)>2

Querying Multiple Tables b Using Subqueries What are the names of the students enrolled in the class BD445?What are the names of the students enrolled in the class BD445? SELECT Name FROM STUDENT WHERE SID IN (SELECT StudentNumber FROM ENROLMENT FROM ENROLMENT WHERE ClassName=BD445) WHERE ClassName=BD445)

Querying Multiple Tables (Cont.) What are the names of the students enrolled in classes on Monday, Wednesday, and Friday at 3 oclock (MWF3)?What are the names of the students enrolled in classes on Monday, Wednesday, and Friday at 3 oclock (MWF3)? SELECT STUDENT.Name FROM STUDENT WHERE STUDENT.SID IN (SELECT ENROLLMENT.StudentNumber FROM ENROLLMENT FROM ENROLLMENT WHERE ENROLLMENT.ClassName IN WHERE ENROLLMENT.ClassName IN

(SELECT CLASS.Name FROM CLASS WHERE CLASS.Time=MWF3)) Querying Multiple Tables (Cont.)

b Joining with SQL List the student number and class name of all students named RYE who were first to enroll in a class.List the student number and class name of all students named RYE who were first to enroll in a class. SELECT STUDENT.SID, ENROLMENT.ClassName FROM STUDENT, ENROLLMENT WHERE STUDENT.SID=ENROLLMENT.StudentNumber AND ENROLLMENT.PositionNumber=1 AND STUDENT.Name= RYE

Querying Multiple Tables (Cont.) b EXISTS and NOT EXISTS List the student numbers of students enrolled in more than one class.List the student numbers of students enrolled in more than one class. SELECT DISTINCT StudentNumber FROM ENROLLMENTA WHERE EXISTS (SELECT * FROM ENROLLMENTB FROM ENROLLMENTB WHERE A.StudentNumber=B.StudentNumber WHERE A.StudentNumber=B.StudentNumber AND A.ClassName NOT = B.ClassName) AND A.ClassName NOT = B.ClassName)

Querying Multiple Tables (Cont.) b CHANGING DATA Inserting DataInserting Data INSERT INTO ENROLLMENT VALUES(400,BD445,44) Deleting DataDeleting Data DELETE STUDENT WHERE STUDENT.Major=Accounting Modifying DataModifying Data UPDATE ENROLLMENT SET PositionNumber=44 WHERE SID=400