Basic Terms of Structured Query Language (SQL)

by Terry Kerolek.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on databases  

You are here: Categories » Computers and technology » Databases

The first questions to ask are what is SQL and how do you use it with databases? SQL has three main roles:

1. Creating a database and defining its structure
2. Querying the database to obtain the data necessary to answer questions
3. Controlling database security

Defining database structure includes creating new database tables and fields, setting up rules for data entry, and so on, which is expressed by a SQL sublanguage called Data Control Language (DCL). The next section discusses querying the database. Finally, DCL deals with database security. Generally, database security is something that database administrators handle. Creating SQL every time you want to change the database structure or security sounds like hard work, and it is! Most modern database systems allow you to execute changes via a user-friendly interface without a single line of SQL.

Introducing SQL Queries
SQL queries are the most common use of SQL. A SQL sublanguage called Data Manipulation Language (DML) deals with queries and data manipulation. SQL allows you to pose a query (basically a question) to the database, and the database then provides the data that answers your query. For example, with a database that stores details of salespersons, car sales, type of cars sold, and so on, you might want to know how many cars each salesperson sold in each month and how much money they made the company. You could write a SQL query that asks this question and the database goes away and gets the data that answers it. A SQL query consists of various statements, clauses, and conditions. A statement is an instruction or a command. For example, “Get me some data” is a statement. A clause specifies limits to a statement, the limits being specified using conditions. For example, instead of “Get some data,” you might say, “Get data only for the sales that were in the month of May,” where “only for” is the clause that specifies which data to retrieve. The condition is “were in the month of May.” If the data doesn’t meet the condition’s criteria, in this case, “month of May,” then you don’t want it. Written as actual SQL code, this could be something like the following:

SELECT CarModel
FROM CarSales
WHERE CarSoldDate BETWEEN ‘May 1 2005’ AND ‘May 31 2005’;

The SELECT statement tells the database system that you want to select some data from the database. You then list the data you want, in this case CarModel data, which is a field name. You then specify the place the data needs to be taken from, in this case a table called CarSales. Finally, you have a condition. The statement above specifies that you want only the data where certain conditions are true. In this case, the condition is that the CarSoldDate is between the first and thirty-first of May 2005.

Comparing SQL to Other Programming Languages
Now that you know what SQL can be used for, you can compare it to other programming languages. To be honest, SQL is quite different from the procedural languages such as C++, Visual Basic, Pascal, and other third-generation programming languages, which allow the programmer to write step-by-step instructions telling the computer exactly what to do to achieve a specified goal. Taking the car sales example, your goal might be to select all the information about sales made in July from the New York car showroom. Very roughly, your procedural language might be along the lines of the following:

1. Load the sales data into the computer’s memory.
2. Extract the individual items of data from the sales data.
3. Check to see if each item of data is from the month of July and from the New York showroom.
4. If it is, then make a note of the data.
5. Go to the next item of data and keep going until all items have been checked.
6. Loop through the data results and display each one.

SQL, however, is a declarative language, which means that instead of telling it what to do to get the results you want, you simply tell it what you want, and it figures out what to do and comes back with the results. In the car sales example, if you were using SQL, you’d specify the results you want, something like this:
SELECT all the data from the sales table WHERE the sales were in July and made at the New York showroom. The SQL language is actually fairly easy to read. The actual SQL could look like this:
SELECT * FROM SalesMade WHERE SaleDate = “July 2005” AND SalesOffice = “New York” The asterisk simply means return the data from all the fields in the record.

Understanding SQL Standards
As with databases, IBM did a lot of the original SQL work. However, a lot of other vendors took the IBM standard and developed their own versions of it. Having so many differing dialects causes quite a headache for the developer, and in 1986 it was adopted by the standards body the American National Standards Institute (ANSI) and in 1987 by the International Standards Organization (ISO), who created a standard for SQL. Although this has helped minimize differences between the various SQL dialects, there are still differences between them. The following table gives a brief summary of the various standards and updates to those standards.

Year Name Also Known As Changes
1986 SQL-86 SQL-87 (date when First publication of the ANSI/ISO adopted by ISO) standard

1989 SQL-89 Only small revision of the original standard

1992 SQL-92 SQL2 Major update of the original standard and still the most widely supported standard

1999 SQL-99 SQL3 Update of the 1992 standard adding new ways of selecting data and new rules on data
integrity and introducing object orientation

2003 SQL-2003 Introduced XML support and fields with autogenerated values

The SQL you write works on most RDBMSs with only minor modifications. There are times when the various RDBMSs do things so differently that compatible code is impossible without big changes. Although standards are important to help bring some sort of commonality among the various RDBMSs’ implementation of SQL, at the end of the day what works in practice is what really counts. That said, the next section shows you how to create your own SQL database.

Leave a comment or ask a question
Total comments: 0

Databases Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
Extracting and Transforming Data in SQL Server 2000 - SQL Server 2000 has several components that support the import and export of data. Data Transformation Services (DTS) is used to import and export data between like OLE DB (more...)
Introduction to SQL - SQL is an acronym for Structured Query Language and is the standard language for interaction with databases. SQL is both an ISO (International Organization for Standardization) and ANSI (Americ (more...)
What Is a Database - A database is simply an organized collection of information. It allows many different types of data to be stored and retrieved in a highly efficient manner. Information within a database (more...)
Installing MySQL Server - Installing MySQL is relatively painless. First, you need the installation program for MySQL, which is available on the companion CD. You can also download the latest version from (more...)
Basic SQL syntax: Creating and Modifying tables and databases - This tutorial shows basic syntax and commands and of the SQL language. Creating and Dropping Databases First, let's see what databases already exist in the MySQL server. We (more...)
Joining SQL Tables - When accessing information within database tables, we may sometimes need to look at data from two or more different tables, as we saw in the previous example. There is another useful way to acc (more...)
Relational SQL Databases - Think of a database that related the players in a game to one another (for example, to determine who was a friend of each player and who was an enemy of each player). First let's create (more...)
SQL Data Import Methods - This article presents the most common ways of importing data to MySQL. Importing from a Text File To create a text file that contains several records to be added to ou (more...)
SQL Data Manipulation: Select Insert Delete and Modify SQL data - This tutoriald focuses on how to add, modify, and remove data from tables in the database using SQL Data Manipulation Language. Without this knowledge, we would not really have any use for a (more...)
Setting the Color of a Movie Clip - You want to control the color of a movie clip dynamically (at runtime, rather than during authoring). Create a Color object that targets the desired movie clip, and then use the Color.setRGB( ) met (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.