Database Land

February 3, 2008

The Basics (V) – Database Queries & SQL

Filed under: basics, query, sql — Amr El-Helw @ 5:59 pm

So far, we have talked about the data being arranged nicely into tables, with relationships between these tables that represent the relationships between the real life objects they represent. We even have information about these tables stored in the database catalog. So, now what??

The real advantage of a database system is not its ability to store the data in an organized format. If we have huge amounts of data that we only need to store, then we can just dump it into huge text files. Actually, we might as well just leave all the data in huge paper files tucked into an old dusty archive room. After all, the data will just be sitting there. But let’s say, for some reason, I want to check how many projects have been completed by the XYZ department in the year 2005, with only 5 employees or less working on each project. I think it will be hard to go through all those files to figure out the answer to that.

That’s where databases make our life easier. The real advantage of using a database is not just storing the data, but also being able to query the data…efficiently. Think of a database query as a question. The user asks the database a question, and the database returns the result. Database queries can be as simple or as complex as required.

In order to standardize the way databases are queries, SQL (Structured Query Language) was invented. SQL is a standard way of formulating a query that can be understood be any database system (except from some system-specific features that are not part of the standard SQL). SQL is considered a declarative language, not a procedural language. This means that the user only specifies WHAT they want, not HOW to get it. For example, the following simple SQL query asks the database to retrieve the names of all employees who work in the Sales department since before 2001:

SELECT name
FROM employee
WHERE dept_name = ‘Sales’
AND hire_year < 2001

SQL can also be used to insert or update the data in the database. We are not going to get into the details of SQL here, but a good introduction to SQL can be found here.

1 Comment »

  1. [...] processing, query, rewrite, semantic, sql — Amr El-Helw @ 2:20 pm I mentioned before that SQL is a declarative language, where the user only specifies WHAT they want to get from the database, [...]

    Pingback by The Basics (VI) - Overview on Query Processing « Database Land — February 14, 2008 @ 2:20 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.