Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
women using this language to "talk" to a database to retrieve the wanted information. The language did
not take off as expected and wasn't really utilized until Oracle based its database access on this
language. Since then, it has become the standard way data is accessed in a relational database.

As stated earlier, SQL is a language that allows the manipulation of relational databases. It is very
English-like in its syntax. For example, if you wanted to know all of the names of the people who were
born in January in your database, an SQL statement might look like the following:
SELECT First_Name, Last_Name FROM Customers WHERE DOB= "January"

This language is more like a communication tool than a programming language. Most programming
languages are compiled and then executed. Generally, SQL is not compiled. Some forms of SQL, such
as T-SQL, are compiled, but that's a different database and a different language. SQL is the language
of databases, just as English is a language of people. To communicate with another person, you would
ask a question and, if the person knew the answer, he or she would reply back to you. SQL works in
much the same way.

To begin "talking" to your database, you must first open a line of communication with it. MySQL
provides a very nice utility to accomplish this task—the MySQL monitor. If you have been following
along from the start, you should already be very familiar with the MySQL monitor. In fact, the commands
that you have used to manipulate and create the tables and columns of the sample databases were
SQL statements. So you have already seen SQL in action.
SQL is a very powerful language. After you ask a question or issue a command, there is no pulling
back. The command is completed without any hesitation or warning. Be very careful when issuing your
commands, especially against a live production system. I can't begin to tell you the countless stories of
lost data because of sloppiness in an SQL statement. Even I am guilty of this terrible sin. I was
responsible for wiping out about 20,000 rows of production data because of a sloppy DELETE
statement. So take heed and be very careful with all SQL statements you execute against a production
system.

Components of SQL


SQL can be broken down into subcomponents. Because the language covers a broad spectrum, it has been
segmented to help users understand it better. SQL can be broken down into two parts—the part that creates
database objects and the part that manipulates them. The part that creates objects is often called DCL or
data creation language. It is still SQL, but the statements apply only to creation, not manipulation. The other
part that deals with manipulation of data is called DML or data manipulation language. You have already
learned about the DCL part of SQL. You used this when you created your tables and columns.
As stated previously, SQL is a language that is used to talk to databases. Because SQL is a language,
it has certain rules and grammar that must be followed. There is also a list vocabulary words used in
SQL. These words can be thought of as reserved words because they have special meaning. SQL
understands the following verbs: CREATE, DROP, ALTER, DELETE, INSERT, UPDATE, and SELECT. SQL
also understands the following words: SET, FROM, INTO, WHERE, JOIN, LEFT JOIN, CROSS JOIN,
RIGHT JOIN, FULL JOIN, INNER JOIN, ON, ORDER BY, and GROUP BY. See Table 9.1 for a full list
of special words.
Table 9.1 Reserved Words


CREATE DROP
ALTER DELETE
INSERT UPDATE
SELECT SET
FROM INTO
ON WHERE
ORDER BY GROUP
BY
JOIN LEFT
JOIN
CROSS JOIN FULL
JOIN
RIGHT JOIN AND
LIMIT OR
Free download pdf