Page 297 - Trackpad 402_Class-X_Final
P. 297
Types of SQL Commands
SQL commands are broadly classified into the given categories:
• Data Definition Language (DDL) commands
• Data Manipulation Language (DML) commands
Data Definition Language (DDL)
The SQL-DDL contains a set of commands that allows the users to make changes in the structure of the table like:
• Creating a new data definition using CREATE
• Adding, updating, removing the data definition using ALTER
• Deleting the data definition from the database using DROP.
Syntax to create a new table in the database using SQL is as follows:
CREATE TABLE <Table Name>
(<Column Name1> <Data Type>,<Column Name2> <Data Type>,
... <Column Name n> <Data Type>);
Example:
CREATE TABLE student (RollNo Integer, Name VARCHAR(20), Fees integer, DOB Date,
Marks integer);
The syntax to display the structure of the table is as follows:
DESCRIBE <Table Name> OR Desc <Table Name>
For example,
DESC STUDENT;
OR
DESCRIBE STUDENT;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| RollNo | int | YES | | NULL | |
| Name | varchar(20) | YES | | NULL | |
| Fees | int | YES | | NULL | |
| DOB | date | YES | | NULL | |
| Marks | int | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
The syntax to add a new column(s) in the table is as follows:
ALTER TABLE <Table Name>
ADD (<Column Name1> <Data Type>,<Column Name2> <Data Type>,
... <Column Name n> <Data Type>);
For examples,
ALTER TABLE student ADD (ClassSec VARCHAR(30));
Database Management System 297

