While using SQL there are some queries we can use on a frequent basis, since these queries play a vital role in storing the data into the database. But, before explaining these queries, let us first understand what "SQL" is.
Structured Query Language (SQL)
SQL stands for Structured Query Language, and is a standard computer language for querying Relational Database Management Systems (RDBMSs) and to store, manipulate and retrieve the data stored in a relational database. All the RDBMS systems use SQL as the standard database language.
Now the question is, what is a RDBMS?
As said above, it stands for Relational Database Management System. It is a database engine that is based on relational model invented by E. F. Codd and uses SQL to access the database.
The data in a RDBMS is stored in database objects called tables. It is the basis for SQL and other modern database systems like:
- MySQL
- Microsoft Access
- ORACLE Sybase
- Informix
- Postgres
- SQL Server
- DB2
SQL commands are mainly divided into six parts and these are as follows.
1. Data Definition Language Commands (DDL)
DDL includes:
| CREATE TABLE | CREATE SEQUENCE | DROP USER |
| CREATE VIEW | CREATE SYNONYM | DROP INDEX |
| CREATE USER | ALTER TABLE | DROP TRIGGER |
| CREATE DATABASE | ALTER VIEW | DROP PROCEDURE |
| CREATE INDEX | ALTER USER | DROP SCHEMA |
| CREATE TRIGGER | ALTER TRIGGER | DROP FUNCTION |
| CREATE PROCEDURE | ALTER SEQUENCE | DROP SEQUENCE |
| CREATE SCHEMA | ALTER SESSION | DROP SYNONYM |
| CREATE FUNCTION | DROP TABLE | DROP JAVA |
| CREATE JAVA | DROP VIEW | TRUNCATE TABLE |
CREATE TABLE, ALTER TABLE, DROP TABLE and TRUNCATE TABLE are the commands that are generally used.
2. Data Manipulation Language (DML)
DML includes:
| DELETE | INSERT | SELECT |
| UPDATE | EXPLAIN PLAN |
3. Data Control Language (DCL)
DCL includes:
| GRANT | REVOKE |
4. Transaction Control Commands (TCC)
TCC includes:
| COMMIT | ROLLBACK | SAVE POINT |
| SET TRANSACTION |
5. Clauses
Clauses includes:
| CONSTRAINT CLAUSE | DROP CLAUSE |
6. Pseudocolumns
Pseudocolumns include:
| LEVEL PSEUDOCOLUMN | ROWNUM PSEUDOCOLUMN | CURRVAL and NEXTVAL PSEUDOCOLUMN |
| ROWID PSEUDOCOLUMN | OL ROW STATUS PSEUDOCOLUMN |
Now, assume the following table to understand the examples.
DDL Commands
1. Create Table Command
It is one of the most fundamental components of SQL. We need to create a table when we want to store some data, and the CREATE TABLE command helps us to do that. And it is compulsory that each table must have its name. Integrity Constraints like primary key, foreign key and unique key can be defined for the columns while creating a table, we can also specify a default value for a column. Different RDBMS systems have different CREATE statements.
Syntax
CREATE TABLE table_name
(
Col1 Datatype Constraint
Col2 Datatype Constraint
Col1 Datatype Constraint
Constraint-list
)
Example
CREATE TABLE Student
(
Stu_ID Number(10),
Stu_Name varchar2(20),
RollNo Number(10),
Stream varchar2(20)
);
Result
Student Table

Kiran Kumar TalikotiPosted Oct 26, 2013, 3:15 AM
Thanks for sharing:)
Nimit JoshiPosted Oct 25, 2013, 12:07 PM
Great Sir.