Understanding Basic SQL Syntax
Jon Flanders
@jonflanders [Link]
A SQL Statement is an
expression that tells a
database what you want it
to do.
SELECT CLAUSE FROM CLAUSE
{
{{
SELECT first_name FROM person ;
{
{
{
KEYWORD KEYWORD
IDENTIFIER IDENTIFIER
Basic SQL Commands
id first_name last_name
1 Jon Flanders
SELECT
Retrieves one or more rows from one or more tables
SELECT first_name, last_name FROM contacts;
Basic SQL Commands
id first_name last_name
1 Jon Flanders
INSERT 2 Fritz Onion
Adds one or more rows into a table
INSERT INTO contacts (first_name, last_name)
VALUES (‘Fritz’,’Onion’);
Basic SQL Commands
id first_name last_name
1 Jon Flanders
Ahern
UPDATE
Modifies one or more rows in a table
UPDATE contacts SET last_name = ‘Ahern’ WHERE id = 1;
Basic SQL Commands
id first_name last_name
1 Jon Flanders
2 Fritz Onion
DELETE
Removes one or more rows from one table
DELETE FROM contacts where id = 2;
More on these commands in later modules!
I’ll be using MySQL
ANSI SQL Only
Course SQL Keywords will be in upper-case
Housekeeping Table names will be singular
Column names will never be repeated
Summary
! Once you understand the basics of SQL