Information Technology Structured Query Language Grade11.

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

Virtual training week 4 structured query language (SQL)
SQL and Databases. Assignment 1. Create the table, and insert the data, shown in the next slide. 2. Display the first name and age for everyone that's.
Beginning SQL Tutorial Author Jay Mussan-Levy. What is SQL?  Structured Query Language  Communicate with databases  Used to created and edit databases.
Session 4 SQL Structured Query Language. SQL Modes of use –Interactive –Embedded Purpose –Create database –Create, Read, Update, Delete.
Chapter 8 Special-Purpose Languages. SQL SQL stands for "Structured Query Language". Allows the user to pose complex questions of a database. It also.
This course has taken from This unique introductory SQL tutorial not only provides easy-to-understand SQL instructions, but it allows.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
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”
SQL Tutorials To understand some of the topics please analyze the following tutorials: The following tutorials will help:
Microsoft Access 2010 Chapter 7 Using SQL.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
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 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
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 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.
SQL/lesson 2/Slide 1 of 45 Retrieving Result Sets Objectives In this lesson, you will learn to: * Use wildcards * Use the IS NULL and IS NOT NULL keywords.
Labs for SQL Training Ashish Raghute, Manager of Applications Development, Fleetwood Enterprises.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Database: SQL and MySQL
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
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.
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.
DAT602 Database Application Development Lecture 3 Review of SQL Language.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
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.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
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,
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
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.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 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 SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
 2012 Pearson Education, Inc. All rights reserved.
JDBC.
SQL Tutorial.
CIS16 Application Programming with Visual Basic
Introduction To Structured Query Language (SQL)
SQL.
Introduction To Structured Query Language (SQL)
Structured Query Language
Manipulating Data Lesson 3.
Presentation transcript:

Information Technology Structured Query Language Grade11

SQL … is used to communicate with a database. SQL statements are used to perform tasks such as Updating data in a database in a database It is the standard language for relational database management systems. Creating data within a database Reading or retrieving data from a database Deleting data from a database That’s right Dain - the CRUD

Introduction continued… Some common relational database management systems that use SQL are: MS SQL Server Access The industry standard SQL commands are: "Select", "Insert", "Update", "Delete", "Create", and "Drop"

Table Basics contains one or more objects called tables. The data or information for the database are stored in these tables. Weather.tbl cityprovincehighlow DurbanKZN3228 KwaMashuKZN2722 PEEC18 12 Cape TownNC17 11 London A relational database system…

Selecting Data The select statement is used to “query the database” and retrieve selected data… SELECT "column1" [,"column2",etc] FROM "tablename" [WHERE "condition"]; [ ] = optional Conditional selections require a where clause: …that match the criteria that you specify.” NB.: The column names that follow the select keyword determine which columns will be returned in the results. You can select as many column names that you'd like, or you can use a "*" to select all columns.

The Optional WHERE Clause… The WHERE clause specifies which data values (rows) will be returned/ displayed. =Equal > Greater than < Less than >= Greater than or equal <= Less than or equal <> Not equal to LIKE Compared to/ with Lets’ looka little closer at LIKE... Every WHERE clause requires a Boolean expression/ function :

The percent sign "%" can be used as a “wild card” to match any possible character that might appear… SELECT first, last, city from empInfo WHERE first LIKE 'Er%'; “Strings” must be in single quotes. Or you can specify, SELECT first, last from empInfo WHERE last LIKE '%s'; last names that end in a 's'. SELECT * from empInfo WHERE first = 'Eric'; This will only select rows where the first name equals 'Eric' exactly. LIKE allows you to select only rows that are "like" what you specify. before or after the characters specified.

Now you try… Sample Table: empInfo firstlastidagecityprovince JohnJones DurbanKZN MaryJones PEEC EricEdwards Senegal NC Mary AnnEdwards Phoenix KZN GingerHowell Chatsworth KZN SebastianSmith Gila Bend G GusGray Bagdad Polo Mary AnnMay Terror Cape EricaWilliams Sholo EC LeroyBrown Pinetop NC ElroyCleaver Durban Cape 1.SELECT first, last, city FROM empInfo; 2.SELECTlast, city, age FROMempInfo WHERE age > 30; 2.SELECT last, city, age FROM empInfo WHERE age > 30; 3.SELECTfirst, last, city, province FROMempinfo WHEREfirst LIKE 'J%'; 3.SELECT first, last, city, province FROM empinfo WHERE first LIKE 'J%'; 4.SELECT* from empInfo; select first, last, FROMempinfo WHERElast LIKE '%s'; 4.SELECT * from empInfo; select first, last, FROM empinfo WHERE last LIKE '%s'; 5.SELECTfirst, last, age FROMempInfoWHERElast LIKE '%illia%'; 5.SELECT first, last, age FROM empInfo WHERE last LIKE '%illia%'; 6.SELECT* FROMempInfoWHEREfirst = 'Eric'; 6.SELECT * FROM empInfo WHERE first = 'Eric'; What will these output?

Now the reverse … 1. Display the first name and age for everyone that's in the table. 2. Display the first name, last name, and city for everyone that's not from Bulowayo. 3. Display all columns for everyone that is over 40 years old. 4. Display the first and last names for everyone whose last name ends in an "ay". 5. Display all columns for everyone whose first name equals "Mary". 6. Display all columns for everyone whose first name contains "Mary". Complete the following SELECT Statement exercise -

Now check your answers… Display everyone's first name and their age for everyone that's in table. Display everyone's first name and their age for everyone that's in table. SELECT first, age FROM empInfo; SELECT first, age FROM empInfo; Display the first name, last name, and city for everyone that's not from Bulowayo. Display the first name, last name, and city for everyone that's not from Bulowayo. SELECT first, last, city FROM empInfo WHERE city <> ‘Bulowayo'; SELECT first, last, city FROM empInfo WHERE city <> ‘Bulowayo'; Display all columns for everyone that is over 40 years old. Display all columns for everyone that is over 40 years old. SELECT * FROM empInfo WHERE age > 40; SELECT * FROM empInfo WHERE age > 40; Display the first and last names for everyone whose last name ends in an "ay". Display the first and last names for everyone whose last name ends in an "ay". SELECT first, last FROM empInfo WHERE last LIKE '%ay'; SELECT first, last FROM empInfo WHERE last LIKE '%ay'; Display all columns for everyone whose first name equals "Mary". Display all columns for everyone whose first name equals "Mary". SELECT * FROM empInfo WHERE first = 'Mary'; SELECT * FROM empInfo WHERE first = 'Mary'; Display all columns for everyone whose first name contains "Mary". Display all columns for everyone whose first name contains "Mary". SELECT * FROM empInfo WHERE first LIKE '%Mary%' SELECT * FROM empInfo WHERE first LIKE '%Mary%'

Inserting into a Table To insert records into a table, the key words insert into is used…followed by the keyword values… To insert records into a table, the key words insert into is used…followed by the keyword values… insert into "tablename" (first_column,...last_column) values (first_value,...last_value); insert into "tablename" (first_column,...last_column) values (first_value,...last_value); The insert statement is used to insert or add a row of data into the table. Example: insert into employee (first, last, age, address, city, state) values ('Luke', 'Duke', 45, '2130 Boars Hoares', 'Hazard Co', ‘Phoenix'); Note: All strings should be enclosed between single quotes: 'string'

Insert statement exercise… It is time to insert data into your new “employee table”. It is time to insert data into your new “employee table”. Your first three employees are the following: Your first three employees are the following: Jonie Weber, Secretary, 28, Potsy Weber, Programmer, 32, Dirk Smirk, Programmer II, 45, Jonie Weber, Secretary, 28, Potsy Weber, Programmer, 32, Dirk Smirk, Programmer II, 45, Now insert at 5 more of your own list of employees in the table. Now insert at 5 more of your own list of employees in the table. Next, enter select statements to: 1.Select all columns for everyone in your employee table. 2.Select all columns for everyone with a salary over Select first and last names for everyone that's under 30 years old. 4.Select first name, last name, and salary for anyone with "Programmer" in their title. 5.Select all columns for everyone whose last name contains "ebe". 6.Select the first name for everyone whose first name equals "Potsy". 7.Select all columns for everyone over 80 years old. 8.Select all columns for everyone whose last name ends in "ith".

Updating Records The update statement is used to update or change records that match a specified criteria. This is accomplished by carefully constructing a where clause. The update statement is used to update or change records that match a specified criteria. This is accomplished by carefully constructing a where clause. update "tablename" set "columnname" = "newvalue" [,"nextcolumn" = "newvalue2"...] where "columnname" OPERATOR "value" [and|or "column" OPERATOR "value"]; update "tablename" set "columnname" = "newvalue" [,"nextcolumn" = "newvalue2"...] where "columnname" OPERATOR "value" [and|or "column" OPERATOR "value"]; [ ] = optional Examples: update phone_book set area_code = 623 where prefix = 979; update phone_book set last_name = 'Smith', prefix=555, suffix=9292 where last_name = 'Jones'; update employee set age = age+1 where first_name='Mary' and last_name='Williams'; Update statement exercises

After each update, issue a select statement to verify your changes. 1. Jonie Weber just got married to Bob Williams. She has requested that her last name be updated to Weber-Williams. 2. Dirk Smith's birthday is today, add 1 to his age. 3. All secretaries are now called "Administrative Assistant". Update all titles accordingly. 4. Everyone that's making under are to receive a 3500 a year raise. 5. Everyone that's making over are to receive a 4500 a year raise. 6. All "Programmer II" titles are now promoted to "Programmer III". 7. All "Programmer" titles are now promoted to "Programmer II".

Updating Records Answers: Jonie Weber just got married to Bob Williams. She has requested that her last name be updated to Weber-Williams. Jonie Weber just got married to Bob Williams. She has requested that her last name be updated to Weber-Williams. update myemployees set lastname= 'Weber-Williams' where firstname= 'Jonie' and lastname= 'Weber'; Dirk Smith's birthday is today, add 1 to his age. Dirk Smith's birthday is today, add 1 to his age. update myemployees set age=age+1 where firstname='Dirk' and lastname='Smith'; All secretaries are now called "Administrative Assistant". Update all titles accordingly. All secretaries are now called "Administrative Assistant". Update all titles accordingly. update myemployees set title = 'Administrative Assistant' where title = 'Secretary'; Everyone that's making under are to receive a 3500 a year raise. Everyone that's making under are to receive a 3500 a year raise. update myemployees set salary = salary where salary < 30000; update myemployees set salary = salary where salary < 30000; Everyone dat’s making over are to receive a 4500 a year raise. Everyone dat’s making over are to receive a 4500 a year raise. update myemployees set salary = salary where salary > 33500; update myemployees set salary = salary where salary > 33500; All "Programmer II" titles are now promoted to "Programmer III". All "Programmer II" titles are now promoted to "Programmer III". update myemployees set title = 'Programmer III' where title = 'Programmer II' update myemployees set title = 'Programmer III' where title = 'Programmer II' All "Programmer" titles are now promoted to "Programmer II". All "Programmer" titles are now promoted to "Programmer II". update myemployees set title = 'Programmer II' where title = 'Programmer' update myemployees set title = 'Programmer II' where title = 'Programmer'

Deleting Records Examples: delete from employee; delete from employee; Note: if you leave off the where clause, all records will be deleted! Note: if you leave off the where clause, all records will be deleted! delete from employee where lastname = 'May'; delete from employee where lastname = 'May'; delete from employee where firstname = 'Mike' or firstname = 'Eric'; delete from employee where firstname = 'Mike' or firstname = 'Eric'; The delete statement is used to delete records or rows from the table. delete from "tablename“ where "columnname" OPERATOR "value" [and|or "column" OPERATOR "value"]; [ ] = optional Delete statement exercises

Use the select statement to verify your deletes 1. Jonie Weber-Williams just quit, remove her record from the table. 2. It's time for budget cuts. Remove all employees who are making over dollars.

Deleting Records Answers: Jonie Weber-Williams just quit, remove her record from the table: Jonie Weber-Williams just quit, remove her record from the table: delete from myemployees where lastname = 'Weber-Williams'; delete from myemployees where lastname = 'Weber-Williams'; It's time for budget cuts. Remove all employees who are making over dollars. It's time for budget cuts. Remove all employees who are making over dollars. delete from myemployees where salary > 70000; delete from myemployees where salary > 70000;

Drop a Table To delete an entire table including all of its rows, issue the drop table command followed by the tablename. To delete an entire table including all of its rows, issue the drop table command followed by the tablename. drop table "tablename" drop table "tablename"Example: drop table myemployees; drop table myemployees; The drop table command is used to delete a table and all rows in the table. End of Lesson 1 on two more to go…SQLCourse2.com