Archive
DB Basics – Is SELECT a DML (Data Manipulation Language)?
DML or Data Manipulation Langauge as the term suggest represents those SQL statements that manipulates the data in a database. Thus these langauges allows users to INSERT, UPDATE & DELETE the data in a particular database. Other than this the much debatable SELECT statement may or may not be considered as DML upon its usage.
A simple SELECT statement which fetches data from a table is a read-only language and cannot be called as DML.
But a modified version of SELECT i.e. ‘SELECT INTO’ can fall into the DML segment. The ‘SELECT INTO’ can be used to create a Table and insert records fetched from the SELECT statement.
Also, we can manipulate the data for reporting purpose while retriving by using the SELECT statement. The data in underlying tables is unchanged but on the frontend you get a view of modified data, like:
USE [AdventureWorks] GO SELECT ContactID, Title, FirstName, MiddleName, LastName, FirstName + ' ' + ISNULL(MiddleName,'') + ' ' + LastName as [FullName] -- Name manipulated by joining 3 part names. FROM Person.Contact SELECT SalesOrderID, SalesOrderDetailID, OrderQty, UnitPrice, OrderQty * UnitPrice as [TotalPrice] -- Manipulated cost by calculating it for total items purchased. FROM Sales.SalesOrderDetail
Thus SELECT also comes under DML and following is the list of all DMLs:
1. SELECT {COLUMN LIST} [INTO {TABLE_NAME}] [WHERE {WHERE condition}]
2. INSERT INTO {TABLE_NAME} VALUES (SET of Values)
3. UPDATE {TABLE_NAME} SET [WHERE {WHERE condition}]
4. DELETE FROM {TABLE_NAME} [WHERE {WHERE condition}]