How to Create, Alter, AND Drop a table
CREATE TABLE: A table is the basic unit of storage. It is composed of rows and columns. To create a table we will name the table and the columns of the table. We follow the rules to name tables and columns:
• It must begin with a letter and can be up to 30 characters long.
• It must not be a duplicate and not any reserved word.
SYNTAX to create a table:
CREATE TABLE tablename (column_name1 datatype (size), column_name2 datatype (size) …);
Example:
CREATE TABLE studen(rollno number (4), name varchar2 (15));
ALTER TABLE: After creating a table one may need to change the table either by adding new columns or by modifying existing columns. One can do so by using the alter table command.
SYNTAX to add a column:
ALTER TABLE tablename ADD(col1 varchar(10),col2 number(10));
SYNTAX to modify a column:
ALTER TABLE tablename MODIFY(col1 datatype,col2 datatype);
DROP TABLE: To remove the definition of an oracle table, the drop table statement is used. The drop command is used to remove the structure of the table so no rollback is possible in this case.
SYNTAX to drop table:
DROP TABLE tablename;