SQL Data Manipulation Language (DML)

Introduction to DML

  • DML stands for Data Manipulation Language.
  • It is a language used for selecting, inserting, deleting and updating data in a database.
  • It is used to retrieve and manipulate data in a relational database.
  • DDL commands are as follows,
    1. SELECT
    2. INSERT
    3. UPDATE
    4. DELETE
  • DML performs read-only queries of data.

1. SELECT COMMAND

  • SELECT command is used to retrieve data from the database.
  • This command allows database users to retrieve the specific information they desire from an operational database.
  • It returns a result set of records from one or more tables.
SELECT Command has many optional clauses are as stated below:

ClauseDescription
WHEREIt specifies which rows to retrieve.
GROUP BYIt is used to arrange the data into groups.
HAVINGIt selects among the groups defined by the GROUP BY clause.
ORDER BYIt specifies an order in which to return the rows.
ASIt provides an alias which can be used to temporarily rename tables or columns.

Syntax:
SELECT * FROM <table_name>;

Example : SELECT Command

SELECT * FROM employee;

OR

SELECT * FROM employee
where salary >=10,000;

2. INSERT COMMAND

  • INSERT command is used for inserting a data into a table.
  • Using this command, you can add one or more records to any single table in a database.
  • It is also used to add records to an existing code.
Syntax:
INSERT INTO <table_name> (`column_name1` <datatype>, `column_name2` <datatype>, . . . , `column_name_n` <database>) VALUES (`value1`, `value2`, . . . , `value n`);

Example:
INSERT INTO employee (`eid` int, `ename` varchar(20), `city` varchar(20))
VALUES (`1`, `ABC`, `PUNE`);

3. UPDATE COMMAND

  • UPDATE command is used to modify the records present in existing table.
  • This command updates existing data within a table.
  • It changes the data of one or more records in a table.
Syntax:
UPDATE <table_name>
SET <column_name = value>
WHERE condition;

Example : UPDATE Command

UPDATE employee
SET salary=20000
WHERE ename='ABC';

4. DELETE COMMAND

  • DELETE command is used to delete some or all records from the existing table.
  • It deletes all the records from a table.

  • Syntax:
    DELETE FROM <table_name> WHERE <condition>;

    Example : DELETE Command

    DELETE FROM employee
    WHERE emp_id = '001';


    If we does not write the WHERE condition, then all rows will get deleted.