Structured Query Language(SQL) as we all know is the database language by the use of which we can perform certain operations on the existing database and also we can use this language to create a database. SQL uses certain commands like Create, Drop, Insert etc. to carry out the required tasks.
These SQL commands are mainly categorized into four categories as discussed below:
DDL(Data Definition Language) : DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in database.
Examples of DDL commands:
[1] CREATE – is used to create the database or its objects (like table, index, function, views, store procedure and triggers).
SYNTAX : create table table_name (column_Name1 data_type(size),
column_Name2 data_type(size),
.
.
column_Namen data_type(size));
EXAMPLE : create table empolyee
(empno number(5) ,
ename char(20) ,
job varchar2(20),
salary number(10,2),
commission number(10,2),
deptno number(10));
[2] ALTER- is used to alter the structure of the database i.e. modify the structure or schema of the database ( table).
In ALTER command, they have 4 option are as following:
SYNTAX : alter table table_name
add(column_Name1 data_type(size),
.
.
column_Namen data_type(size));
EXAMPLE : alter table employee
add(mobileno number(10));
(2) MODIFY - change the data_type(size) of column in a table.
SYNTAX : alter table table_name
modify(column_Name data_type(size));
EXAMPLE : alter table employee
modify(name varchar2(20));
(3) DROP - drop the column in a table.
SYNTAX : alter table table_name
drop column column_name;
EXAMPLE : alter table employee
drop(mobileno number(10));
(4) RENAME- change the name column in a table.
SYNTAX : alter table table_name
rename column old column_name to new column_name;
EXAMPLE : alter table employee
rename column ename to empname;
[3] DROP – is used to delete objects from the database and table structure i.e.we can not have table,this time use drop command.
SYNTAX : drop table table_name
EXAMPLE : drop table employee
[4] DESC - This commands is used for display the structure of table.
SYNTAX : desc table_name;
EXAMPLE : desc employee;
[5]TRUNCATE–is used to remove all records from a table, including all spaces allocated for the records are removed. It keep the data structure of table and rollback option is not work after truncate command use.
SYNTAX : truncate table table_name
EXAMPLE : truncate table employee
[6]RENAME-is used to change the name of table.
SYNTAX : rename old table_name to new table_name;
EXAMPLE : rename employee to emp;
[7]CREATE USER– is used to create user in the database or identified by password.
SYNTAX : create user user-name identified by password
EXAMPLE : create user raj identified by raj@123
If you liked the tutorial then don’t forget to comment and share!
These SQL commands are mainly categorized into four categories as discussed below:
DDL(Data Definition Language) : DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in database.
Examples of DDL commands:
[1] CREATE – is used to create the database or its objects (like table, index, function, views, store procedure and triggers).
SYNTAX : create table table_name (column_Name1 data_type(size),
column_Name2 data_type(size),
.
.
column_Namen data_type(size));
EXAMPLE : create table empolyee
(empno number(5) ,
ename char(20) ,
job varchar2(20),
salary number(10,2),
commission number(10,2),
deptno number(10));
[2] ALTER- is used to alter the structure of the database i.e. modify the structure or schema of the database ( table).
In ALTER command, they have 4 option are as following:
(1) ADD - add the new column in a table.
SYNTAX : alter table table_name
add(column_Name1 data_type(size),
.
.
column_Namen data_type(size));
EXAMPLE : alter table employee
add(mobileno number(10));
(2) MODIFY - change the data_type(size) of column in a table.
SYNTAX : alter table table_name
modify(column_Name data_type(size));
EXAMPLE : alter table employee
modify(name varchar2(20));
(3) DROP - drop the column in a table.
SYNTAX : alter table table_name
drop column column_name;
EXAMPLE : alter table employee
drop(mobileno number(10));
(4) RENAME- change the name column in a table.
SYNTAX : alter table table_name
rename column old column_name to new column_name;
EXAMPLE : alter table employee
rename column ename to empname;
[3] DROP – is used to delete objects from the database and table structure i.e.we can not have table,this time use drop command.
SYNTAX : drop table table_name
EXAMPLE : drop table employee
[4] DESC - This commands is used for display the structure of table.
SYNTAX : desc table_name;
EXAMPLE : desc employee;
[5]TRUNCATE–is used to remove all records from a table, including all spaces allocated for the records are removed. It keep the data structure of table and rollback option is not work after truncate command use.
SYNTAX : truncate table table_name
EXAMPLE : truncate table employee
[6]RENAME-is used to change the name of table.
SYNTAX : rename old table_name to new table_name;
EXAMPLE : rename employee to emp;
[7]CREATE USER– is used to create user in the database or identified by password.
SYNTAX : create user user-name identified by password
EXAMPLE : create user raj identified by raj@123
If you liked the tutorial then don’t forget to comment and share!
0 comments:
Post a Comment