Wednesday, 13 May 2015

SQL Intro & SQL Statements

The Structured Query Language (SQL) is a standard language designed to access the relational databases. SQL is either pronounced as a word SEQUEL or as letters SQL.SQL uses a syntax which is easy to learn and use.

There are five types of SQL statements

1.    Query Statements – This allows you to retrieve the records stored in the database tables. The SELECT statement is used for this.

2.    Data Definition Language (DDL) – This allows you to define the data structures such as tables that make up the database. There are five types of DDL Statements.
  • CREATE – This allows you to create the database structure.
  • ALTER – This allows you to modify the database structure.
  • TRUNCATE – This allows you to delete the whole contents of the table.
  • DROP – This allows to you remove the structure from the database.
  • RENAME – This allows you to change the name of the data structure from one to another.
3.    Data Manipulation Language (DML) – This allows you to modify the contents / data stored in the data structures such as tables. There are three types of DML Statements
  • INSERT – This allows you to insert the records into the table
  • UPDATE – This allows you to change the records.
  • DELETE – This allows you to delete the records.
4.   Transaction Control (TC) Statements – This allows you to permanently record or discard/undo the changes made to the records stored in the table. There are three types of DCL Statements.
  • COMMIT – This allows you to permanently save/record the changes made to the rows in a table.
  • ROLLBACK – This allows you to undo / discard the changes made to the rows in the table.
  • SAVEPOINT – This allows you to set a point to which you can ROLLBACK the changes. This is used when you want to perform a partial UNDO operation.
5.    Data Control Language (DCL) – This allows you to change the permissions on the database structures i.e., grant / revoke access to / from a user for a database structure.
  • GRANT – This allows you to give another user access to your database structures such as tables.
  • REVOKE – This allows you to prevent another user from accessing your database structures.