STRUCTURED QUERY LANGUAGE (SQL)
Structured Query Language is a language that provides an interface to Relational Database Management System.SQL was developed by IBM in 1970s for the use of data in big organisation properly. SQL consists of several commands for communication with Oracle server. SQL is a non-procedural language, which has an English like structure and allow the user to specify what is wanted rather than how it should be done. SQL supports many statements that directly implement the corresponding relational algebra operation.SQL is the Standard Database Language supported by every RDBMS.
SQL is used to communicate with a database. According to ANSI (American National Standards Institute), it is the standard language for relational database management systems. SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database. Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, Ingres, etc. Although most database systems use SQL, most of them also have their own additional proprietary extensions that are usually only used on their system. However, the standard SQL commands such as "Select", "Insert", "Update", "Delete", "Create", and "Drop" can be used to accomplish almost everything that one needs to do with a database. This tutorial will provide you with the instruction on the basics of each of these commands as well as allow you to put them to practice using the SQL Interpreter.
Features of SQL.
• It is non-procedural or set oriented language. • Recovery and concurrency. • Integrity constraints. • The security can be maintained by view mechanism. • It is English like language. • Time efficient.
Classification of SQL statements.
➢ Data Definition Language(DDL). It is a set of SQL command used to define the data in the data-base. This definition includes all the entity sets and their associated attributes as well as the relationship among the entity sets.(Used to define the objects in a relational database).e.g.CREATE,ALTER and DROP.
➢ Data Manipulation Language(DML). It is a set of SQL commands used to manipulate the data in the data-base. Data Manipualtion involves retrieval of data from data-base, insertion of new data into the data-base and deletion or modification of existing data.(Used for query,addition,deletion and updation of data stored in the database).e.g.SELECT,UPDATE and DELETE.
➢ Data Control Language(DCL). ): It is a set of SQL commands used to control the access of data from data-base.(Used for controlling data stored in the database).e.g.GRANT,REVOKE.
➢ Tranaction Control Language(TCL). It is a set of SQL commands used to control the transaction activities done on the data-base. (Used to save the changes made in the table as well as to ignore the changes).e.g.ROLLBACK,SAVEPOINT and COMMITE.
➢ Data Query Language(DQL). It is a component of SQL statement that allow to get data from data-base..(Used to query data from the table).e.g.SELECT.
S.NO SQL COMMANDS DESCRIPTION COMPONENTS
CREATE To create the schema object (table).
To alter the schema object. ALTER
1. DDL DROP To delete the schema object.
RENAME To rename the schema object.
INSERT To insert data in the table.
UPDATE To update existing data with in a table.
To delete all the records from the 2. DML table or to remove rows from the DELETE table.
GRANT To give permission and take away parbaligious to access the
data.
3. DCL REVOKE To give permission and take away parbaligious to access the data.
COMMIT To make a transaction permanent.
4. TCL SAVEPOINT To set a point to which transaction can be rollback.
To undo changes in the ROLLBACK transaction.
5. DQL SELECT To retrive data from one or more table.
SQL DATATYPES
When we create a table, we need to specify the datatype of each column.Datatypes are declared to identify the type of data that will be held or stored for a particular column or variable.The datatypes may be followed by one or more number of parentheses which give information about the column’s width.The table given below list important datatypes.
S.NO DATATYPES DESCRIPTION 1. CHAR(255) This data type is used to store character strings value of fixed length. The size in bracket determine the number of characters the cell can hold. The maximum number of characters this data type can hold is 255 characters. 2. VARCHAR/ This data type is used to store the variable length alpha VARCHAR2 numeric data. It is more flexible form than the char data type. (4000) The maximum number of characters it can hold is 4000 characters. 3. This data type is used to represent date and time. The DATE standard format is DD-MM-YY i.e. 22-jan-13. To enter date other than the standard format we can use appropriate function. 4. NUMBER(P,S) This data type is used to store number either fixed or floating (38) points. It can be used to store either zero, positive and negative numbers. The precision (P) determine the maximum length of the data, and the scale (S) determine the number of places to the right of the decimal. If scale is omitted then, by default it is a zero value. The maximum value of precision value is upto 38 digits.
5. LONG(2GB) This data type is used to store variable length character strengths containing upto 2 GB.
6. RAW/LONG This data type are used to store binary data such as digitised RAW(2GB) picture or image. Raw data type can have a maximum length of 255 bytes. Long raw data type can contain upto 2 GB.
Commands used in Data Definition Language (DDL)
1. CREATE TABLE Command. We use CREATE TABLE command to create a new database.With this command we can specify a name,type,precision and scale for each field in the data base to be created.
Syntax:- CREATE TABLE
Example:-To create a table STUDENT holding the SNO, ROLLNO, NAME, BRANCH, SEM, MARKS the following command has to be writen CREATE TABLE STUDENT (SNO NUMBER(5), ROLLNO NUMBER(10), NAME CHAR(20), BRANCH CHAR(10), SEM VARCHAR2(10), MARKS NUMBER(10));
2. ALTER TABLE Command.
This command is used to change the table.We can add new column,change the datatype of columns or drop any constraints using ALTER TABLE command.
• The ADD Clause. Using ADD clause we can add new column into the table. Syntax:- ALTER TABLE