DML Commands in SQLDML is an abbreviation of Data Manipulation Language. The DML commands in Structured Query Language change the data present in the SQL database. We can easily access, store, modify, update and delete the existing records from the database using DML commands. Following are the four main DML commands in SQL:
SELECT DML CommandSELECT is the most important data manipulation command in Structured Query Language. The SELECT command shows the records of the specified table. It also shows the particular record of a particular column by using the WHERE clause. Syntax of SELECT DML command Here, column_Name_1, column_Name_2, ….., column_Name_N are the names of those columns whose data we want to retrieve from the table. If we want to retrieve the data from all the columns of the table, we have to use the following SELECT command: Examples of SELECT CommandExample 1: This example shows all the values of every column from the table. This SQL statement displays the following values of the student table:
Example 2: This example shows all the values of a specific column from the table. This SELECT statement displays all the values of Emp_Salary and Emp_Id column of Employee table:
Example 3: This example describes how to use the WHERE clause with the SELECT DML command. Let's take the following Student table:
If you want to access all the records of those students whose marks is 80 from the above table, then you have to write the following DML command in SQL: The above SQL query shows the following table in result:
INSERT DML CommandINSERT is another most important data manipulation command in Structured Query Language, which allows users to insert data in database tables. Syntax of INSERT Command Examples of INSERT CommandExample 1: This example describes how to insert the record in the database table. Let's take the following student table, which consists of only 2 records of the student.
Suppose, you want to insert a new record into the student table. For this, you have to write the following DML INSERT command: UPDATE DML CommandUPDATE is another most important data manipulation command in Structured Query Language, which allows users to update or modify the existing data in database tables. Syntax of UPDATE Command Here, 'UPDATE', 'SET', and 'WHERE' are the SQL keywords, and 'Table_name' is the name of the table whose values you want to update. Examples of the UPDATE commandExample 1: This example describes how to update the value of a single field. Let's take a Product table consisting of the following records:
Suppose, you want to update the Product_Price of the product whose Product_Id is P102. To do this, you have to write the following DML UPDATE command: Example 2: This example describes how to update the value of multiple fields of the database table. Let's take a Student table consisting of the following records:
Suppose, you want to update Stu_Marks and Stu_Age of that student whose Stu_Id is 103 and 202. To do this, you have to write the following DML Update command: DELETE DML CommandDELETE is a DML command which allows SQL users to remove single or multiple existing records from the database tables. This command of Data Manipulation Language does not delete the stored data permanently from the database. We use the WHERE clause with the DELETE command to select specific rows from the table. Syntax of DELETE Command Examples of DELETE CommandExample 1: This example describes how to delete a single record from the table. Let's take a Product table consisting of the following records:
Suppose, you want to delete that product from the Product table whose Product_Id is P203. To do this, you have to write the following DML DELETE command: Example 2: This example describes how to delete the multiple records or rows from the database table. Let's take a Student table consisting of the following records:
Suppose, you want to delete the record of those students whose Marks is greater than 70. To do this, you have to write the following DML Update command:
Next TopicSQL CASE
|