ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.

Slides:



Advertisements
Similar presentations
Virtual training week 4 structured query language (SQL)
Advertisements

Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Cs3431 Transactions, Logging and Security. cs3431 Transactions: What and Why? A set of operations on a database must appear as one “unit”. Example: Consider.
Structured Query Language Part I Chapter Three CIS 218.
Introduction to Structured Query Language (SQL)
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
Using SQL Queries to Insert, Update, Delete, and View Data Date Retrieval from a single table & Calculations © Abdou Illia MIS Spring 2015.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 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)
Sundara Ram Matta Apr 01 st, Sundara Ram Matta Apr 01 st, 2015
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
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.
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.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
LOGO 1 Lab_04: Basic SQL. 2 Outline  The ORDER BY Keyword  SQL ORDER BY Syntax  SQL NULL Values.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
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.
1 Creating and Maintaining Database Objects Part 1 Database Systems.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
IS6146 Databases for Management Information Systems Lecture 1: Introduction to IS6146 Rob Gleasure robgleasure.com.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
Selecting Data Database Administration Fundamentals LESSON 3.1a.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
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.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
 CONACT UC:  Magnific training   
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Database Design lecture 3_2 Slide 1 Database Design Lecture 3_2 Data Manipulation in SQL Simple SQL queries References: Text Chapter 8 Oracle SQL Manual.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
SQL Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
MySQL DML Commands By Prof. B.A.Khivsara
Introduction to Structured Query Language(SQL)
ATS Application Programming: Java Programming
Introduction to Oracle9i: SQL
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Chapter 8 Working with Databases and MySQL
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Introduction To Structured Query Language (SQL)
HAVING,INDEX,COMMIT & ROLLBACK
ITS232 Introduction To Database Management Systems
Introduction To Structured Query Language (SQL)
Presentation transcript:

ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah | A | ext:2561 | | | CHAPTER 7 An Introduction To SQL Lab 1: Simple SQL Queries

Objectives 2

Data Manipulation Language(DML) Data Manipulation in SQL is an ability for manipulating the data to provide information needs by users. Manipulating the data referees to process of: selecting the data do some operation at the data user view it or save it in the database 3 SELECT * FROM printer WHERE color = ‘red’ OR color = ‘blue’;

DML: Queries: SELECT Statement SELECT Statement The SELECT statement allows you to find, retrieve, and display data. To execute the SELECT statement on a table, you must be the table owner, have DBA or SYSADM security privileges, or have the SELECT privilege for that table. The result of SELECT statement is a set of rows known as the result set, which meets the conditions specified in the SELECT statement SQL SELECT Syntax Note SQL is not case sensitive { SELECT is the same as select } 4 SELECT column_name(s) FROM table_name; SELECT * FROM table_name;

DML: Queries: SELECT Statement printerNOdescriptioncolorprice P123Dot-matrixRed HP874Laser JetBlue Select all data from table printer. Select printerNO and price from table printer. SELECT * FROM printer; SELECT printerNO, price FROM printer; printerNOprice P HP

DML: Queries: SELECT DISTINCT Statement SELECT DISTINCT Statement In a table, some of the columns may contain duplicate values. The DISTINCT keyword can be used to return only distinct (different) values. SQL SELECT DISTINCT Syntax 6 SELECT DISTINCT column_name(s) FROM table_name;

DML: Queries: SELECT DISTINCT Statement The following statement only will select the distinct values from the column named city from table staff. 7 SELECT DISTINCT city FROM staff; staffNOstaffNAMEcity ABC987NadzKuala Lumpur ABC988AinaJerantut ABC999HalimatonJerantut city Kuala Lumpur Jerantut

SQL LIKE Operator The LIKE operator is used in a WHERE statement to search for a specified pattern in a column. SQL LIKE Syntax Note The LIKE operator is commonly used with SQL Wildcards 8 SELECT column_name(s) FROM table_name WHERE column_name LIKE patern;

SQL LIKE Operator staffNOstaffNAMEcity ABC987NadzKuala Lumpur 9 SELECT * FROM staff WHERE city LIKE “K%”; The following select staffs living in a city start with “K” from table ‘staff’.

SQL Wildcards SQL wildcards can be used when searching for data in a database. SQL wildcards can substitute for one or more characters when searching for data in a database. SQL wildcards must be used with the SQL LIKE operator. With SQL, the following wildcards can be used: 10 WildcardDescription % A substitute for zero or more characters _ A substitute for exactly one character [charlist] Any single character in charlist [^charlist] or [!charlist] Any single character not in charlist

Wildcards: Using The % Wildcard Select staff living in the city that start with ‘La’ from staff table. Select staff living in the city that contain pattern ‘wi’ from staff table. 11 SELECT * FROM staff WHERE city LIKE "La%"; SELECT * FROM staff WHERE city LIKE "%wi%";

Wildcards: Using The _ Wildcard Select staff with a name that starts with any character, followed by ‘da’ from staff table. Select staff with a name that starts with "S", followed by any character, followed by "ar", followed by any character, followed by "s" from staff table. 12 SELECT * FROM staff WHERE staffNANE LIKE "_da"; SELECT * FROM staff WHERE staffNANE LIKE "S_ar_s";

Wildcards: Using The [charlist] Wildcard Select staff with a name that starts with "a" or "s" or "p" from staff table. Select staff name that do not starts with “ "a" or "s" or "p" from staff table. 13 SELECT * FROM staff WHERE staffNANE LIKE "[asp]%"; SELECT * FROM staff WHERE staffNANE LIKE "[!asp]%";

DML: COMMIT The COMMIT statement terminates the current transaction and makes all changes under the transaction persistent. COMMIT is used for saving the data that has been changed permanently because whenever you perform any DML like UPDATE, INSERT or DELETE then you are required to write COMMIT at the end of all or every DML operation in order to save it permanently. If you do not write COMMIT and you program crashes then your data will be restored into its previous condition. The COMMIT statement has the following general format: 14 UPDATE printer SET indate = ‘15/01/2007' WHERE printerNO = 'F380'; COMMIT;

DML: ROLLBACK The ROLLBACK statement terminates the current transaction and cancel all changes made under the transaction. ROLLBACK is used if you want to restore your data into its previous condition. ROLLBACK can be write at any time after the DML queries has been written but remember once COMMIT has been written then you cannot rollback the data. You can only rollback the DML queries that have been written after the last commit statement. The ROLLBACK statement has the following general format: 15 INSERT INTO staff VALUES (“ABC990”, “Shafiza”, “Johor”) ROLLBACK;

DML: COMMIT & ROLLBACK The concept of COMMIT and ROLLBACK is designed for data consistency because many uses manipulate data of the same table, using the same database so the user must get updated data. That is why COMMIT and ROLLBACK are used for. COMMIT to save whatever has been done. It is used to permanently store it in memory. ROLLBACK to undo something. If we use roll-back, the particular changes made are undone. 16

DML: Compound Statement with SELECT SymbolMeaning = Equal to < Less than <= Less than or equal to > Greater than >= Greater than or equal to <> Not equal to* *Some SQL version use != 17 – AND to combine two search conditions which must be both true. – OR to combine two search conditions when one or the other (or both) must be true You can combine simple conditions with the logical operators AND, OR, and NOT to form compound conditions.

DML: Compound Statement with SELECT Select only the staff live in Merbok AND age greater then or equal to 40 years old from table staff. Select only the staff live in Penang OR age greater then or equal to 40 years old from table staff. 18 SELECT * FROM staff WHERE city=“Merbok” AND age >= 40; SELECT * FROM staff WHERE city=“Penang” OR age >= 40;

DML: Compound Statement with SELECT Select only the staff live in Merbok OR Penang AND age greater then or equal to 40 years old from table staff. 19 SELECT * FROM staff WHERE (city=“Merbok” OR city=“Penang”) AND age >= 40;

DML: ORDER BY Keyword The ORDER BY keyword is used to sort the result-set by a specified column. sort the records in ascending order by default. By default the records are in ascending order or you can used ASC keyword If you want to sort the records in a descending order, you can use DESC keyword. The default order is ascending. NULL values are treated as larger that non-null values for sorting purposes. SQL ORDER BY Syntax 20 SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC

DML: ORDER BY Keyword The following statement will output staff average salary group by city. 21 staffNOstaffNAMEcitysalarygenderdepartNO ABC987NadzKuala Lumpur2300Male0001 ABC988AinaJerantut2500Female0002 ABC989HalimatonJerantut2200Female0001 ABC990NorainJohor2000Female0003 staff SELECT city, MIN(salary) AS minSALARY FROM staff GROUP BY city ORDER BY city DESC;