Saturday, December 15, 2012

SQL Statements


                               SQL Statements





1-DML (Data Manipulation Language)
  1. SELECT
  2. INSERT
  3. UPDATE
  4. DELETE
  5. MERGE



2-DDL (Data Definition Language)
  1. CREATE
  2. ALTER
  3. DROP
  4. RENAME
  5. TRUNCATE
  6. COMMENT
 

3-DCL (Data Control Language)

  1.  GRANT
  2.  REVOKE


4-TCL (Transaction Control Language)
  1. COMMIT
  2. ROLLBACK
  3. SAVEPOINT

SQL Keys

                                                        

Types of SQL Keys


1.   Candidate Key
A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.
2.   Alternate key
A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.
3.   Super Key
Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table. Example: Primary key, Unique key, Alternate key are subset of Super Keys.
4.   Primary Key
Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.
5.   Composite/Compound Key
Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.
6.   Unique Key
Unique key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it cannot have duplicate values.
7.   Foreign Key
Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values.