Structured Query Language Chris Nelson CS 157B Spring 2008.

Slides:



Advertisements
Similar presentations
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Advertisements

Introduction to Structured Query Language (SQL)
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)
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Structured Query Language Part I Chapter Three CIS 218.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
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)
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.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
Chapter 7: SQL, the Structured Query Language Soid Quintero & Ervi Bongso CS157B.
Structured Query Language
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.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Introduction to SQL J.-S. Chou Assistant Professor.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
FEN  Concepts and terminology  Operations (relational algebra)  Integrity constraints The relational model.
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
SQL (Chapter 2: Simple queries; Chapter 7 and 8: Nested and DML queries) Many of the examples in this document are based on the tables in the next slide.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) Structured Query Language Introduction to SQL Structured Query Language.
SQL (DDL & DML Commands)
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
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)
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
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.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
SQL advanced select using Oracle 1. 2 Select Simple –data from a single table Advanced –data from more tables join sub-queries.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
(SQL - Structured Query Language)
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
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.
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.
 CONACT UC:  Magnific training   
Copyright © Curt Hill SQL The Data Manipulation Language.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
SQL, the Structured Query Language
More SQL: Complex Queries, Triggers, Views, and Schema Modification
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
More SQL: Complex Queries,
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Using SQL to Prepare Data for Analysis
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Structured Query Language
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL OVERVIEW DEFINING A SCHEMA
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Database systems Lecture 3 – SQL + CRUD
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Contents Preface I Introduction Lesson Objectives I-2
SQL: Structured Query Language
Presentation transcript:

Structured Query Language Chris Nelson CS 157B Spring 2008

Overview Language Selections Joins Insertions Updates and Deletes Aggregate Functions Grouping SQL Training Resources

SQL Language SQL-1 Standardized by ANSI in 1986 Includes Data Definition Lang. (DDL) statements for Schema Modification Includes Data Manipulation Lang. (DML) statements for Data Manipulation SQL-2 Standardized in 1992 SQL-3 standardization still ongoing

Selections Selects  select from where  select is Relational algebra’s projection operation.  where is relational algebra’s selection operation.  Select does not maintain relational algebra’s uniqueness property. Hence the ‘ distinct ’ keyword.

Selection Criteria Numbers/Identities  Can be indicated with an equal sign Strings  Require single quotes  Can be wildcarded using % (multichar) _ (singlechar)  Depending on database implementation, may or may not have to worry about case. Oracle is case sensitive, SQL Server, Postgres, etc. are not

Joins Inner Join  Relational Algebra’s natural join. Joins primary keys on foreign keys. Matching elements will form a tuple in result list. Left/Right Joins  Allows additional null/non-matching columns to be included in result set. Side indicated in join will be the mandatory one. Outer Join  Union of left and right joins. Results will include inner join matches, as well as right and left mismatches.

Joins (Continued) The previous joins follow the format:  Select from tableA tableB on ie: select * from employee left join department on (employee.dept = dept.id); Also, manual joins can be used  Select from tableA, tableB where ie: select * from employee, department where employee.dept = dept.id; // note, not necessarily same result as above

Table Aliasing Used in manual joins. Useful for joining multiple tables, saving typing in where criteria. Follows format:  select.property from where.property = foo;  select p.name, r.balanceOwed from person p, record r where r.patientId = p.id;

Insertions Inserts  insert into tableName (attributes+) values (properties+);  Properties must follow same order as attributes  Can also chain with a select statement to handle a sort of “copy” operation insert into tableName (select…)

Updates and Deletes Updates  Update set = where Deletes  Delete from where Leaving out where criteria will delete/Update everything in the table

Aggregate Functions Count – returns count of matching tuples Average – returns average of specified attribue Max – returns max of specified attribute Min – returns min of specified attribute Sum – returns sum of all rows in table attribute Follow format: select fn( ) from where

Grouping Element grouping  Group by - groups common elements into one tuple  having - used to indicate criteria for grouping Query Unions (select * from xyz) union (select * from abc)

Schema Creation, Deletion Primary Keywords  Create create table { attribName … } usual attribute types include char, varChar(#), int.  Drop Cascade – delete all connected tables (ie: matching key pairs) Restrict – Delete only empty tables These have already been covered in-depth in previous presentations.

Common Errors Using double-quotes instead of single for string literals Forgetting escape characters for words featuring apostrophes ie: ‘o’reilly’ will terminate the string after o should be ‘o\’reilly’

Training Slides are nice, but practice is better than anything. Most databases have sample data sets available/installed (ie: SQL Server’s ‘Northwind’ database. Download here: yID= A0-8DA2- EEBC53A68034&displaylang=en) yID= A0-8DA2- EEBC53A68034&displaylang=en SQL Zoo Has a number of tests and tutorials (they’re actually kind of fun)

References and Recommended Links Principles of Database Systems with Internet and Java Applications, by Greg Riccardi MySQL Intro resources/articles/mysql_intro.htmlhttp://dev.mysql.com/tech- resources/articles/mysql_intro.html W3C School SQL intro