SQL Data Manipulation Language

tutorial and example
tutorial and example

Data Manipulation Language manipulates/make changes in data present in a table.

It only affects data/records of table, not on the schema/structure of table.

 

INSERT, UPDATE, DELETE are the commands of DML.

INSERT: Stores data in a table or creates new records by inserting values.

UPDATE: It modifies the record in a table.

DELETE: Deletes on or more records from table.

Syntax:

  1. INSERT INTO table_name VALUES ( value1,value2,….);
  2. INSERT INTO table_name (column 1,column 2, column 3) VALUES (value1, value2,value3);

Example:

  1. INSERT INTO

STUDENT

VALUES (0001,’ARUN’,’CS’,’FIRST’);

  1. INSERT INTO

STUDENT (classyear, student_name,student_dept,student_id)

VALUES (‘FIRST’,’VRUN’,’CS’,0002);

Here, user can change the sequence of columns while inserting values in table. We can increase or decrease number of columns.

Syntax:

DELETE

FROM Table_name

[WHERE Condition];

Example:

  1. Delete

From Student

Where Student_id=06;

Here, Single row is deleted as per where condition.

  1. Delete

From Student

Where Student_name=’ARYA’;

Multiple rows deleted, as three rows were present with the same name ARYA. Here, where condition decides how many records to delete.

  1. Delete

From Student;

In the above query, where condition is not specified so, all records are deleted from STUDENT table. If user want to delete single or multiple records then where condition is required. Delete query without where condition deletes all records from table.

Syntax:

UPDATE

Table_name

set column_name = value

[Where condition];

Example:

  1. update

student

set student_dept=’ele’

where student_name=’GITA’;

 

  1. UPDATE

Student

SET classyear=’FINAL’

Where student_id=9;

By using UPDATE command, user can update single value or multiple values in the table.

To change single value/to change specific value, ‘Where’ condition is required.

UPDATE without where condition changes complete column values in the table.

UPDATE

STUDENT

SET student_dept=’EXTC’;