DML (Data Manipulation Language)
DML stands for Data Manipulation Language, which means that these commands are used to manipulate the data in a database. There are four main DML commands in SQL: SELECT
, INSERT
, UPDATE
, and DELETE
.
Let's take a look for each Command. We will Learn More details in Next Chapter.
- SELECT
The SELECT
command is used to retrieve data from a database. This command allows you to specify the table or tables you want to retrieve data from, as well as the columns you want to retrieve. You can also add conditions to the SELECT
statement to filter the results. For example, if you have a table called "employees" and you want to retrieve the names and salaries of all employees who earn more than $50,000 per year, you would use the following SELECT
statement:
SELECT name, salary FROM employees WHERE salary > 50000;
This command would retrieve the names and salaries of all employees who earn more than $50,000 per year from the "employees" table.
- INSERT
The INSERT
command is used to add new data to a database. This command allows you to specify the table you want to add data to, as well as the values you want to add. For example, if you have a table called "employees" and you want to add a new employee named John Smith who earns $60,000 per year, you would use the following INSERT
statement:
INSERT INTO employees (name, salary) VALUES ('John Smith', 60000);
This command would add a new row to the "employees" table with the name "John Smith" and the salary of $60,000.
- UPDATE
The UPDATE
command is used to modify existing data in a database. This command allows you to specify the table you want to modify, as well as the columns you want to modify and the new values you want to set. You can also add conditions to the UPDATE
statement to filter the rows you want to modify. For example, if you have a table called "employees" and you want to give a 10% raise to all employees who earn less than $50,000 per year, you would use the following UPDATE
statement:
UPDATE employees SET salary = salary * 1.1 WHERE salary < 50000;
This command would increase the salary of all employees who earn less than $50,000 per year by 10%.
- DELETE
The DELETE
command is used to remove data from a database. This command allows you to specify the table you want to remove data from, as well as the conditions you want to use to filter the rows you want to remove. For example, if you have a table called "employees" and you want to remove all employees who earn less than $30,000 per year, you would use the following DELETE
statement:
DELETE FROM employees WHERE salary < 30000;
This command would remove all rows from the "employees" table where the salary is less than $30,000 per year.
In summary, DML commands are used to manipulate the data in a database. The four main DML commands in SQL are SELECT
, INSERT
, UPDATE
, and DELETE
. The SELECT command is used to retrieve data from a database, the INSERT command is used to add new data to a database, the UPDATE command is used to modify existing data in a database, and the DELETE command is used to remove data from a database.