Data Manipulation Language ( DML ) is the language used to maintain the database in a DMBS. The SQL (Structured Query Language) is the most popular language to manipulate databases.
DML Commands
The DML commands perform following tasks on a database.
- INSERT
- SELECT
- DELETE
- UPDATE
The SQL being a DML can do above task without any problem. Other than inserting, deleting or querying database, the SQL has advanced commands to change the schema of relations or create new relations.
It is used for maintaining the database and they are called Data Definition Language (DDL) commands. You can create table, delete a table and do other operations to maintain the structure of your database.
INSERT command
The INSERT command helps insert data into the relation. For example, you can insert values in the ‘MANAGER’ relation as follows.
The schema for Manager relation is given in the previous post about DDL commands.
SELECT command
The SELECT command helps query the database and retrieve the tuples from one or more relations.
There are two types of query – Selection(σ) and Projection(π).
Selection(σ)
This unary operator selects all the tuple in a relation that meet specific condition using normal conditional operators and logical operator such as AND, OR and NOT.
For example
, will return all the tuples that have an age greater than 30.
Projection(π)
This unary operator selects columns, but you can add selection with those retrieved columns.
For example
will return two column – age and salary.
Rename operator(ρ)
The rename operator will rename the existing field of a relation to a different specified name. Alter is a DDL command that modifies the relation name.
UPDATE command
The UPDATE command modifies the value for one or more tuple in the relation. In the following example, we have an updated salary of a manager whose salary is less than 20000.
The result of the update is as follows.
DELETE command
The DELETE will delete the tuple from the relation. Here is an example of DELETE.
The following figure shows the relation Manager after the delete operation. Note that one entry is already deleted successfully.
References
Ramakrishnan, Johannes Gehrke, and Raghu. 1996. Database Management Systems. McGraw Hill Education; Third edition (1 July 2014).
Wikipedia. n.d. Data definition language. Accessed March 14, 2018. https://en.wikipedia.org/wiki/Data_definition_language.