How to Create, Alter AND Drop a table

How to Create, Alter AND Drop a table

CREATE TABLE: A table is 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 duplicate and not any reserved word.

SYNTAX to create a table is:

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 have need to change the table either by add new columns or by modify existing columns. One can do so by using alter table command.

SYNTAX to add a column is

ALTER TABLE tablename ADD(col1 varchar(10),col2 number(10));

SYNTAX to modify a column is:

ALTER TABLE tablename MODIFY(col1 datatype,col2 datatype);

DROP TABLE: To remove the definition of oracle table, the drop table statement is used.
Drop command is used to remove the structure of table so no rollback possible in this case.

SYNTAX to drop table is

DROP TABLE tablename

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s