SQL

Types of commands in Structured Query Language (SQL):

Data Definition Language (DDL):    Create, Alter, Drop, Truncate, Rename
Data Retrieval Language (DRL):      Select
Data Manipulation Language (DML): Insert, Delete and Update
Data Control Language (DCL):        Grant and Revoke
Transaction Control Language (TCL): Commit, Save point and Rollback

Create Table Command:
                 This command allows you to create a table.
Syntax: CREATE TABLE table_name (Column1  data type null/notnull,column2  data type  null/not null..);
                Each and every column should have a data type.
Creating a table from an existing table:
Syntax: create table table_name as (select * from existing table_name);
Creating a table from the selected columns of an existing table:
Syntax: create table table_name as (select  column1,column2  from existing table_name);
Creating a table definition without the data:
Syntax: create table table_name as (select * from existing table_name where 1=2);

Alter Table Command:
                Alter table command allows you to add, delete and modify the columns in an existing table.
To add a column:
Syntax: alter table table_name add column1 data type;
To modify a column:
Syntax: alter table table_name modify column1 data type;
To delete a column:
Syntax: alter table table_name drop column1;


Drop Command:
The DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed.
Syntax: Drop table table_name

Truncate Command:
Truncate is used to delete all the rows from the table and free the space containing the table.
Syntax: truncate table table_name

Rename Command:
This is used to rename an existing table.
Syntax: rename  old_table_name  to new_table_name
Share on Google Plus

About Mindsforest

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment