logo

SQL: Data Manipulation Language (DML)

Data Manipulation Language (DML) commands are used for accessing and manipulating the data stored in the database. The DML commands are not auto-committed, meaning they do not permanently save all the changes in the database until they are explicitly committed. These changes can be rolled back if needed.

DDL Commands are used to define the structure and schema of the database.

⇒ All the commands of DDL are auto-committed, meaning they permanently save all the changes in the database.

DML Commands

1.SELECT - to retrieve data from the database.

2.INSERT - to insert a new row into a table.

3.UPDATE - to update an existing row in a table.

4.DELETE - to delete a row from a table.

1. SELECT (Most Commonly Used SQL Command)

The SELECT statement is used to select a set of data from a database table. It retrieves data and returns it in the form of a result table, also known as a result-set. The SELECT statement specifies column names, and the FROM clause specifies the table name. SELECT is also referred to as Data Query Language (DQL) because it is used to query information from a database table. The SELECT command is used with different conditions and clauses.

SQL SELECT Syntax Example Table SQL SELECT Example

WHERE Clause

The WHERE clause is used to select particular records based on a condition. It is used to filter records. The WHERE clause can be used in SELECT, UPDATE, and DELETE statements to specify a condition while fetching data from a single table or by joining multiple tables.

SQL WHERE Clause

Basic Query Structure

SQL is based on set and relational operations with certain modifications and enhancements. A typical SQL query has the following form:

A1, A2, ..., An represent attributes (columns).

r1, r2, ..., rm represent relations (tables).

P is a predicate (condition).

This SQL query is equivalent to the relational algebra expression. The result of an SQL query is a relation (table).

Optional Clauses in SELECT Statement

WHERE Clause: Specifies which rows to retrieve by specifying conditions.

GROUP BY Clause: Groups rows that share a property so that an aggregate function can be applied to each group.

HAVING Clause: Selects among the groups defined by the GROUP BY clause by specifying conditions.

ORDER BY Clause: Specifies an order in which to return the rows.

DISTINCT Clause: Removes duplicates from the result set of a SELECT statement. (SELECT DISTINCT)

SQL Operators

I.SQL Arithmetic Operators

SQL Arithmetic Operators

II.SQL Comparison Operators

SQL Comparison Operators

III.SQL Logical Operators

SQL Logical Operators

IV.SQL Special Operators

SQLSpecial Operators

2.INSERT

The INSERT INTO statement is used to insert new records into a table. It can be written in two ways:

1.Specifying the column names:

2.Without specifying column names (values should be in the same order as the columns in the table):

SQL INSERT Syntax SQL INSERT Example

3.UPDATE

The UPDATE statement is used to update existing records in a table. The syntax is:

UPDATE Syntax In SQL UPDATE Table Example in SQL

4.DELETE

The DELETE statement is used to delete existing records in a table. It is important to use the WHERE clause with a DELETE statement to delete the selected rows; otherwise, all the records in the table would be deleted. The syntax is:

DELETE Syntax In SQL DELETE Example In SQL
Next ❯ ❮ Previous
discription of faastop website
logo