Monday, July 28, 2008

SQL Introduction and Data Types

SQL ( Structured Query Language )

SQL is a common language to interact with the database in any RDBMS software.
IBM Corporation first developed SQL. They have developed SQL as a part of
System-R project. After recognizing the ease and flexibility of this part, they have developed it as a separate language and named it as SEQUEL (Structured English Query Language).
Oracle Corporation first commercially released SEQUEL by changing its name to SQL.

Features Of SQL

SQL is a 4th generation (4 GL) or Non procedural language.
Every statement in SQL must end with a semicolon.
SQL is not a case sensitive language.
In SQL at a time a single SQL statement is stored in buffer. To re-execute the statement stored in buffer we have to use ‘/’.
In SQL a single SQL statement can be broken into more than one line without using any continuation character.

Datatypes In SQL

To represent data in database we have to create tables. During the creation of a table we have to specify the columns to be included in the table and the type of values that are going to be stored in those columns. The data types available in SQL are as follows.

Number :
This data type is used to store numeric values in a column. For number datatype maximum allowed digits is specified in parantheses. For example, if we specify the datatype as number(5) then we can store –99,999 to +99,999 in that column.

Char :
This data type is used to store fixed length character data. Max. Allowed size for Char is 1000 bytes.

Varchar2 :
This data type is used to store variable length character data. Max. Allowed Size for varchar2 is 2000 bytes. Difference between char and varchar2 is if we specify the datattype as char(10) and stored the string “Oracle” then even the given string contains 6 characters it occupies 10 bytes in memory by placing blank spaces towards the end. if we specify the datatype as varchar2(10) then it occupies only 6 bytes even max. size is 10.
Long : This data type is used to store variable length character data up to 2 GB.

Raw : This data type is used to store binary data up to 1000 bytes. Binary data means pictures and sounds.

Long Raw :
This data type is used to store binary data up to 2 GB.

Date :

This data type is used to store dates in a column. Default Date format in Oracle is DD – MON – YY (Ex: 12-AUG-02).

No comments: