SQL -I Reading: C&B, Chaps 6, 7, 8 & 9. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn The basic concepts and principles.

Slides:



Advertisements
Similar presentations
NTAUG Introduction in to use of SQL Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,
Advertisements

Dept. of Computing Science, University of Aberdeen1 Writing SELECT SQL Queries Nigel Beacham based on materials.
Logical Database Design Reading: C&B, Chap 17. Dept. of Computer Science, University of Aberdeen2 In this lecture you will learn What is logical database.
Access Control & Views Reading: C&B, Chap 7. Dept of Computing Science, University of Aberdeen2 In this lecture you will learn the principles of object.
Database Design: ER Modelling
Query Processing Reading: CB, Chaps 5 & 23. Dept of Computing Science, University of Aberdeen2 In this lecture you will learn the basic concepts of Query.
Data Definition and Integrity Constraints
Database Design: Normalization
File Organization & Indexing Reading: C&B, Ch 18 & 23.
SQL-II Reading: C&B, Chap 6, 7, 8 & 9. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn how to sort and group query.
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Virtual training week 4 structured query language (SQL)
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Introduction to Structured Query Language (SQL)
 Review HW #4  Answer questions about Microsoft Visio  Introduce SQL  Introduce SQL Server 2008 environment for programming SQL  Will meet in AB208.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 2 Structured Query Language.
Introduction to Structured Query Language (SQL)
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Introduction to Structured Query Language (SQL)
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
1 IT420: Database Management and Organization SQL: Structured Query Language 25 January 2006 Adina Crăiniceanu
Chapter 2 Basic SQL SELECT Statements
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
CSC271 Database Systems Lecture # 10.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CIS 103 — Applied Computer Technology Last Edited: September 17, 2010 by C.Herbert Using Database Management Systems.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
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.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
Oleh Munawar Asikin. Principles of Information Systems, Seventh Edition 2  Database management system (DBMS): group of programs that manipulate database.
SQL: Data Manipulation I Chapter 5 CIS 458 Sungchul Hong.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
SQL 101 – Class 1 Lee Turner. Agenda 1. This is your life – SQL A brief history of SQL What SQL is and what it is not Normalization 2. Some Super Simple.
Oracle & SQL Introduction. Database Concepts Revision DB? DBMS? DB Application? Application Programs? DBS? Examples of DBS? Examples of DBMS? 2Oracle.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
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.
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.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
1 SY306 Web and Databases for Cyber Operations SQL: Structured Query Language.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
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.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 10 SQL DDL.
Chapter 5 Introduction to SQL.
REV 00 Chapter 4 SQL and QBE DDC 2483 – Database Systems.
Oracle & SQL Introduction
STRUCTURED QUERY LANGUAGE
SQL .. An overview lecture3.
SQL-1 Week 8-9.
CSC 453 Database Systems Lecture
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Chapter Name SQL: Data Manipulation
Presentation transcript:

SQL -I Reading: C&B, Chaps 6, 7, 8 & 9

Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn The basic concepts and principles of SQL How to use SQL to perform basic database queries The different components of SQL How SQL can be described by a meta- language (BNF) The principles of Query By Example (QBE)

Dept. of Computing Science, University of Aberdeen3 Relational Tables Can Answer Many Queries Student EnrolmentCourse How many courses are there & what are their names? Which students are enrolled for Java? How many students take 3 or more courses?

Dept. of Computing Science, University of Aberdeen4 SQL - Structured Query Language SQL was developed at IBM around Structured programming? No! - Structured English (from SEQUEL) SQL is a declarative language - says what not how SQL is an abstract & portable interface to RDMBs Warning: different vendors have dialects & extensions These notes & course text book: ANSI SQL (ANSI = American National Standards Institute) This course: Microsoft Access and MySQL

Dept. of Computing Science, University of Aberdeen5 SQL Syntax SQL uses English keywords & user-defined names CREATE TABLE Staff ( StaffNo INTEGER, Salary FLOAT, Lname VARCHAR(20) ); INSERT INTO Staff VALUES (32, , 'Smith'); By convention, keywords are upper-case Text data is enclosed using single quotes ( ' ) Round brackets (() are used to group related items Commas (,) separate items in a list Statements are terminated with a semicolon (;)

Dept. of Computing Science, University of Aberdeen6 Simple Queries Using SELECT The SELECT statement retrieves & formats data SELECT is the most frequently used SQL statement SELECT * FROM Staff; Here, asterisk (*) acts as a wild card - all columns By default, SELECT outputs all the rows in the table Use SELECT DISTINCT target_list FROM Staff; for avoiding duplicates

Dept. of Computing Science, University of Aberdeen7 SELECT SELECT target-list FROM relation-list WHERE qualification; relation-list- A list of relation names. target-list -A list of attributes of relations in relation-list qualification -Comparisons (Attr op const or Attr1 op Attr2, where op is one of,=,, =) combined using AND, OR and NOT.

Dept. of Computing Science, University of Aberdeen8 Selecting Specific Columns Specific columns can be output by giving their names: SELECT Lname, Position, Salary FROM Staff; NB. must have a comma (,) between column names Can consider the output from SELECT as a new table

Dept. of Computing Science, University of Aberdeen9 Selecting Specific Rows & Columns Specific rows can be selected with a WHERE clause: SELECT Lname, Position, Salary FROM Staff WHERE Salary > 20000; The symbol > (greater than) is a comparison operator Other comparison operators: =; ! =; <> The condition Salary > is called a predicate For each row, if predicate is true, row is output

Dept. of Computing Science, University of Aberdeen10 Building Up Complex Predicates Predicates evaluate to either true or false Predicates can be combined using AND, OR, and NOT Use brackets to avoid ambiguity The next two statements are different: SELECT * FROM Staff WHERE (Position = 'Manager') OR (Position = 'Assistant' AND Salary > 10000); SELECT * FROM Staff WHERE (Position = 'Manager' OR Position = 'Assistant') AND NOT (Salary <= 10000); In each case, whole WHERE clause is true or false

Dept. of Computing Science, University of Aberdeen11 Other Types of Predicate Other predicates include BETWEEN, IN, and LIKE But they still evaluate to either true or false SELECT * FROM Staff WHERE (Salary BETWEEN AND 20000) AND (Position IN ('Manager', 'Assistant')) AND (Lname LIKE 'S%' OR Lname LIKE 'W____'); '%' matches zero or more characters '_' matches exactly one character NB. Some DMBSs use * and ? for wildcards

Dept. of Computing Science, University of Aberdeen12 SQL Terminology SQL does not use formal relational terminology Formal Informal (SQL) Relation Table Tuple Row Attribute Column Cardinality No. of rows Degree No. of columns Relationships Foreign keys Constraints Assertions

Dept. of Computing Science, University of Aberdeen13 SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main categories (or sub-languages): Data Definition Language (DDL) for creating a DB e.g. CREATE, DROP, ALTER Data Control Language (DCL) for administering a DB e.g. GRANT, DENY, USE Data Manipulation Language (DML) to access a DB e.g. SELECT, INSERT, UPDATE, DELETE

Dept. of Computing Science, University of Aberdeen14 Describing SQL Syntax Using BNF Notation CB use a special BNF notation to describe SQL syntax: BNF (Backus-Naur form) is a meta language... meta language: a language that describes a language SELECT [ DISTINCT | ALL ] { * | [ Colexpr [ AS Newcol ] ] [,...] } FROM TableName [ Alias ] [,...] [ WHERE Predicate ] [ GROUP BY Columnlist ] [ HAVING Predicate ] [ ORDER BY Columnlist ] [;] [ ] optional; { } required; | alternative;... zero or more

Dept. of Computing Science, University of Aberdeen15 Query By Example (QBE) Modern DBMSs often provide simple form-based methods of specifying queries (QBE). For example, MS-Access: Generates the following SQL: SELECT * FROM Staff WHERE (Fname LIKE 'W%' AND Position = 'Manager') OR (Salary > 15000);

Dept. of Computing Science, University of Aberdeen16 Conclusion SQL is the standard query language for RDBMS Three main categories of SQL –DDL, Data Definition Language –DCL, Data Control Language –DML, Data Manipulation Language SELECT belongs to DML SELECT retrieves & displays data from the database We continue to explore DML