0% found this document useful (0 votes)
18 views2 pages

Insert, Delete & Update Operations

The document discusses SQL DML commands like INSERT, UPDATE, DELETE and provides examples of using them to manipulate data in tables A and B by inserting records, updating field values based on subqueries, deleting records based on subqueries, and setting a field to NULL then updating that NULL value.

Uploaded by

navinkumar7197
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Insert, Delete & Update Operations

The document discusses SQL DML commands like INSERT, UPDATE, DELETE and provides examples of using them to manipulate data in tables A and B by inserting records, updating field values based on subqueries, deleting records based on subqueries, and setting a field to NULL then updating that NULL value.

Uploaded by

navinkumar7197
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

DML - Data Manipulation Language

-- SQL commands that deals with the manipulation of data present in the database
belong to DML or Data Manipulation Language.
-- this includes various SQL Statements such as:

* 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 table.
*/

create or replace table A(id number,


name varchar(20));

create or replace table B(id number,


name varchar(20));

select * from A;
select * from B;

insert into A values(1,'Aman'),


(2,'Bhavesh'),
(3,'Carolyn'),
(5,'David');

insert into B values(4,'Fulos'),


(9,'Bhavesh'),
(1,'Shanaya'),
(2,'Bhavesh'),
(10,'Pawan');

insert into B (select * from A);

select * from B;

-- SUBQUERY in DELETE statement

delete from B
where name = (select
name from A
where name = 'Bhavesh');

select * from B;

-- SUBQUERY in UPDATE statement

insert into B values(4,'Fulos'),


(9,'Bhavesh'),
(1,'Shanaya'),
(2,'Bhavesh'),
(10,'Pawan');

select * from B;

update B
set name = 'Rohit'
where name in (select distinct name
from A
where name like 'B%');

select * from B;

insert into B values(1,NULL);

update B
set name = 'KASHISH'
where name is NULL;

-- be cautious while using UPDATE and DELETE operations - MAKE SURE TO USE WHERE
STATEMENT
update B
set name = 'XYZ';

You might also like