Library tutorials & articles

SQL In Simple English

Lets get started

What is SQL?
SQL stands for 'Structured Query Language'

What does that mean?
There are a lot of Databases available in the market such as MS Access, Oracle and many others. For you to write programs that interact with these databases easily, there has to be a way where you could get information from all these databases using the same method. For this purpose SQL was developed. It is a kind of language (simple when compared to the likes of C or C++) which enables you to ask all your queries to a database without bothering about the exact type of database.


What the heck is SQL??!!!

Ok lets get straight to the point. Suppose you have a database which has a table called people. (I hope you know what tables are). And you want the details of all persons whose firstname is 'Reena'. So you could use a SQL statement as follows

SELECT * FROM people WHERE firstname = 'Reena'

When you use this Query the database engine would first find the table called people. Then it would find a column called firstname. Next it would compare all the values in that column with 'Reena'. Finally it would return all the details wherever it finds a match for the firstname.


Tell me something more of the bigger picture..
When you write a database program in VC++ or Java or any other language for that matter, you would make a database connection to your database and then you would query the database using SQL queries. When you query the database with any SQL query the database returns a recordset. A recordset is basically a set of records (all the entries that your query returns). This recordset is received in your program and all languages have a data structure which represents a recordset. Once this data structure (in your program) gets populated with the results from the database query, your could use a for loop to loop through all the entries.

How do I connect to a Database through my program?
Hey guys.. this is a tutorial on SQL.. so I wouldn't be focussing on those aspects in this series


What was that thing about recordsets?
When you connect to a database and execute SQL Queries,the results of the Query are returned back to your program. This returned data has to be stored in some Object or Data Structure within your program to be used by your program. Once you store the results in this Object you no longer have to be connected to the Database. For a more detailed explanation please refer to a book on Database programming.

Comments

  1. 10 Jun 2003 at 14:57

    Hi I would first like to say your site has been really helpful to me.


    When using ASP to display database information in a web page you might use


    [courier new]
    Set adoConnect = Server.CreateObject("ADODB.Connection")
    adoConnect.Open "Reports"
    Set onIndex = Server.CreateObject("ADODB.Recordset")


    strSQL = "SELECT * FROM index WHERE number=10"


    onIndex.Open strSQL, adoConnect
    [/courier new]


    Then if you wanted to display the recordset you could use


    [courier new]
    <% onIndex=("Number") %>
    [/courier new]


    but what I can't work out is if your select statement uses COUNT how do you display the result


    [courier new]
    Set adoConnect = Server.CreateObject("ADODB.Connection")
    adoConnect.Open "Reports"
    Set onIndex = Server.CreateObject("ADODB.Recordset")


    strSQL = "SELECT COUNT(*) FROM index WHERE number=10"


    onIndex.Open strSQL, adoConnect
    [/courier new]

  2. 06 Mar 2002 at 09:17

    sorry probably it has been too long  and may be you've got the answer but try this
    select  * from table where date> #2/2/1979#

  3. 26 Feb 2002 at 12:35

    hi..
    check this ... should work


    select * from tablename where DateOfBirth<TODATE('10/9/1976','mm/dd/yyyy')


    try using TO_DATE with the date you want.. i have used this before in this manner..


    hope it helps


    bye

  4. 26 Feb 2002 at 06:47

    Thanks, very helpful.


    What about dates though?  What is the code for finding dates using the SELECT statement eg 'SELECT from * WHERE DateOfBirth < 10/9/76 10:01:10', I can't get it to work.

  5. 01 Jan 1999 at 00:00

    This thread is for discussions of SQL In Simple English.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • Stack Overflow: Podcast #31

    This is the thirty-first episode of the StackOverflow podcast, where&#10;Joel and Jeff discuss.. stuff!&#10;&#10;Based on some comments from Podcast #30, we now know that &ldquo;Learning about NP-Completeness from Jeff is like learning about irony from Alanis Morissette&rdquo;. It&rsquo;s funny b...

Related jobs

Events coming up

  • Jun 16

    Code Generation 2009

    Cambridge, United Kingdom

    A developer event with a practical focus on helping people get to grips with code generation tools and technologies.