0% found this document useful (0 votes)
14 views

SQL 2 B

Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

SQL 2 B

Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

InfyTq-DBMS

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

• Data Manipulation Language includes following SQL statements.


 select: select keyword in sql is used to retrieve data from a table.
 insert: insert or add data into a table.
 update: update the existing data in a table.
 delete: Delete all records from a database table.
 merge: It is a kind of insert or update operation.
 call: call statement is used to call a PL/SQL or any subprogram.
 explain plan: interpretation of the data access path.
 lock table: concurrency Control.
DML INSERT INTO

• 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

CustomerId CustomerName DOB Address Salary


101 John ‘1993-05-28’ 305 - 14th Ave. 48000.00
S. Suite 3B
102 Ramesh ‘1998-09-20’ Keskuskatu 45 65000.00
103 Chaitali ‘1998-08-20’ Mumbai 65000.00
Populate one table using another table

• 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

• Update statement is used to modify existing records in a single table in


a relational database.
• We can use the WHERE clause with the UPDATE query to update the
selected rows, otherwise all the rows would be affected.
• Syntax The basic syntax of the UPDATE query with a WHERE clause
is as follows:
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
UPDATE STATEMENT

• The database system ensures that no constraints are violated during


execution of an update statement. Any violation of constraints results
in failure of the statement.
UPDATE Statement Example
The SQL DELETE 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.

You might also like