Page 344 - TP_IT_V1.0_C10_flipbpookl
P. 344
FOR ADVANCED LEARNERS
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));
The syntax to delete a table (data as well as the structure) is as follows:
DROP TABLE <Table Name>;
For example,
DROP TABLE Student;
DML (Data Manipulation Language)
DML is a language that enables users to access or manipulate data. By data manipulation, we mean:
• The retrieval of information stored in the table, using SELECT
• The insertion of new row with information into the table, using INSERT
342 Trackpad Information Technology (Ver. 1.0)-X

