A short course "SQL Fundamentals - Oracle 11g" is being in progress at PMAS Arid Agriculture University. Complete course video and can be found at following link
https://www.youtube.com/playlist?list=PL12t8CWUhXZaUXsmg7M67o_Q37JhhfAKU
Data Manipulation(DML) and Transaction Control (TCL)
1. SQL Fundamentals
Oracle 11g
M U H A M M A D WA H E E D
O R AC L E D ATA BA S E D E V E LO P E R
E M A I L : m .wa h e e d 3 6 6 8 @ g m a i l . co m
.
1
Lecture#4
3. Question#1
Create doctor table (lisence no., name,
qualification,salary,contact no.,cnic,employee no.) using
column level constraints.
i- salary needs to be in currency format e.g 200000.00
ii- salary can’t be less than 10000
iii- employee no. is linked with employee table with same
field name.
3
5. Question#2
Create a table lawyer(lawyer no., name, no of cases, office address,
contact no) using column level as well as table level constraints where
necessary.
i- each lawyer must have a unique id
ii- each lawyer name is required
iii- no. of cases can not be zero
iii- each lawyer have either different contact number or none.
5
6. Solution#2
SQL>CREATE TABLE lawyer
2 (lawyer_no INT PRIMARY KEY,
3 name VARCHAR2(100) NOT NULL,
4 no_of_cases INT CHECK (no_of_cases>0),
5 office_address VARCHAR2(200),
6 contact_no INT
7 ,
8 CONSTRAINT lawyer_contact_uk UNIQUE(contact_no));
6
8. CRUD Operations (DML)
•CRUD represents an acronym for the database
operations Create, Read, Update, and Delete.
•Create (known as Insert)
•Read/Retrieve ( known as Select)
•Update (Update)
•Delete (Delete)
*Note: CRUD operations are effected by integrity
constraints.
8
9. Insert Statement
•We use following syntax:
•INSERT INTO <table_name> (<column1>,<column2>,….,<columnN>)
VALUES (<value1>,<value2>,….,<valueN>);
OR
•INSERT INTO <table_name>
VALUES (value1,value2,….);
OR
•INSERT ALL
INTO <table_name> VALUES(<column1>,<column2>,….,<columnN>)
INTO <table_name> VALUES(<column1>,<column2>,….,<columnN>)
INTO <table_name> VALUES(<column1>,<column2>,….,<columnN>)
SELECT * FROM DUAL;
9
10. SELECT Statement
•Syntax:
SELECT *|<column_name(s)> FROM <table_name>
[WHERE <condition>];
•Example:
SELECT * FROM student;
or
SELECT std_id,std_name FROM student;
or
SELECT * FROM student
WHERE dept_id=10;
10
12. Capabilities of SELECT
•Projection
a part of SQL statement after SELECT keyword is called “Projection” and
it refers to the consideration or elimination of columns.
•Selection
the part of SQL statement after WHERE keyword is called “Selection”
and it refers to the consideration or elimination of rows.
•In previous mentioned example “*” refers to projection and
“dept_id=10” refers to selection.
•Join
it is used to bring together data that is stored in different by creating a
link between them. You learn more about Joins in later lesson.
12
14. Line Size
•You can set the number of output lines to be displayed on output
screen.
•Syntax:
SET LINESIZE n;
n is the number of vertical lines to be displayed simultaneously on
screen.
14
16. UPDATE STATEMENT
•Modify existing records with UPDATE statement.
•Syntax:
UPDATE <table_name>
SET <column_name> = <column_value>, …….
[WHERE <condition>];
•Condition is optional part.
16
17. DELETE STATEMENT
•DELETE is used to either removing table contents or specific rows.
•Syntax:
DELETE FROM <table_name>
[WHERE <condition>];
17
18. Difference btw Delete & Truncate
Statement
•Delete is a DML command and Truncate is a DDL command.
•We can ROLLBACK the DELETE action but can't do for
truncate.
•Delete uses WHERE clause to delete specific rows while
truncate deletes whole table records.
18
22. ROLLBACK
•Ends the current transaction by discarding all pending data changes.
•Syntax:
ROLLBACK;
or
ROLLBACK TO SAVEPOINT <savepoint_name>;
•Example:
22