Table Commands


☞ Following are the topics to be covered :

 
1. Creating a Table 
2. Viewing a Table Structure
3. Viewing a Table
4. Removing a Table

Creating a Table

☞ To create a table in RDBMS, we use CREATE TABLE command.

Syntax :

CREATE TABLE <database_name>
(
<col1 > <type1>(size),
<col2 > <type2>(size),
<col3 > <type3>(size),
.......
)
;

Example :

CREATE TABLE student
(
Rollno INTEGER NOT NULL PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Gender CHAR(1),
DOB DATE,
Fees DECIMAL(8,2)
)
;

OR

CREATE TABLE student
(
Rollno INTEGER NOT NULL,
Name VARCHAR(50) NOT NULL,
Gender CHAR(1),
DOB DATE,
Fees DECIMAL(8,2),
PRIMARY KEY(Rollno)
)
;

Viewing a Table Structure

☞ To view a table structure in RDBMS, we use DESCRIBE / DESC command.

Syntax :

DESCRIBE <table_name> ;

OR

DESC <table_name> ;

Example :

DESCRIBE student ;

OR

DESC student ;

Viewing a Table

☞ To verify that the table is created in RDBMS, we use SHOW TABLES command.

Syntax :

SHOW TABLES ;

Example :

SHOW TABLES ;

Removing a Table

☞ To permanently remove a table which is not in use from RDBMS, we use DROP TABLE command.

Syntax :

DROP TABLE <table_name> ;

Example :

DROP TABLE student ;