Monday, January 3, 2011

A complete tutorial of SQL

this will guide you through a complete refrence but we will go step by step
before starting sql some basic concepts should be clear so starting with introduction:

What is Database?

It is collection of information(records) that is organized so that it can easily be accessed,managed and updated.
What is Database Mangement System?

It is set of computer programs that controls the creation,maintenance and the use of the database of an organization.
Eg. Oracle,mysql.

What is SQL?

SQL stands for Structured Query Language.
Originally developed by IBM in the early 1970s.
It was initially spelt and pronounced as ‘SEQUEL’ but now popularly called SQL.
It has  an ANSI as well as ISO standard.
 

In DBMS a group of similar information or data which is of interest to an organization is called an Entity.
Entity information is stroed in an object called Table.

Eg. Student (entity) & information about student stored in student_master table.
Table is two dimentsional matrix that consists of rows and columns.
Table must have a unique name(i.e here student_master).

Components parts of a Two Dimensional Matrix:

Attributes/columns/fields:

Each entity can have a number of characteristics. 
Eg. Student have characteristics name,address,telephon number etc…
The values for these characteristics are called Attributes values.

Tuple/record/row:
An organization will deal with many clients and the same information must be record for each student. Multiple fields placed in a horizontal plane, is called a record or row or tuple.

Different Components of SQL:
Data Defination Language(DDL)
Data Manipulation Language(DML)
Data Control Language(DCL)
Transaction Control
Data Retrieval(Queries)


DDL (Data Defination Language):
The DDL commands related to structure of an object (table ,view etc.)
   i.e creating an object, modifying structure of an object, removing an object or changing the name of object
   E.g.  CREATE,ALTER,DROP,RENAME,TRUNCATE

DML (Data Manuplation Language):

The DML commands are those related to the content of the table (i.e data). They deal with the insertion, updation and deletion of rows in a table.
   E.g. INSERT,UPDATE,DELETE.

DCL(Data Control Language):


The DCL commands are required to give or take back access rights on objects.
      eg. GRANT,REVOKE

TRANSACTION CONTROL:


Handle the unit of work i.e a transcation
   A transcation either exectues as a whole or none of its statements execute.
   eg. COMMIT,ROLLBACK,ROLLBACK TO SAVEPOINT

Data retirval:
-To display data(records,columns)in required fields.
   Eg. SELECT(many options with the select command)

DATA TYPES:


1)CHAR (size):    To store character strings values of fixed length. 
            Max no:255

   oracle compares CHAR values using blank – comparison semantics i.e  if a value that is inserted in a cell CHAR data type is shorter than the size it is defined for then it will be padded with spaces on the right until it reaches the size characters in length.

   2)VARCHAR/VARCHAR2(size):  To store variable length alphanumeric data.
               max no: 2000characters
   Note: inserted values will not be padded with spaces.

   3)NUMBER(P,S):    To store numbers (fixed or floating)
      P (precision): max. length of data
      S (scale):   number of places to the right of the decimal
   IF scale is omitted then default is zero. If precision is omitted ,values are stored with their original precision upto the maximum of 38 digits.
         Max:38 digits.

4) DATE:   To reprent date and time. 
      Standard format: DD-MON-YY  & 24 hour    time format.eg. 21-JUL-09.
      By default time is 12:00:00  If no time portion is specified.
      The default date : first day of the current month.

  5) LONG:    Variable length character string(2 GB)

  6)RAW/LONG RAW:
      To store binary data like digitalized picture or 
      image.(255bytes for raw and 2 GB for long raw)
eg.The Situation: Student table

field           type       width            contents
        id             numeric           4        student id number
    name             varcharacter    10          name
    Address           varcharacter     20        address
     dob               date        8        date of birth
    sex            character             1        sex: M / F

this is end of chap1 we will see how to create databse using sql and study the DDL and DML queries in the next lesson

while learning sql one should have database software so that  you can practice while learning i reccomend to have "oracle" because it is available free for education purposes new release is 11g sp2 available on www.oracle.com
to practice sql i will also provide the exercises with there solutions..

No comments:

Post a Comment