Blog is developed for free online learning of Oracle Applications, SQL, PLSQL

Learning SQL Tables


SQL Tables: -


After learning types of SQLstatements in my last post, Now we will learn about SQL Tables,

Table is a database object which holds the data and contains one or more
columns associated with its datatypes
Table Structure
Table Structure

Creating a Table: we use the create table statement to create a table. The simple
syntax for the creation of table.
Syntax: CREATE Table table_name
(column_name type [CONSTRAINT constraint_def DEFAULT default_exp],
column_name type [CONSTRAINT constraint_def DEFAULT default_exp],
column_name type [CONSTRAINT constraint_def DEFAULT default_exp]…
)
[ON COMMIT {DELETE | PRESERVE} ROWS]
TABLESPACE tab_space;
Ex: SQL> Create table chaitu_0016(ename varchar2(10),
Eno number unique);
Table Created.
Altering a Table: we can alter the table using the alter statement. The alter table
statement perform such tasks given below.
_ Add, modify, or drop a column.
_ Add or drop a constraint.
_ Enable or Disable a constraint.
Ex: SQL> Alter table chaitu_0016
Add address varchar2(10);
Modifying a Column:
Ex: SQL> Alter table chaitu_0016
Modify address varchar2(20);
Dropping a Column:
Ex: SQL> Alter table chaitu_0016
Drop address;
Renaming a Table: If we want to change the name of the table then we use this
RENAME statement.
Ex: SQL> Rename table chaitu_0016
To
Chaitu_0015;
Truncating a Table: If we want to delete all the rows existing in the table then we use
the TRUNCATE Statement.
Ex: SQL> Truncate table chaitu_0015;
Dropping a Table: If we want to drop the total structure along with the records existing
in the table we use this DROP statement.
Ex: SQL> Drop table chaitu_0015;

Thanks a lot for reading.. Happy Blogging!