SQL 2 B
SQL 2 B
DML Statements
• The SQL commands that deal with the manipulation of data present in
the database belong to DML or Data Manipulation Language.
• The manipulation of data includes following operations like storing,
modifying, retrieving, deleting, and updating data in a database.
• DML commands are used to modify the database. It is responsible for
all form of changes in the database.
• The command of DML is not auto-committed that means it can't
permanently save all the changes in the database. They can be
rollback.
SQL DML Statement
• Insert statement is used to add tuples (records) to table It supports three alternate syntax as shown
below:
• If column names are not used, then values must be provided for all columns in the order of their
specification during table creation. If Column names are used then the data provided in values clause
must have same data type of column at same position. Multiple rows can be inserted through a single
INSERT statement only when it is used with SELECT statement.
The SQL INSERT INTO Statement
• The SQL INSERT INTO Statement is used to add new rows(tuples)of data to a table
in the database.
• It is possible to write the INSERT INTO statement in two ways:
1. Specify both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
2. If you are adding values for all the columns of the table, you do not need to specify
the column names in the SQL query. However, make sure the order of the values is in
the same order as the columns in the table. Here, the INSERT INTO syntax would be
as follows:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
INSERT INTO Statement Example
• We can populate the data into a table through the select statement over
another table; provided the other table has a set of fields, which are
required to populate the first table.
INSERT INTO first_table_name [(column1, column2, ... columnN)]
SELECT column1, column2, ...columnN
FROM second_table_name
[WHERE condition];
The SQL UPDATE Statement
• The SQL DELETE Query is used to delete the existing records from a
table.
• We can use the WHERE clause with a DELETE query to delete the
selected rows, otherwise all the records would be deleted.
• We can delete a single record or multiple records depending on the
condition we specify in the WHERE clause.
• Syntax The basic syntax of the DELETE query with the WHERE
clause is as follows:
DELETE FROM table_name
WHERE [condition];
DELETE STATEMENT
• The database system ensures that no constraints are violated during execution of a
delete statement. Any violation of constraints results in failure of the statement.