sql basic. what is sql? sql (pronounced "ess-que-el") stands for structured query...

19
SQL SQL Basic Basic

Upload: roberta-boone

Post on 04-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

SQLSQL

BasicBasic

Page 2: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

What is SQL?

SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.

Page 3: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

What can you do with SQL?

SQL enables you to select, insert, modify, and delete the information in a database; perform system security functions and set user permission on tables and databases; handle online transaction processing within an application, create store procedures and triggers to reduce application coding; and transfer data between different databases.

Page 4: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

SQL Data Manipulation Language (DML)

SQL (Structured Query Language) is a syntax for executing queries.

SELECT - extracts data from a database table

UPDATE - updates data in a database table DELETE - deletes data from a database table INSERT INTO - inserts new data into a

database table

Page 5: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Selecting Data

The select statement is used to query the database and retrieve selected data that match the criteria that you specify. Here is the format of a simple select statement:

select "column1"

[,"column2",etc] from

"tablename" [where "condition"];

[ ] = optional

Page 6: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Inserting data into a Table

The insert statement is used to insert or add a row of data into the table.

insert into "tablename" (first_column,...last_column) values (first_value,...last_value);

Page 7: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

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.

update "tablename”

set "columnname" =

"newvalue" [,"nextcolumn" = "newvalue2"...]

where "columnname"

OPERATOR "value" [and| or "column"

OPERATOR "value"];

Page 8: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Deleting Records

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"];

Page 9: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Will this statement work?

Select *

Page 10: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

The FROM clause is missing

Select * from [tablename]

Page 11: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

If amount name payee are column names from tables check would this statement work

Select amount name payee from checks

Page 12: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Select amount, name, payee from checks

You need to have comma between each column name.

Page 13: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

What is wrong with the following statement?

Delete collection,

Page 14: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Delete from collections;

Page 15: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Is this correct

Delete * from collections

Page 16: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Delete * from Collection

No the * is not needed

Page 17: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Let’s take a quiz!!!!!

Page 18: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Answer to Quiz1. Structured Query Language2. Select3. Update4. Delete5. Insert6. Select Firstname from Persons7. Select * from Persons8. Select * from persons where firstname = “peter9. Select * from persons where firstname like ‘a%’10. Update persons set lastname = ‘nilsen’ where

lastname = ‘hansen’

Page 19: SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database

Congratulations! You have just learned Basic SQL statements.