The SQL syntax is quite an easy one to grasp. Most of the actions you need to perform are done with a SQL statement.
Generally, a SQL statement begins by stating what to do (for example,
SELECT), then states which object to do it to (for example, using the
It may also have a condition added to the end (for example, with a
SQL is not case sensitive — the above examples could just have easily used all lowercase or all uppercase. Different programmers have their own preferences. For readability purposes, many SQL programmers prefer to use uppercase for SQL commands and lowercase for everything else.
The SQL syntax allows you to include line breaks at logical points without it breaking the statement. For example, the above example could have been written all on one line — or across 4 lines.
Also, a semicolon should be placed at the end of each SQL statement. There are some exceptions where a semicolon may be omitted, however, it's good practice to include them unless you have good reason not to.
DML & DDL
SQL is divided into two main categories; Data Manipulation Language (DML), and Data Definition Language (DDL). An explanation follows.
Data Manipulation Language (DML)
DML enables you to work with the data that goes into the database. DML is used to insert, select, update, and delete records in the database. Many of your SQL statements will begin with one of the following commands:
SELECT- Retrieves data from the database
INSERT- Inserts new data into the database
UPDATE- Updates existing data in the database
DELETE- Deletes existing data from the database
Data Definition Language (DDL)
You may also occasionally need to create or drop a table or other datbase object. SQL enables you to do this programatically using DDL.
Examples of DDL commands:
CREATE DATABASE- Creates a new database
ALTER DATABASE- Modifies the database
DROP DATABASE- Drops (deletes) a database
CREATE TABLE- Creates a new table
ALTER TABLE- Modifies the table
DROP TABLE- Drops (deletes) a table
These are just some of the object classes that can be defined using DDL. As you can probably guess, the syntax is generally the same for any object, although, each object will have properties specific to that object class.
As you can see, the SQL syntax is quite simple. It is also very powerful syntax — you can do a lot of damage with one line of code!