As we mentioned earlier, SQL resembles a human language more than a computer language because it has a simple, defined imperative structure. Much like an English sentence, individual SQL commands, called “queries,” can be broken down into language parts. Consider the following examples:
CREATE TABLE people (name CHAR(10)) verb object adjective phrase INSERT INTO people VALUES ('me') verb indirect object direct object SELECT name FROM people WHERE name LIKE '%e' verb direct object indirect object adjective phrase
Most implementations of
SQL, including MySQL, are case
insensitive. Specifically, it does not matter how you type SQL
keywords as long as the spelling is correct. The previous
CREATE
example could just as well be:
cREatE TAblE people (name cHaR(10))
The case insensitivity extends only to SQL keywords.[1] In MySQL, names of databases, tables, and columns are case-sensitive. This case sensitivity is not necessarily true for all database engines. Thus, if you are writing an application that should work against all databases, you should assume that names are case sensitive.
This first element of an SQL query is always a verb. The verb
expresses the action you wish the database engine to take. While the
rest of the statement varies from verb to verb, they all follow the
same general format: you name the object upon which you are acting
and then describe the data you are using for the action. For example,
the query CREATE TABLE people (name CHAR(10))
uses
the verb CREATE
, followed by the object
TABLE
. The rest of the query describes the table
to be created.
An SQL query originates with a client (the application that provides the façade through which a user interacts with the database). The client constructs a query based on user actions and sends the query to the SQL server. The server must then process the query and perform the specified action. Once the server has done its job, it returns some value or set of values to the client.
Because the primary focus of SQL is to communicate actions to the database server, it does not have the flexibility of a general-purpose language. Most of the functionality of SQL concerns input to and output from the database: adding, changing, deleting, and reading data. SQL provides other functionality, but always with an eye towards how it can be used to manipulate the data within the database.
[1] For the sake of readability, we capitalize all SQL keywords in this book. We recommend this convention as a solid “best practice” technique.