|
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.
|
|
|
|
|
|
|
|
|
|
What are you going to discuss now?
Now
you will learn basic SQL statements such as SELECT,
INSERT, UPDATE
and DELETE.
For all the examples in this article we would be using
a sample database table which is shown below
Table
Name : people
|
lastname
|
firstname
|
age
|
address
|
city
|
|
Pai
|
Kiran
|
22
|
Mahavir
Nagar
|
Mumbai
|
|
Hunter
|
Jason
|
41
|
Oak
Street
|
San
Jose
|
|
Kanetkar
|
Yashwant
|
38
|
Rajabhai
Street
|
Nagpur
|
|
|