Today, we take a look at what SQL is and describe its major features and benefits. This is chapter one of McGraw-Hill/Osborne's SQL: The Complete Reference (ISBN 0-07-222559-9, 2004) by James R. Groff and Paul N. Weinberg.
Introduction to SQL - The SQL Language (Page 2 of 8 )
SQL is a tool for organizing, managing, and retrieving data stored by a computer database. The acronym SQL is an abbreviation for Structured Query Language. For historical reasons, SQL is usually pronounced “sequel,” but the alternate pronunciation “S.Q.L.” is also used. As the name implies, SQL is a computer language that you use to interact with a database. In fact, SQL works with one specific type of database, called a relational database.
Figure 1 shows how SQL works. The computer system in the figure has a database that stores important information. If the computer system is in a business, the database might store inventory, production, sales, or payroll data. On a personal computer, the database might store data about the checks you have written, lists of people and their phone numbers, or data extracted from a larger computer system. The computer program that controls the database is called a database management system, or DBMS.
Figure 1. Using SQL for database access
When you need to retrieve data from a database, you use the SQL language to make the request. The DBMS processes the SQL request, retrieves the requested data, and returns it to you. This process of requesting data from a database and receiving back the results is called a database query—hence the name Structured Query Language.
The name Structured Query Language is actually somewhat of a misnomer. First of all, SQL is far more than a query tool, although that was its original purpose, and retrieving data is still one of its most important functions. SQL is used to control all of the functions that a DBMS provides for its users, including:
Data definition. SQL lets a user define the structure and organization of the stored data and relationships among the stored data items.
Data retrieval. SQL allows a user or an application program to retrieve stored data from the database and use it.
Data manipulation. SQL allows a user or an application program to update the database by adding new data, removing old data, and modifying previously stored data.
Access control. SQL can be used to restrict a user’s ability to retrieve, add, and modify data, protecting stored data against unauthorized access.
Data sharing. SQL is used to coordinate data sharing by concurrent users, ensuring that they do not interfere with one another.
Data integrity. SQL defines integrity constraints in the database, protecting it from corruption due to inconsistent updates or system failures.
SQL is thus a comprehensive language for controlling and interacting with a database management system.
Second, SQL is not really a complete computer language like COBOL, C, C++, or Java. SQL contains no IF statement for testing conditions, and no GOTO, DO, or FOR statements for program flow control. Instead, SQL is a database sublanguage, consisting of about 40 statements specialized for database management tasks. These SQL statements can be embedded into another language, such as COBOL or C, to extend that language for use in database access. Alternatively, they can be explicitly sent to a database management system for processing, via a call-level interface from a language such as C, C++, or Java, or via messages sent over a computer network.
Finally, SQL is not a particularly structured language, especially when compared to highly structured languages such as C, Pascal, or Java. Instead, SQL statements resemble English sentences, complete with “noise words” that don’t add to the meaning of the statement but make it read more naturally. There are quite a few inconsistencies in the SQL language, and there are also some special rules to prevent you from constructing SQL statements that look perfectly legal, but don’t make sense.
Despite the inaccuracy of its name, SQL has emerged as the standard language for using relational databases. SQL is both a powerful language and one that is relatively easy to learn. The quick tour of SQL in Chapter 2 will give you a good overview of the language and its capabilities.
Remember: this is chapter one of SQL: The Complete Reference, by Groff and Weinberg (McGraw-Hill/Osborne, ISBN 0-07-222559, 2004). You can find this and many other fine McGraw-Hill Osborne books at your favorite bookstores. Buy this book now.