1 SQL-Structured Query Language SQL is the most common language used for creating and querying relational databases. Many users can access a database applications.

Slides:



Advertisements
Similar presentations
Relational Algebra Relational algebra consists of a set of relational operators Each operator has one or more relations as input and creates a new relation.
Advertisements

Concepts of Database Management Sixth Edition
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 4 5 6_ SQL SQL Is: Structured Query Language
Introduction to Structured Query Language (SQL)
Chapter 7: Introduction to SQL
Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
1 © Prentice Hall, 2002 Chapter 7: SQL Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
1 IS 4420 Database Fundamentals Chapter 7: Introduction to SQL Leon Chen.
1 Creating a Non-Conditional List A- What are you going to do? You will “list” “all of the records” in a database. (it means you will not use any condition!)
Structured Query Language Part I Chapter Three CIS 218.
SQL Tutorials To understand some of the topics please analyze the following tutorials: The following tutorials will help:
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.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
Introduction to SQL J.-S. Chou Assistant Professor.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
Chapter 3 Single-Table Queries
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Microsoft Access 2010 Building and Using Queries.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 Chapter 7 Introduction to SQL. 2 Objectives Definition of terms Interpret history and role of SQL Define a database using SQL data definition language.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
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
© 2007 by Prentice Hall 1 Chapter 7: Introduction to SQL Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Using Special Operators (LIKE and IN)
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
Lec 3- B Database Integrity 1. Overview Define a database using SQL data definition language Work with Views Write single table queries Establish referential.
© 2005 by Prentice Hall 1 Chapter 7: Introduction to SQL Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
Chapter 7: Introduction to SQL
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.
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.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
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.
SQL Overview Structured Query Language
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Querying Single Tables with SQL.
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 LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Lecture 7: Introduction to SQL Modern Database Management 9 th Edition Jeffrey A. Hoffer,
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
How to: SQL By: Sam Loch.
Web Systems & Technologies
SQL Query Getting to the data ……..
Structured Query Language
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
CHAPTER 6: INTRODUCTION TO SQL
Chapter 4 Summary Query.
Access: SQL Participation Project
ITEC 3220M Using and Designing Database Systems
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

1 SQL-Structured Query Language SQL is the most common language used for creating and querying relational databases. Many users can access a database applications with no knowledge of SQL at all. Sites on the Web allow users to browse the catalog of the site being visited. The information about an item that is presented, such as size, color, etc. is stored in a database The information has been retrieved using an SQL query, but the user has not issued an SQL command. An SQL-based relational database application involves a user interface, a set of tables in the database.

2 SQL-Structured Query Language Within the RDBMS, SQL will be used to create the tables, translate user requests, maintain the data dictionary and system catalog, update and maintain the tables, establish security and carry out backup and recovery procedures. General Syntax: SELECT [ALL|DISTINCT] column_list FROM table_list [WHERE conditional expressions ] [GROUP BY group_by_column_list ] [HAVING conditional expressions ] [ORDER BY order_by_column_list ]

3 SQL-Structured Query Language inserting, updating, and deleting data Once tables have been created, it is necessery to populate them with data and maintain those data. INSERT : is used to populate tables. exp.1) In order to enter data to each column of the table INSERT INTO CUSTOMER VALUES (001, ‘Cavit’, ‘Tüketir’, ’13.Sok. Cuma Apt. 1/A’, ‘Bahçelievler’, ‘Ankara’); exp.2) Data will not be entered into every column in the table; INSERT INTO CUSTOMER (CUST_ID, CUST_NAME, CUST_LNAME) VALUES (001, ‘Cavit’, ‘Tüketir’); exp.3) Populating a table by using a subset of another table with the same structure. INSERT INTO IST_CUSTOMER SELECT * FROM CUSTOMER WHERE CITY = ‘İST’;

4 SQL-Structured Query Language inserting, updating, and deleting data DELETE : rows can be deleted individually or in groups. exp.1) Deleting with a certain criteria DELETE FROM CUSTOMER WHERE CITY = ‘İST’ exp.2) All rows; DELETE FROM CUSTOMER UPDATE: To modify unit price in the product table to 775 UPDATE PRODUCT SET UNIT PRICE = 775 WHERE PRODUCT_ID = 7;

5 SQL-Structured Query Language expressions Using Functions: count, min, max, sum and avg Exp 1): Select count (*) from order_line where order_id = 1004; Exp 2): Select order_id, count (*) from order_line where order id = 1004; Count (*) counts all rows, even null! But “count” counts only the rows that contain a value. Exp 3): Select (product_name) from product; alphabetically it shows the first product name in product table. Using Wildcards: (*) in a Select statement selects all records according to a given condition (%) is used to represent any collection of characters. Using LIKE ‘%Desk’ when searching product name will find all different types of desks.

6 SQL-Structured Query Language expressions Comparison Operators: =, >, >=, or != Exp 4: Select order_id, order_date from order where order_date > ’24-OCT-98’; Exp 5: Select product_name from product where product_name != ‘cherry’; Using Boolean Operators: AND joins two or more conditions and returns results only when all conditions are true. OR joins two or more conditions and returns results when any condition is true. NOT negates an expression. Ranges: The comparison operators are used to establish a range of values. The keyword BETWEEN or NOT BETWEEN can also be used......where unit_price >199 AND unit_price <300;

7 SQL-Structured Query Language expressions Distinct: Sometimes when returning rows that don’t include the primary key, dublicate rows will be returned. Exp 8): Select distinct order_id, quantity from order IN and NOT IN Lists: To match a list of values, consider using IN. Exp 9): Select customer_name, city, state from customer where state IN (‘CA’, ’TX’) Sorting Results:The ORDER BY Clause ORDER BY sorts the final results rows in ascending or descending order. GROUP BY groups rows in an intermediate results table where the values in those rows are the same for one or more columns. HAVING can only be used following a GROUP BY and acts is a secondary WHERE clause, returning only those groups which meet a specified condition.

8 SQL-Structured Query Language using expressions EXAMPLES: 1) SELECT PRODUCT_NAME, PRODUCT_FINISH, PRODUCT_UNIT_PRICE FROM PRODUCT WHERE PRODUCT_NAME LIKE ‘%desk’ OR PRODUCT_NAME LIKE ‘%table’ AND PRODUCT_UNIT_PRICE > 300; 2) SELECT PRODUCT_NAME, PRODUCT_UNIT_PRICE FROM PRODUCT WHERE PRODUCT_UNIT_PRICE >199 AND PRODUCT_UNIT_PRICE<300; 3) SELECT ORDER_ID FROM ORDER_LINE; 4) SELECT DISTINCT ORDER_ID FROM ORDER_LINE; 5) SELECT CITY FROM CUSTOMER GROUP BY CITY HAVING AVG(UNIT_PRICE)<760 ORDER BY CITY;

9 FROM identifies involved tables WHERE Finds all rows meeting stated condition(s) GROUP BY Organizes rows according to values in stated column(s) HAVING Finds all groups meeting stated condition(s) SELECT Identifies columns ORDER BY Sorts rows Results SQL-statement processing order Mandatory clauses are only FROM and SELECT Processing order is different from the order of the syntax used to create statement. Each clause is processed an intermediate results table is produced that will be used for next clasuse. Users do not see the intermediate results tables; only see the final results.