You are on page 1of 4

Experiment 5: Practicing DML commands

The structured query language (SQL) commands deal with the manipulation of data present in the database
that belongs to the DML or Data Manipulation Language. This includes most of the SQL statements.

Examples of DML
The examples of DML in the Database Management System (DBMS) are as follows −
 SELECT − Retrieve data from the database.
 INSERT − Insert data into a table.
 UPDATE − Update existing data within a table.
 DELETE − Delete records from a database table.
DML Commands

1) INSERT: It is used to insert a row (or) record in to a table.

a) Syntax for Inserting values in to all columns:

Syntax: INSERT INTO tablename VALUES (Data or values);


Example: Insertion of values into BUS table.
> insert into BUS values ('B120', 'HYD’, 'DELHI’);
> insert into BUS values ('B121', 'HYD’, 'KOLKATA’);
> insert into BUS values ('B122', 'HYD’, 'CHENNAI’);
> insert into BUS values ('B123', 'DELHI’, 'CHENNAI’);

b) Syntax for Inserting values in to specified columns:


Syntax: INSERT INTO tablename (column name’s) VALUES (Data or values) ;
Example: > INSERT INTO BUS (busno, source) VALUES ('B124', 'DELHI’);

c) Syntax for Inserting multiple rows in to the table (RUN TIME):


Syntax: INSERT INTO tablename VALUES (&columnname1, &columnname2,..........);
Example: > INSERT INTO BUS VALUES (‘&busno’, ‘&source’, ‘&destination’);
Enter the value of busno: B125
Enter the value of source: VIZAG
Enter the value of destination: HYD
1 row updated.
MYSQL> / (To repeat the process)

2) UPDATE: It is used to modify the contents present in the table.

a) Syntax for Updating all the rows of a table:


Syntax: UPDATE tablename SET columnname = expression;
Example: > UPDATE BUS SET source = ‘HYD’;
Note: The above syntax updates all the records of a table. i.e., all the values of SOURCE are
updated to HYD.

b) Syntax for Updating specified rows of a table:

Syntax: UPDATE tablename SET columnname=expression WHERE <condition>;

Example: > UPDATE BUS SET Source= ‘VIZAG’ WHERE busno = ‘B123’;
3) DELETE: It is used to delete (or) remove the records of a table.

a) Syntax for Deleting all the records of a table:

Syntax: DELETE

FROM tablename;

Example: >

DELETE FROM

bus;
b) Syntax for Deleting specified records of a table:

Syntax: DELETE FROM tablename WHERE

<condition>; Example: > DELETE FROM

bus WHERE busno = ‘B125’;

4) TRUNCATE: It is a DDL command. It is also used to delete (or) remove


the records of a table. Truncate deletes the contents permanently.
Syntax: TRUNCATE TABLE tablename;

NOTE: DML statements are NON-AUTO COMMIT. Means we have to save


the data. i.e., whenever DML statements are executed it won’t save the data in to
data base. By executing COMMIT statement we have to manually save the data.

5) SELECT: It Used to Retrieve or Search or Filter the data from


Data Base table(s). SYNTAX: SELECT * {[DISTINCT]
(column(s)), Expressions, aliases} from
<Table name>
[Where condition(s)]; NOTE: SELECT
statement is CASE IN SENSITIVE.
Ex: SeLecT (we can write this way also).
a) Syntax to retrieve all the records from the table:

Example: > SELECT * from BUS;


BUSNO SOURCE DESTINATION

b120 hyd delhi


b121 hyd kolkata
b122 hyd chennai
b) Syntax to retrieve specified columns from the table:
Example: > SELECT busno,
source from BUS;
BUSNO

SOURCE
b120 hyd
b121 hyd
b122 hyd
c) Syntax to retrieve specified columns with specified records:

Example: > SELECT busno, source from BUS


where busno=’b120’; BUSNO
SOURCE
b120 hyd

You might also like