SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
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
2
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
Solution#1
SQL>CREATE TABLE doctor
2 (license_no int,
3 name varchar2(100),
4 qualification varchar2(100),
5 salary NUMBER(10,2) CHECK (salary >=10000),
6 contact_no INT,
7 cnic INT,
8 employee_no INT REFERENCES employee);
4
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
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
DATA MANIPULATION
LANGUAGE (DML)
•INSERT
•SELECT
•UPDATE
•DELETE
7
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
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
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
Capabilities of SELECT
11
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
TOTAL USER_TABLES
•SELECT TABLE_NAME/* FROM TAB;
OR
SELECT TABLE_NAME FROM USER_TABLES;
13
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
Motivational Speaking
15
UPDATE STATEMENT
•Modify existing records with UPDATE statement.
•Syntax:
UPDATE <table_name>
SET <column_name> = <column_value>, …….
[WHERE <condition>];
•Condition is optional part.
16
DELETE STATEMENT
•DELETE is used to either removing table contents or specific rows.
•Syntax:
DELETE FROM <table_name>
[WHERE <condition>];
17
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
Transaction Control
Language(TCL) Commands
19
COMMIT
•Ends the current transaction by making
all pending data changes permanent.
•Syntax:
COMMIT;
20
SAVEPOINT
•Marks a savepoint within current
transaction.
•Syntax:
SAVEPOINT <savepoint_name>;
21
ROLLBACK
•Ends the current transaction by discarding all pending data changes.
•Syntax:
ROLLBACK;
or
ROLLBACK TO SAVEPOINT <savepoint_name>;
•Example:
22
TCL Operational Structure
23
Your Suggestions?
24
Give your feedback at: m.waheed3668@gmail.com

Contenu connexe

Tendances

Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
Ehtisham Ali
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
Ashwin Dinoriya
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
Vivek Singh
 

Tendances (19)

Sql commands
Sql commandsSql commands
Sql commands
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
 
Sql commands
Sql commandsSql commands
Sql commands
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Sql DML
Sql DMLSql DML
Sql DML
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
 
Null values, insert, delete and update in database
Null values, insert, delete and update in databaseNull values, insert, delete and update in database
Null values, insert, delete and update in database
 
Mysql
MysqlMysql
Mysql
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 

Similaire à Data Manipulation(DML) and Transaction Control (TCL)

SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SaiMiryala1
 
2. DBMS Experiment - Lab 2 Made in SQL Used
2. DBMS Experiment - Lab 2 Made in SQL Used2. DBMS Experiment - Lab 2 Made in SQL Used
2. DBMS Experiment - Lab 2 Made in SQL Used
TheVerse1
 

Similaire à Data Manipulation(DML) and Transaction Control (TCL) (20)

DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
Sql wksht-2
Sql wksht-2Sql wksht-2
Sql wksht-2
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
Lab
LabLab
Lab
 
lect 2.pptx
lect 2.pptxlect 2.pptx
lect 2.pptx
 
2. DBMS Experiment - Lab 2 Made in SQL Used
2. DBMS Experiment - Lab 2 Made in SQL Used2. DBMS Experiment - Lab 2 Made in SQL Used
2. DBMS Experiment - Lab 2 Made in SQL Used
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Oracle
OracleOracle
Oracle
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库Oracle OCP 1Z0-007题库
Oracle OCP 1Z0-007题库
 
1 z0 047
1 z0 0471 z0 047
1 z0 047
 
01 basic orders
01   basic orders01   basic orders
01 basic orders
 
Module 3
Module 3Module 3
Module 3
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL commands.docx
SQL commands.docxSQL commands.docx
SQL commands.docx
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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
  • 2. 2
  • 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
  • 4. Solution#1 SQL>CREATE TABLE doctor 2 (license_no int, 3 name varchar2(100), 4 qualification varchar2(100), 5 salary NUMBER(10,2) CHECK (salary >=10000), 6 contact_no INT, 7 cnic INT, 8 employee_no INT REFERENCES employee); 4
  • 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
  • 13. TOTAL USER_TABLES •SELECT TABLE_NAME/* FROM TAB; OR SELECT TABLE_NAME FROM USER_TABLES; 13
  • 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
  • 20. COMMIT •Ends the current transaction by making all pending data changes permanent. •Syntax: COMMIT; 20
  • 21. SAVEPOINT •Marks a savepoint within current transaction. •Syntax: SAVEPOINT <savepoint_name>; 21
  • 22. ROLLBACK •Ends the current transaction by discarding all pending data changes. •Syntax: ROLLBACK; or ROLLBACK TO SAVEPOINT <savepoint_name>; •Example: 22
  • 24. Your Suggestions? 24 Give your feedback at: m.waheed3668@gmail.com