1 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL Structured Query Language.

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Advertisements

Yong Choi School of Business CSU, Bakersfield
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
COMP 5531 Introduction to MySQL. SQL SQL is a standard language for accessing and managing databases. SQL stands for Structured Query Language.
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Virtual training week 4 structured query language (SQL)
SQL Structured Query Language. SQL The SELECT Statement The SELECT statement is used to select data from a table. The tabular result is stored in a result.
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.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
1 IT420: Database Management and Organization SQL: Structured Query Language 25 January 2006 Adina Crăiniceanu
Database Lecture # 1 By Ubaid Ullah.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
Introduction to SQL Yong Choi School of Business CSU, Bakersfield.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 What is database 2? What is normalization? What is SQL? What is transaction?
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
FEN  Data Definition: CREATE TABLE, ALTER TABLE  Data Manipulation: INSERT, UPDATE, DELETE  Queries: SELECT SQL: Structured Query Language.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
DAT602 Database Application Development Lecture 3 Review of SQL Language.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
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.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
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.
Chapter 11 Database and SQL. Flat Files and Databases Flat files Databases Advantages Efficient use of resources Access control Disadvantages Security.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
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.
1 A Very Brief Introduction to Relational Databases.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
SQL Basics Review Reviewing what we’ve learned so far…….
Lecturer: Eng. Mohamed Adam Isak PH.D Researcher in CS. M.Sc. and B.Sc. of Information Technology Engineering Senior Lecturer in University of Somalia,
SQL Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Introduction to Structured Query Language(SQL)
Structured Query Language (SQL) William Klingelsmith
STRUCTURED QUERY LANGUAGE
SQL Tutorial.
Workbench Data Definition Language (DDL)
Introduction To Structured Query Language (SQL)
SQL Queries Chapter No 3.
SQL .. An overview lecture3.
Introduction To Structured Query Language (SQL)
Structured Query Language
Presentation transcript:

1 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL Structured Query Language

2 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems. SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.

3 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems There are different versions of the SQL language, but they must support the same major keywords in a similar manner (such as SELECT, UPDATE, DELETE, INSERT, WHERE, and others) with SQL standards Most of the SQL database programs also have their own extensions in addition to the SQL standard!

4 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL Database Tables Person LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit BohçacıBerkeÇeşme Sokak 4/1İzmit SungurAyşegülTepe Sokak 8/23Balıkesir

5 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems With SQL, we can query a database and have a result set returned. A query like this: SELECT LastName FROM Persons Gives a result set like this: SQL Queries LastName Kiraz Bohçacı Sungur

6 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL can be divided into two parts: –The Data Manipulation Language (DML) –The Data Definition Language (DDL).

7 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Data Manipulation Language SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records. –SELECT - extracts data from a database table –UPDATE - updates data in a database table –DELETE - deletes data from a database table –INSERT INTO - inserts new data into a database table

8 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Data Definition Language The Data Definition Language (DDL) part of SQL permits database tables to be created or deleted. We can also define indexes (keys), specify links between tables, and impose constraints between database tables. The most important DDL statements in SQL are: –CREATE TABLE - creates a new database table –ALTER TABLE - alters (changes) a database table –DROP TABLE - deletes a database table –CREATE INDEX - creates an index (search key) –DROP INDEX - deletes an index

9 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL The SELECT Statement

10 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL The SELECT Statement The SELECT statement is used to select data from a table. The tabular result is stored in a result table (called the result-set). Syntax SELECT column_name(s) FROM table_name

11 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems To select the columns named "LastName" and "FirstName", use a SELECT statement like this: SELECT LastName, FirstName FROM Persons LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit BohçacıBerkeÇeşme Sokak 4/1İzmit SungurAyşegülTepe Sokak 8/23Balıkesir LastNameFirstName KirazMeltem BohçacıBerke SungurAyşegül

12 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems To select all columns from the "Persons" table, use a * symbol instead of column names, like this: SELECT * FROM Persons LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit BohçacıBerkeÇeşme Sokak 4/1İzmit SungurAyşegülTepe Sokak 8/23Balıkesir Select All Columns

13 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems The DISTINCT keyword is used to return only distinct (different) values. The SELECT statement returns information from table columns. But what if we only want to select distinct elements? With SQL, all we need to do is to add a DISTINCT keyword to the SELECT statement: Syntax SELECT DISTINCT column_name(s) FROM table_name Select Distinct Statement

14 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems To select ALL values from the column named "Company" we use a SELECT statement like this: SELECT Company FROM Orders Company SONY ACME VESTEL ACME Orders CompanyOrderNumber SONY3412 ACME5464 VESTEL5876 ACME3425 Using Distinct Keyword

15 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Note that "W3Schools" is listed twice in the result-set. To select only DIFFERENT values from the column named "Company" we use a SELECT DISTINCT statement like this: SELECT DISTINCT Company FROM Orders Orders CompanyOrderNumber SONY3412 ACME5464 VESTEL5876 ACME3425 Company SONY ACME VESTEL

16 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Select All Columns The WHERE clause is used to specify a selection criterion. The WHERE Clause To conditionally select data from a table, a WHERE clause can be added to the SELECT statement. Syntax SELECT column FROM table WHERE column operator value

17 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems With the WHERE clause, the following operators can be used: Operator Description = Equal <> Not equal > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between an inclusive range LIKE Search for a pattern IN If you know the exact value you want to return for at least one of the columns Operators

18 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Using the WHERE Clause To select only the persons living in the city "Sandnes", we add a WHERE clause to the SELECT statement: SELECT * FROM Persons WHERE City=‘İzmit' LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit BohçacıBerkeÇeşme Sokak 4/1İzmit SungurAyşegülTepe Sokak 8/23Balıkesir BohçacıNilgünKahya Sokak 3/65İzmit LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit BohçacıBerkeÇeşme Sokak 4/1İzmit BohçacıNilgünKahya Sokak 3/65İzmit

19 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Using Quotes SQL uses single quotes around text values Numeric values should not be enclosed in quotes. For Text Valuıes This is correct : SELECT * FROM Persons WHERE FirstName=‘Ayşe‘ This is wrong: SELECT * FROM Persons WHERE FirstName=Ayşe For Numeric Values This is correct : SELECT * FROM Persons WHERE Year=1985 This is wrong: SELECT * FROM Persons WHERE Year=‘1985’

20 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems The LIKE Condition The LIKE condition is used to specify a search for a pattern in a column. Syntax SELECT column FROM table WHERE column LIKE pattern A "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.

21 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Using LIKE The following SQL statement will return persons with first names that start with an 'O': SELECT * FROM Persons WHERE FirstName LIKE 'O%' The following SQL statement will return persons with first names that end with an 'a': SELECT * FROM Persons WHERE FirstName LIKE '%a'

22 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Using LIKE 2 The following SQL statement will return persons with first names that contain the pattern 'la': SELECT * FROM Persons WHERE FirstName LIKE '%la%'

23 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL The INSERT INTO Statement

24 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems The INSERT INTO Statement The INSERT INTO statement is used to insert new rows into a table. Syntax INSERT INTO table_name VALUES (value1, value2,....) You can also specify the columns for which you want to insert data: INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)

25 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Insert a New Row INSERT INTO Persons VALUES (‘Arslan', ‘Hüseyin', ‘Karga Sok 3/23', ‘Balıkesir') LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir

26 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Insert Data in Specified Columns And This SQL statement: INSERT INTO Persons (LastName, Address) VALUES (‘Kibar', ' Terzi Sok 1/3 ') LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir KibarTerzi Sok 1/3

27 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL The UPDATE Statement

28 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems The Update Statement The UPDATE statement is used to modify the data in a table. Syntax UPDATE table_name SET column_name = new_value WHERE column_name = some_value

29 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Update one Column in a Row We want to add a first name to the person with a last name of "Rasmussen": UPDATE Person SET FirstName = ‘Nehar' WHERE LastName = ‘Kibar' LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir KibarTerzi Sok 1/3 LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir KibarNeharTerzi Sok 1/3

30 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Update several Columns in a Row We want to change the address and add the name of the city: UPDATE Person SET Address = 'Stien 12', City = ‘İzmit‘ WHERE LastName = ‘Kibar' LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir KibarNeharTerzi Sok 1/3 LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir KibarNeharTerzi Sok 1/3İzmit

31 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems SQL The Delete Statement

32 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems The Delete Statement The DELETE statement is used to delete rows in a table. Syntax DELETE FROM table_name WHERE column_name = some_value

33 Başar Öztayşi 2011 END 213E Data Processing in Industrial Systems Delete a Row "Nehar Kibar" is going to be deleted: DELETE FROM Person WHERE LastName = ‘Kibar' LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir KibarNeharTerzi Sok 1/3İzmit LastNameFirstNameAddressCity KirazMeltemPaşa Sokak 1/23İzmit ArslanHüseyin Karga Sok 3/23Balıkesir