DDL Commandss
There are four types of DDL commands:
- CREATE
- ALTER
- DROP
- TRUNCATE
There are four types of DDL commands:
A database is nothing but the structured organization of data. For organizing the data in a database we need to create database tables as per the required structure
CREATE is the DDL(data definition language) commands used for the creation of the tables in a database
CREATE TABLE table_name
(
column1 datatype(size),
column2 datatype(size),
column3 datatype(size),
.....
columnN datatype(size),
PRIMARY KEY( one or more columns )
);
Example :
create table emp(
empno number(4,0),
ename varchar2(10),
job varchar2(9),
mgr number(4,0),
hiredate date,
sal number(7,2),
deptno number(2,0)
PRIMARY KEY (ID)
);
Creating a new table from an existing Table :
We can create a new table with exactly the same structure of any of the existing tables
Here an empty table with exactly the same structure of the existing table is created but data and constraints of the table are not copied
create table
sample as (select * from emp);
ALTER table :
It is used to add columns, delete columns, drop constraints, renaming the columns, changing the data type and data type size of the column existing in the table.
ALTER TABLE table_name ADD(column_name datatype);
Example :
ALTER TABLE student ADD(address VARCHAR(100));
ALTER table :
It is used to add columns, delete columns, drop constraints, renaming the columns, changing the data type and data type size of the column existing in the table.
ALTER TABLE table_name ADD(column_name datatype);
Example :
ALTER TABLE student ADD(address VARCHAR(100));