Programming Index Cards

August 1, 2008

Why Use SQL Over procedural?

Filed under: SQL, database, programming — apcig @ 3:01 am

http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=27

Why Use SQL Over procedural?

Structured Query Language (SQL) is a set-based language as opposed to a procedural language. It is the defacto language of relational databases.

The difference between a set-based language vs. a procedural language is that in a set-based language you define what set of data you want or want to operate on and the atomic operation to apply to each element of the set. You leave it up to the Database process to decide how best to collect that data and apply your operations. In a procedural language, you basically map out step by step loop by loop how you collect and update that data.

There are two main reasons why SQL is often better to use than procedural code.

  • It is often much shorter to write – you can do an update or summary procedure in one line of code that would take you several lines of procedural.
  • For set-based problems – SQL is much faster processor-wise and IO wise too because all the underlining looping iteration is delegated to a database server process that does it in a very low level way and uses IO/processor more efficiently and knows the current state of the data – e.g. what other processes are asking for the data.

Blog at WordPress.com.