- DDL commands used for design or defines database.
- in DDL create,alter,truncate,drop commands include.
CRATE
- crate command used to create a table in database.
- syntax
(
<column 1> <datatype> (<size>),
<column 2> <datatype> (<size>),
);
- Example
(
id number(6),
name varchar2(30),
phone number(10)
);
ALTER
- Alter command used modify structures of a table.
- Alter command used add ,modify, or drop table columns in a table.
- syntax
- Adding New Columns
ALTER TABLE <tablename>
Add (NewColumnName Datatype(size),
NewColumnName Datatype(size)….);
EXAMPLE
ALTER TABLE student ADD(address varchar2(100));
MODIFY (ColumnName NewDatatype(NewSize));
Add (NewColumnName Datatype(size),
NewColumnName Datatype(size)….);
EXAMPLE
ALTER TABLE student ADD(address varchar2(100));
- Modifying Existing Columns
MODIFY (ColumnName NewDatatype(NewSize));
EXAMPLE
ALTER TABLE student MODIFY(id number(10));
- Dropping(deleting) Existing Columns
ALTER TABLE <TableName> DROP COLUMN <columname>;
EXAMPLE
ALTER TABLE student DROP COLUMN phone
TRUNCATE TABLE
- TRUNCATE TABLE used to delete all data from a table.
- this command deletes all rows
- syntax
EXAMPLE
TRUNCATE TABLE student;
TRUNCATE TABLE student;
DROP TABLE
- DROP TABLE command is used to delete table from a database.
- syntax
EXAMPLE
DROP TABLE student;