DML (Data Manipulation Language) : Heba Nsour 2020
DML (Data Manipulation Language) : Heba Nsour 2020
The SQL commands that deals with the manipulation of data present in the
database belong to DML or Data Manipulation Language and this includes most of
the SQL statements.
Examples of DML:
INSERT – is used to insert data into a table.
UPDATE – is used to update existing data within a table.
DELETE – is used to delete records from a database table.
we will specify both the columns which we want to fill and their
corresponding values as shown below:
Syntax :
INSERT INTO table_name (column1, column2, column3,..) VALUES
( value1, value2, value3,..);
table_name: name of the table.
column1: name of first column, second column …
value1, value2, value3 : value of first column, second column,… for the new
record
Notice that the columns for which the values are not provided are
filled
Heba Nsour 2020 by null. Which is the default values for those columns.
Using SELECT in INSERT INTO Statement
We can use the SELECT statement with INSERT INTO statement to copy rows
from one table and insert them into another table. The use of this statement
is similar to that of INSERT INTO statement. The difference is that the SELECT
statement is used here to select data from a different table. The different
ways of using INSERT INTO SELECT statement are shown below:
Inserting all columns of a table: We can copy all the data of a table and insert into in a
different table.
We have used the SELECT statement to copy the data from one table and INSERT INTO
statement to insert in a different table.
Inserting specific columns of a table: We can copy only those columns of a table which we
want to insert into in a different table.
Syntax:
INSERT INTO first_table(names_of_columns1) SELECT names_of_columns2 FROM second_table;
first_table: name of first table.
second_table: name of second table.
names of columns1: name of columns separated by comma(,) for table 1.
names of columns2: name of columns separated by comma(,) for table 2.
We have used the SELECT statement to copy the data of the selected columns only from
the second table and INSERT INTO statement to insert in first table.
3 Sarah UK 25301487 20
Output:
This query will insert all the data of the table Lateral Student in the table
Student. The table Student will now look like,
Roll-NO NAME ADDRESS PHONE Age
3 Sarah UK 25301487 20
3 Sarah UK 25301487 20
Basic Syntax
UPDATE table_name SET column1 = value1, column2 = value2,...
WHERE condition;
NOTE: In the above query the SET statement is used to set new values to the particular column and the WHERE clause is used to
select the rows for which the columns are needed to be updated. If we have not used the WHERE clause then the columns in all the
rows will be updated. So the WHERE clause is used to choose the particular rows.
3 Sarah UK 25301487 20
3 Tala UK 25301487 20
3 Tala UK 25301487 20
columns.
Note
Omitting WHERE clause: If we omit the WHERE clause from the update query
then all of the rows will get updated.
The DELETE Statement in SQL is used to delete existing records from a table. We can
delete a single record or multiple records depending on the condition we specify in the
WHERE clause.
Basic Syntax:
DELETE FROM table_name WHERE some_condition;
Deleting single record: Delete the rows where NAME = ‘Ram’. This will delete
only the first row.
3 Sarah UK 25301487 20
3 Sarah UK 25301487 20
3 Sarah UK 25301487 20