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

Lesson 8: Data Manipulation Language (DML)

This document discusses data manipulation language (DML) commands in SQL. It covers the INSERT statement which adds new rows to a table, either with explicit values or by copying rows from another table. It also covers the UPDATE statement which modifies existing rows in a table, allowing updates to multiple columns at once or using values from a subquery. Both statements are demonstrated with syntax examples for inserting and updating data in database tables.

Uploaded by

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

Lesson 8: Data Manipulation Language (DML)

This document discusses data manipulation language (DML) commands in SQL. It covers the INSERT statement which adds new rows to a table, either with explicit values or by copying rows from another table. It also covers the UPDATE statement which modifies existing rows in a table, allowing updates to multiple columns at once or using values from a subquery. Both statements are demonstrated with syntax examples for inserting and updating data in database tables.

Uploaded by

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

LESSON 8

Data
Manipulation
Language
(DML)
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
INSERTION:

 INSERT statement add new rows to the table.


 Only one row is inserted in a row.

SYNTAX:

INSERT INTO table [(column, coulmn,…)] VALUES


(values,values,….);

Example:

INSERT INTO emp (empno,ename,sal,deptno,hiredate)


VALUES (105,’ADNAN’,4000,20,’22-JUN-03’);

DBT BSSE-A-F12
DBT BSSE-A-F12
INSERTING NULL VALUES:

1) IMPLICIT METHOD:
Omit the column from the column list

Example:
 INSERT INTO dept (deptno,dname) VALUES (50,’IT’);
 INSERT INTO dept VALUES (50,’IT’);

2) EXPLICIT METHOD:
Specify the NULL keyword or the empty string ‘’in the values
list.

Example:
INSERT INTO dept VALUES (50,’IT’, NULL);
DBT BSSE-A-F12
INSERTING DATES:

1) INSERT INTO emp (empno,ename,deptno,hiredate)


VALUES (105,’KAMRAN’,30,SYSDATE);

2) INSERT INTO emp (empno,ename,deptno,hiredate)


VALUES (105,’KAMRAN’,30,’09-OCT-03’);

3) INSERT INTO emp (empno,ename,deptno,hiredate)


VALUES (105,’KAMRAN’,30,to_date(‘OCT 09, 2003’,’MON
dd,yyyy’));

DBT BSSE-A-F12
INSERTING VALUES BY SUBSTITUTION VARIABLES:

1) INSERT INTO emp (empno,&col,deptno,hiredate)


VALUES (105,’&value’,30,’09-OCT-03’);

2) ACCEPT col PROMPT ‘Enter column name? ‘


ACCEPT val PROMPT ‘Enter value for column? ‘
INSERT INTO emp (empno,&col,deptno,hiredate)
VALUES (105,’&val’,30,’09-OCT-03’);

DBT BSSE-A-F12
COPYINGS ROW FROM ANOTHER TABLE:

 Write your INSERT statement with a subquery.


 Do not use the VALUES clause.
 Match the number of columns in the INSERT clause to
those in the subquery.

Example:

INSERT INTO employee(id, name, salary)


SELECT empno, ename, sal FROM emp WHERE job =‘CLERK’;

DBT BSSE-A-F12
UPDATION:

Modify existing rows with the UPDATE statement.


More than one rows can be modified.
Specify row or rows are modified when you specify the WHERE
clause.
All the rows in the table are modified if you omit the WHERE clause.

SYNTAX:

UPDATE table SET column = value [, column = value, ….]


[WHERE condition];

EXAMPLE:

UPDATE emp SET sal = 7000 WHERE empno = 103;


UPDATE emp SET ename = ‘ZAHID’, sal = 7000 WHERE empno =103;

DBT BSSE-A-F12
DBT BSSE-A-F12
UPDATING WITH MULTIPLE COLUMN SUBQUERY:

EXAMPLE:

UPDATE emp
SET (ename,sal) = (SELECT ename,sal FROM
emp where empno = 103)
WHERE empno = 2241;

DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12

You might also like