SQL

Data Definition Language – Introduction

Data Definition Language (DDL):It is also called as data description language which is a similar to other programming languages. We must follow syntax for describing a data or information in database. In this sub language, there are 5-commands are available which are given below.

1. create:It is used to create a table in database.
syntax:SQL>create table <Table Name>(col1 <data type>, col2 <data type>, col3 <data type>, ….);
Example:SQL>create table student(sno int, sname varchar2(20), saddress varchar2(20), sfee number(10, 2));

After creating table, if you want to see the structure of the table, we must use the DESC command in the oracle environment.
DESC syntax:SQL>DESC <Table Name>;
Example:SQL>DESC student;

2. alter:This command is sued to change the table name, table column name, table data type, delete table column and add table column. It is having the following sub commands, they are,

alter rename:This command is used to change the column name and as well as table name.
1. Changing the column name:
syntax:SQL>alter table <Table Name> rename column <old_column_name> to <new_column_name>;
Example:SQL>alter table student rename column sno to student_no;

1. Changing the table name:
syntax:SQL>alter table <Table Name> rename to <new_table_name>;
Example:SQL>alter table student rename to student_table;

alter modify:This command is used change/ modify the column data type in a table.
syntax:SQL>alter table <Table Name> modify <column_name> <data type>;
Example:SQL>alter table student modify sno number(6,2);

Note: When you are changing the column data type to another data type in a table that must be empty

alter add:This command is used to add a new column in a table.
syntax:SQL>alter table <Table Name> add <column_name> <data type>;
Example:SQL>alter table student add smarks int;

alter drop:This command is used to drop/delete a particular column in a table.
syntax:SQL>alter table <Table Name> drop column <column_name>;
Example:SQL>alter table student drop smarks;

3. rename:This command is used to change name of the table.
syntax:SQL>rename <old_Table Name> to <New_Tabble_Name>;
Example:SQL>rename student to student_table;

4. truncate:This command is used to delete all records from a table at a time. But, we can not delete a specific record from a table by using this command.
syntax:SQL>truncate table <Table Name>;
Example:SQL>truncate table student_table;

5. drop:This command is used to delete the structure of the table from an oracle environment.
syntax:SQL>drop table <Table Name>;
Example:SQL>drop table student_table;

About the author

karunakar

I completed the M.TECH, am enthusiastic to finding the gadgets & learning new things.

Add Comment

Click here to post a comment