Introduction To Structured Query Language (SQL)

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Introduction to Structured Query Language (SQL)
SQL Basics Based on the relational algebra we just learned. Nonprocedural language – what to be done not how Simple, powerful language Used for both data.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
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.
Sundara Ram Matta Apr 01 st, Sundara Ram Matta Apr 01 st, 2015
Data Access Basics Intro to basic SQL. Have you used SQL? Yes No Es Que What?
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
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.
Lab_03: Basic SQL.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
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 9 SQL อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
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.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
Chapter 11 Database and SQL. Flat Files and Databases Flat files Databases Advantages Efficient use of resources Access control Disadvantages Security.
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.
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.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
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.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
Module T03d Software Engineering
From: SQL From:
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Query Methods Where Clauses Start ….
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Introduction to Structured Query Language(SQL)
SQL Implementation & Administration
Structured Query Language – The Basics
STRUCTURED QUERY LANGUAGE
SQL Tutorial.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Database systems Lecture 3 – SQL + CRUD
SQL Queries Chapter No 3.
SQL.
SQL .. An overview lecture3.
Structured Query Language – The Fundamentals
Introduction To Structured Query Language (SQL)
Structured Query Language
Manipulating Data Lesson 3.
Presentation transcript:

Introduction To Structured Query Language (SQL)

SQL SQL is a standard language for accessing databases. Our SQL tutorial will teach you how to use SQL to access and manipulate data in: MS Access SQL Server database systems.

What is SQL? SQL stands for Structured Query Language SQL lets you access and manipulate databases SQL is an ANSI (American National Standards Institute) standard

What Can SQL do? SQL can execute queries against a database SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database SQL can create new databases SQL can create new tables in a database SQL can create stored procedures in a database SQL can create views in a database SQL can set permissions on tables, procedures, and views

Some of The Most Important SQL Commands SELECT - extracts data from a database UPDATE - updates data in a database DELETE - deletes data from a database INSERT INTO - inserts new data into a database CREATE DATABASE - creates a new database ALTER DATABASE - modifies a database CREATE TABLE - creates a new table ALTER TABLE - modifies a table DROP TABLE - deletes a table CREATE INDEX - creates an index (search key) DROP INDEX - deletes an index

Student

SELECT Statements In this tutorial we will use the well-known sample database (included in MS Access and MS SQL Server). The following SQL statement selects all the records in the table: Statement: SELECT * FROM Table; E.g.: SELECT * FROM Student;

SELECT Statements SELECT column_name,column_name FROM table_name; Select id, Firstname, age From Student;

SQL SELECT DISTINCT Statement The SELECT DISTINCT statement is used to return only distinct (different) values. SELECT DISTINCT column_name,column_name FROM table_name;

SQL WHERE Clause The WHERE clause is used to filter records. SELECT * FROM Student WHERE Field_Name ="Text Value"; SELECT * FROM Student WHERE Field_Name =Numeric Value;

Operators in The WHERE Clause Description = Equal <> Not equal. Note: In some versions of SQL this operator may be written as != > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between an inclusive range LIKE Search for a pattern IN To specify multiple possible values for a column

AND & OR Operators The AND & OR operators are used to filter records based on more than one condition. SELECT * FROM Student WHERE City =Nizwa" AND Age < 30; SELECT * FROM Student WHERE City =Nizwa" OR Age < 30; SELECT * FROM Student WHERE City=Nizwa" AND (lastname= "said" OR firstname="ali");

Operators in The WHERE Clause The BETWEEN operator selects values within a range. The values can be numbers, text, or dates. SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; Not Between used to NOT Include SELECT Firstname, Lastname, city, age FROM student WHERE city NOT BETWEEN "Muscat" AND "Izki";

IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...);

LIKE Operator The LIKE operator is used to search for a specified pattern in a column. SELECT * FROM Student WHERE City LIKE "s*";

ORDER BY Keyword The ORDER BY keyword is used to sort the result-set. SELECT * FROM student ORDER BY city; SELECT * FROM student ORDER BY city ASC /DESC; SELECT * FROM student ORDER BY city, firstname; SELECT * FROM student ORDER BY city ASC, lastname DESC;

INSERT INTO Statement The INSERT INTO statement is used to insert new records in a table. INSERT INTO Student(FirstName, LastName, City, age, Mob) VALUES (‘Nour',Elshaiekh',Halfa',42, 5654566);

UPDATE Statement The UPDATE statement is used to update records in a table. UPDATE student SET FirstName = ‘ALSaadi' WHERE d =4; UPDATE Student SET LastName= “Mussab”, City= “Suhar” WHERE FirstName= “Ali”;

Update table with data from another table UPDATE ab SET current_category = (SELECT category_id FROM products WHERE products.product_id = summary_data.product_id) WHERE EXISTS (SELECT category_id FROM products WHERE products.product_id = summary_data.product_id);

Delete Statement The DELETE statement is used to delete records in a table. DELETE FROM Student WHERE FirstName="Ali" AND LastName="Said" ;

SELECT TOP Clause The SELECT TOP clause is used to specify the number of records to return. SELECT TOP 2 * FROM Student;

SELECT TOP Clause SQL statement selects the first ?% of the records from the table: SELECT TOP 20 PERCENT * FROM Student;

SQL JOIN An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. SELECT abs.name, Student.FirstName, ab.age FROM student INNER JOIN ab ON ab.Name=student.FirstName;

SQL Aliases SQL aliases are used to give a database table, or a column in a table, a temporary name. Basically aliases are created to make column names more readable. SELECT FirstName AS CEMIS FROM Student;

The SQL UNION Operator The UNION operator is used to combine the result-set of two or more SELECT statements SELECT FirstName FROM Student UNION SELECT FirstName FROM ab; SELECT City FROM Student SELECT FirstName From ab ORDER BY City;

SQL SELECT INTO Statement With SQL, you can copy information from one table into another. The SELECT INTO statement copies data from one table and inserts it into a new table. We can copy all columns into the new table: SELECT * INTO newtable [IN externaldb] FROM table1;

SQL SELECT INTO Statement Or we can copy only the columns we want into the new table: SELECT column_name(s) INTO newtable [IN externaldb] FROM table1;

SQL SELECT INTO Statement Copy only the German customers into the new table: SELECT * INTO qq FROM Student WHERE City='Muscat';

SQL SELECT INTO Statement INSERT INTO table2 (column_name(s)) SELECT column_name(s) FROM table1;

The SQL CREATE TABLE Statement The CREATE TABLE statement is used to create a table in a database. Tables are organized into rows and columns; and each table must have a name. REATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... );

The SQL CREATE TABLE Statement CREATE TABLE Staff ( StaffID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) );

CREATE TABLE StaffNotNull ( S_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) )