DML (Data Manipulation Language)

DML (Data Manipulation Language) commands are used to interact with and modify data within existing database tables. These commands allows to insert new data, update existing data, delete unwanted data, and perform bulk operations for efficiency.

INSERT

Adds new rows of data to a table.

  • Syntax

INSERT INTO [schema_name.]table_name ([column_list]) VALUES ([value_list]);
  • Example

INSERT INTO Customers (CustomerID, CustomerName, Email, Phone) VALUES (1001, 'John Smith', '[email protected]', '123-456-7890');

UPDATE

Modifies existing data in a table based on a specific criteria (WHERE clause).

  • Syntax

UPDATE [schema_table.]table_name SET [column_name] = new_value [, ...] WHERE condition;
  • Example

UPDATE Customers SET Email = '[email protected]' WHERE CustomerID = 1002;

DELETE

Removes rows of data from a table based on a specific criteria (WHERE clause).

  • Syntax

  • Example

MERGE

The MERGE statement is used to perform an "upsert" operation, which means inserting new rows into a table or updating existing rows based on specified conditions

  • Syntax

  • Example Suppose we have two tables: employees and employees_updates. The employees table contains the current employee data, and the employees_updates table contains updates to be applied to the employees table. We will use the MERGE statement to update the employees table with the data from the employees_updates table.

CALL

Executes a stored procedure or function in the database.

  • Syntax

  • Example

EXPLAIN PLAN

Analyzes and displays the execution plan for a SQL statement, providing insights into how the database will retrieve data.

  • Syntax

  • Example

LOCK TABLE

Explicitly locks a table or specific rows to prevent other users from modifying the data concurrently. We can release a table lock implicitly by committing or rolling back the transaction

  • Syntax

  • Example

Last updated