Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

SQL by Example: - by Convention SQL Keywords Are Written in Uppercase. - Select From Books

The document provides an overview of SQL commands like SELECT, WHERE, UPDATE, DELETE, INSERT and CREATE TABLE. It gives examples of using these commands to query, update, insert and delete data from database tables and create new tables.

Uploaded by

Daddie Inyasis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

SQL by Example: - by Convention SQL Keywords Are Written in Uppercase. - Select From Books

The document provides an overview of SQL commands like SELECT, WHERE, UPDATE, DELETE, INSERT and CREATE TABLE. It gives examples of using these commands to query, update, insert and delete data from database tables and create new tables.

Uploaded by

Daddie Inyasis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

SQL by Example

• By convention SQL keywords are written


in uppercase.
• SELECT * FROM Books
– This query returns all rows in the Books table.
– SQL statements always require FROM
• SELECT ISBN, Price, Title
FROM Books
– This query returns a table with only the ISBN,
price and title columns from the Books table.
SQL by Example
• SELECT ISBN, Price, Title
FROM Books
WHERE Price <=29.95
– This query returns a table with the ISBN, Price
and Title from the Books table but only for the
books where the price is less or equal to
29.95.
SQL by Example
• SELECT ISBN, Price, Title
FROM Books
WHERE Title NOT LIKE “%n_x%”
– Returns a table with Price and Title as
columns excluding the boos that contain Linux
or UNIX in the title.
– The “%” character means any zero or more
characters. “_” means any single character.
SQL by Example
• SELECT Title, Name, URL
FROM Books, Publishers
WHERE Books.Publisher_ID=Publishers.Publisher_ID
It returns a table with the Title, Name of pusblisher, and URL from
Books and Publishers.

Title Name URL


A Guide to the SQL Addison-Wesley www.aw-bc.com
Standard
A Pattern Language: John Wiley & Sons www.wiley.com
Towns, Buildings,
Construction
SQL by Example
• You can also use SQL to change data
inside a database.
• UPDATE Books
SET Price = Price – 5.00
WHERE Title Like “%C++%”
This reduces the price by $5.00 for all
books that have C++ in the title.
SQL by Example (from textbook)
• You can also delete rows with SQL
• DELETE FROM Books
WHERE Title Like “%C++%”
– This deletes all books that have C++ in the
title.
SQL by Example
• Use INSERT to insert a new row in the
table.
• INSERT INTO Books
VALUES (‘A Guide to the SQL Standard’,
‘0-201-96426-0’, ‘0201’, 47.95)
– This inserts a new book in the Books table.
SQL by Example
• You can also create a new table using SQL
• CREATE TABLE Books
(
TITLE CHAR(60),
ISBN CHAR(13),
Publisher_ID CHAR(6),
Price DECIMAL(10,2)
)
SQL Tutorials
• For more information about SQL, see the
SQL tutorial in
– http://www.w3schools.com/sql/default.asp

• You can also run some SQL examples


there.

© Gustavo Rodriguez-Rivera 9

You might also like