In this post I would like to revise the basic concepts of
SQL: Structured Query Language. This would be based mainly on Oracle. Hope this
mini tutorial would be useful as a quick guide.
DDL: Data
Definition Language: This is a part of
SQL which mainly defines the state of the database schema. There basically four
commands:
“CADT”
Ø
Create: Used for creating database objects:
tables, index, stored query, views etc.
Ø
Alter: Used to modify an existing db object.
Ø
Drop: Completely remove a DB object from the database
Ø
Truncate: Used to remove the data of the table,
but retain the structure of the table.
Right now, we will generalize these commands for tables, though these can be used for any database objects, for convenience sake.
Right now, we will generalize these commands for tables, though these can be used for any database objects, for convenience sake.
Syntax:
create:
Create table
table_name (var datatype,….)
Alter:
alter table table_name add column_name datatype:
Similarly we can drop the added column using alter table table_name drop COLUMN column_name
Note the use of the keyword COLUMN in this case.
Drop:
As we have seen in the previous command, drop is used. Also drop can be used to remove the table/DB object completely from the database.
Drop table table_name;
alter table table_name add column_name datatype:
Similarly we can drop the added column using alter table table_name drop COLUMN column_name
Note the use of the keyword COLUMN in this case.
Drop:
As we have seen in the previous command, drop is used. Also drop can be used to remove the table/DB object completely from the database.
Drop table table_name;
Truncate:
Since we have not inserted any data into the table now, we would deal with truncate in later segment.