1 / 19

SQL Queries

SQL Queries. Chapter No 3. Introduction . SQL stands for Structured Query Language Access and Manipulate Database SQL is an ANSI Standard SQL is not Case Sensitive Supports a set of commands that can perform common operations over a database Works with MS Access, SQL Server, MySql

xaria
Download Presentation

SQL Queries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQL Queries Chapter No 3

  2. Introduction • SQL stands for Structured Query Language • Access and Manipulate Database • SQL is an ANSI Standard • SQL is not Case Sensitive • Supports a set of commands that can perform common operations over a database • Works with MS Access, SQL Server, MySql • With Scripting languages like PHP • Works with HTML and ASP

  3. Operations • 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 views in a database • SQL can set permissions on tables, procedures, and views

  4. SQL Organization • SQL can be divided into three parts • RDML • RDDL • RDCL • Relational Data Manipulation Language • Relational Data Definition Language • Relational Data Control Language

  5. DML Commands • INSERT INTO - inserts new data into a database • SELECT - extracts data from a database • UPDATE - updates data in a database • DELETE - deletes data from a database

  6. DDL Commands • 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

  7. SELECT Statement • SELECT column_name(s) FROM table_name • SELECT * FROM table_name • SELECT LastName,FirstName FROM Persons • SELECT * FROM Persons

  8. SQL WHERE Syntax • SELECT column_name(s) FROM table_name WHERE column_name operator value • SELECT * FROM Persons WHERE City='Sandnes‘ • This is correct: • SELECT * FROM Persons WHERE FirstName='Tove‘ • This is wrong: • SELECT * FROM Persons WHERE FirstName=Tove

  9. Operators Allowed in the WHERE Clause

  10. LIKE Syntax • SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern • We want to select the persons living in a city that ends with an "s" from the "Persons" table. • SELECT * FROM Persons WHERE City LIKE ‘%s‘

  11. We want to select the persons living in a city that contains the pattern "tav" from the "Persons" table. • SELECT * FROM Persons WHERE City LIKE '%tav%'

  12. NOT Like • Select the persons living in a city that NOT contains the pattern "tav" from the "Persons" table, by using the NOT keyword. • SELECT * FROM Persons WHERE City NOT LIKE '%tav%‘

  13. INSERT Statement • INSERT INTO table_nameVALUES (value1, value2, value3,...) • INSERT INTO Persons VALUES (4,'Nilsen', 'Johan', 'Bakken 2', 'Stavanger')

  14. UPDATE Statement • The UPDATE statement is used to update existing records in a table. • UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value • UPDATE Persons SET Address='Nissestien 67', City='Sandnes' WHERE LastName='Tjessem' AND FirstName='Jakob'

  15. DELETE Statement • DELETE FROM table_name WHERE some_column=some_value • DELETE FROM Persons WHERE LastName='Tjessem' AND FirstName='Jakob‘ • Delete All Rows • DELETE FROM table_name • Or • DELETE * FROM table_name

  16. References • http://www.w3schools.com/SQL/default.asp • http://sqlzoo.net/1_2.htm • Database system by Thomas Connolly

More Related