SQL Tutorial.

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

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.
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Beginning SQL Tutorial Author Jay Mussan-Levy. What is SQL?  Structured Query Language  Communicate with databases  Used to created and edit databases.
Introduction to Structured Query Language (SQL)
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”
Introduction to Structured Query Language (SQL)
SQL Tutorials To understand some of the topics please analyze the following tutorials: The following tutorials will help:
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
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.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
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.
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.
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.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
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
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
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.
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,
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.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
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.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
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.
 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.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Query Methods Simple SQL Statements Start ….
Chapter 5 Introduction to SQL.
Query Methods Where Clauses Start ….
Query Methods Where Clauses Start ….
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL Implementation & Administration
SQL Creating and Managing Tables
PHP + MySQL Commands Refresher.
SQL Creating and Managing Tables
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL Creating and Managing Tables
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Introduction To Structured Query Language (SQL)
SQL Queries Chapter No 3.
SQL.
Introduction To Structured Query Language (SQL)
Structured Query Language
PHP and MySQL.
MySQL Database System Installation Overview SQL summary
Manipulating Data Lesson 3.
Introduction to Web programming
Presentation transcript:

SQL Tutorial

SQL Database Tables This tutorial uses a MySql database which is on studshare You need to import it Start phpMyAdmin Create a library database Select Import Select the file Click Go The tables will be created and their data imported You can now use the following examples

SQL Queries With SQL, we can query a database and have a result set returned. SELECT * FROM books

The SQL 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 Note: SQL statements are not case sensitive. SELECT is the same as select.

SQL SELECT Example To select the content of columns named “lastname" and “firstname", from the database table called “borrower", use a SELECT statement like this: SELECT lastname,firstname FROM borrower

The SELECT DISTINCT Statement 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

Using the DISTINCT keyword To select ALL values from the column named “address2" we use a SELECT statement SELECT address2 FROM borrower Note that “Molden and “Highcliffe" are listed more than once. To select only DIFFERENT values from the column named “address2" we use a SELECT DISTINCT statement SELECT DISTINCT address2 FROM borrower

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

Using the WHERE Clause To select only the persons living in the city “Perth", we add a WHERE clause to the SELECT statement:  SELECT lastname FROM borrower WHERE address2 = "Perth"

Using Quotes Note that we have used single quotes around the conditional values in the examples. SQL uses single quotes around text values (most database systems will also accept double quotes). Numeric values should not be enclosed in quotes. For text values: This is correct: SELECT lastname FROM borrower WHERE firstname=‘Frank‘ This is wrong: SELECT lastname FROM borrower WHERE firstname=Frank

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.

Using LIKE SELECT firstname, postcode FROM borrower WHERE firstname LIKE "f%“ SELECT lastname, Postcode FROM borrower WHERE lastname LIKE "%r SELECT lastname, Postcode FROM borrower WHERE lastname LIKE "%v%"

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,....)

Insert a New Row INSERT INTO borrower VALUES (40, "Mr", "James", "Joyce", "22 Parnell Street", "Spennymoor", "NW22 4ED", "1947-06-23", "M")

Insert Data in Specified Columns INSERT INTO borrower (borrowerid, title, firstname, lastname, address1, postcode, gender) VALUES(41, "Mrs", "Jemima", "Joyce", "22 Parnell Street", "NW22 4ED", "F") Note that where a value was not entered, the returned value is NULL

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

Update one row UPDATE borrower SET address2 = "Spennymoor" WHERE borrowerid = 41

Update several Columns in a Row UPDATE borrower SET address1 = "44 Dublin Parade", address2 = "Newcastle" WHERE postcode = "NW22 4ED"

The DELETE Statement The DELETE statement is used to delete rows in a table. DELETE FROM borrower WHERE borrowerID = 40 Delete All Rows It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact: DELETE FROM table_name Or DELETE * FROM table_name