Data Manipulation Language (DML)
Data Manipulation Language (or simply DML) consists of SQL commands that handle data maintenance functions. This means that you can manipulate the data contained within the relational database objects. The command statements, which read like normal English sentences, will allow you to enter, change, remove or retrieve data. The following are the DML statements commonly used:
INSERT
This command statement is used to insert new data values into a certain table. To add values to a table with two columns, use the following syntax:
INSERT INTO TABLE_NAME VALUES (‘value1’, ‘value2’); TABLE_NAME
INSERT INTO orderDetails(id, customer_id, order_date, product, quantity, unit_price)
VALUES
(102, 10041 ,'2015-11-10', 'Product 1', 6 ,18);
UPDATE
This command statement is used to modify or alter-existing data values in a table, not add or remove records. The update is done one table at a time or multiple rows/columns of one table within a database. To change a single column, use the
following syntax:
UPDATE TABLE_NAME SET COLUMN_NAME = ‘value’ [WHERE CONDITION];
UPDATE orderDetails
SET quantity = 6
WHERE customer_id = 10041
AND product = 'Product 1'
;
As long as the given WHERE clause is satisfied, then the value of the COLUMN_NAME will be updated. This could be within one or multiple records of the given TABLE_NAME
DELETE
This command statement deletes certain records or even the entire table, not data values from specific columns. To remove a single row or multiple records from a table, use the following syntax:
DELETE FROM TABLE_NAME [WHERE CONDITION]
DELETE orderDetails
WHERE customer_id = 10041
AND id = 102
;
The WHERE clause is an important part of this command if you want to delete
selected rows from the TABLE_NAME.
Subscribe to my newsletter
Read articles from Rukayat Balogun directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by