Data Management

Is SQL a legitimate programming language?

Developers often dispute the merits of SQL as a legitimate programming language, but this misses the point. SQL is a powerful 4GL for accessing data.

Let’s face it: Bigotry within the ranks of the development community is rampant. Java developers look down on .NET stalwarts, and vice versa. Surprisingly, I’ve noticed the same behavior with SQL (Structured Query Language). Many developers view SQL as an afterthought—a relatively easy syntax for accessing data. These novices usually access relational data by way of Open Database Connectivity (ODBC), Java Database Connectivity (JDBC), or a native driver. They are blind to the power of SQL.

Yes, SQL is a language
As the SQL acronym pronounces, it is a language. It offers looping, logic directives, variables, and so on. Now, it’s not a language in the same sense as, say, Java or C++: SQL is considered a fourth-generation language (4GL), whereas Java and C++ are third-generation languages (3GLs).

Fourth-generation languages are programming languages that are closer to human language than high-level languages like Java. These 4GLs are often used to access databases, such as SQL, where humanlike syntax is used to retrieve and manipulate data.

SQL may not be a language on par with Java or C#, but it is a language. This is often a moot argument with Visual Basic or C developers. They refute the claim by stating that SQL is not compiled and offers little functionality compared to a 3GL.

The power of SQL
The best way to prove a point is by offering a concrete example. The following sample SQL illustrates the power and depth of SQL:
IF EXISTS (SELECT * FROM table_name1)
BEGIN
UPDATE table_name2 SET field_name = ‘value’
FROM table_name2 alias2 INNER JOIN table_name1 alias1
ON alias2.field_name = alias1.field_name AND alias2.fieldname = alias1.fieldname
END
ELSE
BEGIN
UPDATE table_name2 SET field_name = ‘value’
FROM table_name2 alias3 INNER JOIN table_name1 alias4
ON alias3.fieldname = alias4.fieldname AND alias3.fieldname = alias4.fieldname
END
ELSE
PRINT ‘Error’


This example was constructed on SQL Server. It demonstrates a few points: control flow (IF/ELSE), control block (BEGIN/END), and Boolean operators (AND)—all elements of a programming language.

In addition, it’s easy to incorporate variables. You can reuse code in stored procedures and automate or schedule procedures using triggers. Many of these elements depend on the database platform (SQL Server, Oracle, Sybase, Informix, DB/2, etc.), but the core SQL99 standard is often supported.

Learn more about SQL
SQL allows easy access to that valuable data. Read these Builder.com articles to learn more about this important standard:

Data is king
Data is the backbone of an enterprise. It’s retrieved for reporting or viewing, and new data is often added with the purging of older data. SQL provides the language to easily work with this valuable commodity. The power afforded by SQL should not be dismissed lightly.

I’d like to know your thoughts. Have you encountered similar SQL bigotry? Please post your comments in the discussion below or send me an e-mail. I look forward to a lively discussion.
0 comments

Editor's Picks