SQL (Structured Query Language): introduction

What’s the big deal with SQL?? I like to simplify everything, because its very difficult to think straight when you know the problem at hand has thousands of modules, several ways to go wrong. So the first thing to do is create a big picture schematic of the problem. So what’s present here is a simple schema of the SQL structure, which is a simple language used on Relational Database Systems. The RDBM systems can be Microsoft, PlSQL, MySqL or Oracle, and there are differences between the syntax implementation between vendors (one could ask why!?) but the principles are similar to all. As are the syntaxes more often used.

An overview of the lexical structure of the SQL.  created using: http://yuml.me

Example 1:

SELECT name, phone FROM Authors WHERE phone=123456789;

Token Special Character: SELECT

Keywords: FROM, WHERE

Operator: = (equal sign)

Objects: name (which is of Datatype String), phone (datatype: int)

Objects Table: Authors

Translation of the statement: Show the name of the author that has the phone number 123456789. The data displayed will show the name and phone number. Attention that this will show more than one registry (row) of for some reason two authors have the same phone number. This could be avoided, by setting the phonenumber as unique, which will enforce a unique relation between phone number and name.

So all the SELECT statements will be similar with this one. Sure it can be way more tricky when adding relations (1-many, many-many) between tables, in that case there will be other keywords to connect (JOIN) the tables, and even nested statements.

Example 2:

Assuming one has 2 tables Authors, Books which are connected by the authorname (OK its not a strong key, but its just for example), anyway,

SELECT name, phone FROM authors INNER JOIN books ON books.authorname = authors.name WHERE authors.phone = 123456789;

Translation: Show the author name, author phonenumber and book title published by the author, which as the phone number 123456789. There are also several other ways (simpler even) to do this but i wanted to point out the use of the keyword INNER JOIN.

References worth checking out :

http://www.thethirdmanifesto.com/