Oracle Commands
Oracle Commands
DDL:
CREATE
ALTER
DROP
TRUNCATE
CREATE:
The create table command defines each column of the table uniquely. Each column has
minimum of three attributes.
Name
Data type
o Char-Fixed length datatype ,it accepts only char
o Varchar()-
It is variable length character of data . it will occupy space for NULL values.It can store up
to 2000 bytes of characters. Varchar stores alphanumeric values without padding the
unused memory locations.
o Varchar2()- can store up to 4000 bytes of characters. it will not occupy any space .
Varchar2 is also used to store alphanumeric values with padding the unused memory
locations by using varchar2 we are saving the memory locations.
Size(column width).
Each table column definition is a single clause in the create table syntax. Each table
column definition is separated from the other by a comma. Finally, the statement is terminated
with a semicolon.
Examples:
CREATE TABLE Student
(Reg_no varchar2(10),
Name char(30),
DOB date,
Address varchar2(50));
Syntax:
DROP TABLE <table_name>
Example:
DROP TABLE Student;
It will destroy the table and all data which will be recorded in it.
Syntax:
TRUNCATE TABLE <Table_name>
Example:
TRUNCATE TABLE Student;
Syntax:
RENAME <OldTableName> TO <NewTableName>
Example:
RENAME <Student> TO <Stu>
The old name table was Student now new name is the Stu.
By The use of ALTER TABLE Command we can modify our exiting table.
Syntax:
ALTER TABLE <table_name>
ADD (<Column_Name> <Data_Type>(<size>),......n)
Example:
ALTER TABLE Student ADD (Age number(2), Marks number(3));
The Student table is already exist and then we added two more columns Age and Marks
respectively, by the use of above command.
Dropping a Column from the Table
Syntax:
ALTER TABLE <table_name> DROP COLUMN <column_name>
Example:
ALTER TABLE Student DROP COLUMN Age;
This command will drop particular column
Syntax:
ALTER TABLE <table_name> MODIFY (<column_name>
<NewDataType>(<NewSize>))
Example:
ALTER TABLE Student MODIFY (Name Varchar2(40));
The Name column already exist in Student table, it was char and size 30, now it is modified by
Varchar2 and size 40.