Hudzilla.org - the homepage of Paul Hudson
Contents > Databases Wish List | Report Bug | About Me ]

9.3     SQL

This is NOT the latest copy of this book; click here for the latest version.

The data inside your database server is stored in large, compressed files, which are read in by the DBMS and manipulated through the DBMS. The way we read and write data is through a special language known as Structured Query Language (SQL). SQL, pronounced S-Q-L (not "Sequel"), is a very simple language designed to let you specify how you want to manipulate your data without needing to specify the steps the DBMS should go through - that is, you say "I want this", not "I want this, so do A, B, and C, then give me D", which makes SQL a 4th-generation language (4GL). SQL can be surprisingly powerful when you get skilled with it, so it is strongly recommended you read this whole section thoroughly.

If we did not have SQL, data extraction would be much more difficult. For example, the SQL syntax to select the Name attribute of all fields in a table is this:

SELECT Name FROM sometable;

That would automatically return an array of all the values. If we did not have SQL, we would need to do something like this pseudo-code:

Open file sometable.db
Search from line one to end of file {
    Split each line into fields
    Get field "Name" and add to our array of return values
}
Return array of names

It's not exactly hard , but it's certainly a lot more work than is necessary, and that was only for a simple query - some really complicated SQL queries are three or four lines long, and it'd be very chaotic to have to do the same using a generic language such as PHP or C++.

Author's Note: "Sequel" is actually an entirely separate language, which is why the pronunciation of SQL (ess-que-ell) needs to be preserved.

All databases, from Oracle all the way down to the lowly Microsoft Access, support SQL, although most have their own dialect of it - a slightly different version to implement various special features. Using SQL you can extract data from any DBMS, regardless of who makes it, which makes it easy to learn and use wherever you go.

Note that SQL is case insensitive, but for the purpose of clarity I have tried to print all SQL keywords in uppercase in this book.





<< 9.2.4 Microsoft SQL Server   9.3.1 SQL comments >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP User - 05 Sep 2008

how about we leave the SQL/sequel/squeal and just call it squirrel? thats way more fun than the other lot

Gunny - 05 Sep 2008

The only way to pronounce it is in your best teenage squeaky voice is (My) Essssssss-Squeal

kewlceo - 05 Sep 2008

I know people who use all three variants (S-Q-L, Squeal, and Sequel). As for me, it's quicker to say "sequel"; besides, I can't be arsed about a trademark held by an aircraft company.

A PHP User - 05 Sep 2008

Um, the author's comment is incorrect. "Sequel" = SEQUEL = SQL. It is NOT in fact as separate language, it is the same language and just the original name for it.

*The acronym SEQUEL was later condensed to SQL due to a trademark dispute (the word 'SEQUEL' was held as a trade mark by the Hawker-Siddeley aircraft company of the UK)*

http://en.wikipedia.org/wiki/SQL

singpolyma AT gmail.com - 05 Sep 2008

I know some ppl call SQL 'Squeal'... but I never heard of it being called sequel..

nielubie@yahoo.com - 05 Sep 2008

Author's Note: "Sequel" is actually an entirely separate language, which is why the pronunciation of SQL (ess-que-ell) needs to be preserved.

Now at work and vendors that I deal with, they use SQL and Sequel interchangeably. Is it totally a different language or is it just another version of SQL?

BTW, great book so far. I have learned so much, can't wait so start working on my RPG game.



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is three plus ten?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow