SlideShare a Scribd company logo
1 of 19
ORACLE SQLORACLE SQL
OverviewOverview
Personal DBMS Vs Client/Server DBMSPersonal DBMS Vs Client/Server DBMS
Oracle 8 EnvironmentOracle 8 Environment
SQL – syntax and examplesSQL – syntax and examples
PL/SQL-introductionPL/SQL-introduction
Server
Gets file requests from clients
Sends files to client
Receives files back from clients
NETWORK
Client A
Sends file requests to server
Receives files from server
Updates data
Sends files back to server
Client B
Sends file requests to server
Receives files from server
Updates data
Sends files back to server
Personal
DBMS
Personal DBMS - ProblemsPersonal DBMS - Problems
Demand on the client and the networkDemand on the client and the network
Does not perform table locking automaticallyDoes not perform table locking automatically
Not fault tolerant in the case of client failureNot fault tolerant in the case of client failure
Do not have file based transaction loggingDo not have file based transaction logging
Server
Gets data requests from clients
Adds, Deletes and updates data
Sends results to clients
NETWORK
Client A
Sends data requests to server
Receives results from server
Sends new data or changes to server
Client B
Sends data requests to server
Receives results from server
Sends new data or changes to server
Client/server
DBMS
Client/Server DBMSClient/Server DBMS
Minimal load on the client and the networkMinimal load on the client and the network
Performs table locking automaticallyPerforms table locking automatically
Fault tolerant in the case of client failureFault tolerant in the case of client failure
File based transaction loggingFile based transaction logging
Oracle 8 EnvironmentOracle 8 Environment
SQL * PlusSQL * Plus
PL/SQLPL/SQL
Query BuilderQuery Builder
DeveloperDeveloper
Enterprise ManagerEnterprise Manager
Web application serverWeb application server
SqlplusSqlplus username/passwordusername/password
ALTER USERALTER USER user-nameuser-name IDENTIFIED BYIDENTIFIED BY newpasswordnewpassword
STASTART filename |RT filename | @@ filenamefilename
CLCLEAREAR SCRSCREENEEN
HELPHELP <command><command>
SAVESAVE filename[.ext] REPLACE|APPENDfilename[.ext] REPLACE|APPEND
EXITEXIT
SQL*Plus commandsSQL*Plus commands
SQLSQL
Both an ANSI and ISO standardBoth an ANSI and ISO standard
Types of commands:Types of commands:
1.1. Data Definition Language (DDL) : Create, Alter,Data Definition Language (DDL) : Create, Alter,
Drop, Rename, TruncateDrop, Rename, Truncate
2.2. Data Manipulation Language (DML): Insert,Data Manipulation Language (DML): Insert,
Delete, UpdateDelete, Update
3.3. Data Retrieval: SelectData Retrieval: Select
4.4. Transaction Control: Commit, Rollback, SavepointTransaction Control: Commit, Rollback, Savepoint
5.5. Data Control Language (DCL): Grant, RevokeData Control Language (DCL): Grant, Revoke
PositionPosition
IDID
PositionPosition
DescriptionDescription
11 PresidentPresident
22 ManagerManager
33 ProgrammerProgrammer
44 AccountantAccountant
55 SalesmanSalesman
QualificationQualification
IDID
QualificationQualification
DescriptionDescription
11 DoctorateDoctorate
22 MastersMasters
33 BachelorsBachelors
44 AssociatesAssociates
DeptDept
IDID
DeptDept
NameName
LocationLocation
1010 FinanceFinance CharlotteCharlotte
2020 InfosysInfosys New YorkNew York
3030 MarketingMarketing WoodbridgeWoodbridge
4040 AccountantAccountant CaliforniaCalifornia
DEPARTMENT
POSITION
QUALIFICATION
EmpEmp
IDID
LastLast
NameName
FirstFirst
NameName
PositionPosition
IDID
SuperSuper
IDID
HireHire
DateDate
SalarySalary CommComm DeptDept
IDID
QualQual
IDID
111111 SmithSmith JohnJohn 11 04/15/6004/15/60 265000265000 35003500 1010 11
246246 HoustonHouston LarryLarry 22 111111 05/19/6705/19/67 150000150000 10001000 4040 22
123123 RobertsRoberts SandiSandi 22 111111 12/02/9112/02/91 7500075000 1010 22
433433 McCallMcCall AlexAlex 33 543543 05/10/9705/10/97 6650066500 2020 44
543543 DevDev DereckDereck 22 111111 03/15/9503/15/95 8000080000 20002000 2020 11
200200 ShawShaw JinkuJinku 55 135135 01/03/0001/03/00 2450024500 30003000 3030
222222 ChenChen SunnySunny 44 123123 08/15/9908/15/99 3500035000 1010 33
135135 GarnerGarner StanleyStanley 22 111111 02/29/9602/29/96 4500045000 50005000 3030 55
EMPLOYEE
Data Definition Language:Data Definition Language:
CREATE TABLECREATE TABLE {table}{table}
(( {column datatype [DEFAULT expr]{column datatype [DEFAULT expr]
[column_constraint] ... | table_constraint}[column_constraint] ... | table_constraint}
[, { column datatype [DEFAULT expr][, { column datatype [DEFAULT expr]
[column_constraint] ...[column_constraint] ...
))
ALTER TABLEALTER TABLE {table}{table}
[[ADD|MODIFYADD|MODIFY {column datatype [DEFAULT expr] [column_constraint]}{column datatype [DEFAULT expr] [column_constraint]}
[[DROPDROP drop_clause]drop_clause]
DROP TABLEDROP TABLE {table} [cascade constraints]{table} [cascade constraints]
DESCDESC {table}{table}
CREATE TABLE EmpCREATE TABLE Emp
((
empid Decimal(10) NOT NULL,empid Decimal(10) NOT NULL,
positionid Number(2),positionid Number(2),
supervisorid Number(3),supervisorid Number(3),
deptid Number(2),deptid Number(2),
qualid Number(1),qualid Number(1),
lname varchar2(10),lname varchar2(10),
fname varchar2(10),fname varchar2(10),
salary Decimal(10,2),salary Decimal(10,2),
hiredate Date,hiredate Date,
commission Decimal(4,2),commission Decimal(4,2),
PRIMARY KEY (empid),PRIMARY KEY (empid),
FOREIGN KEY (positionid) REFERENCES Position(positionid),FOREIGN KEY (positionid) REFERENCES Position(positionid),
FOREIGN KEY (deptid) REFERENCES Dept(deptid),FOREIGN KEY (deptid) REFERENCES Dept(deptid),
FOREIGN KEY (qualid) REFERENCES Qualification(qualid)FOREIGN KEY (qualid) REFERENCES Qualification(qualid)
););
ALTER TABLE EMP MODIFY Commission decimal(7,2);ALTER TABLE EMP MODIFY Commission decimal(7,2);
Data Manipulation Language:Data Manipulation Language:
INSERT INTOINSERT INTO {table | view} [ (column [, column] ...) ]{table | view} [ (column [, column] ...) ]
VALUESVALUES (expr,expr ...)(expr,expr ...)
UPDATEUPDATE {table | view }{table | view }
SETSET { (column [, column] = { expr | }{ (column [, column] = { expr | }
[[WHEREWHERE condition]condition]
DELETEDELETE [[FROMFROM] {table | view} [] {table | view} [WHEREWHERE condition]condition]
INSERT INTO Dept( deptid,deptname,location)
VALUES(50,'IT','Dallas');
INSERT INTO Emp(empid,
lname,fname,positionid,
supervisorid,hiredate,
salary,deptid,qualid)
VALUES(227,'howser','Barbara',4,111,'25-AUG-83',45000,10,3);
UPDATE dept SET deptname='Sales' WHERE deptID=50;
DELETE FROM dept
WHERE deptid='50';
Data Retrieval:Data Retrieval:
SELECTSELECT [DISTINCT | ALL] {table|view}[DISTINCT | ALL] {table|view}
FROMFROM {table | view}{table | view}
[[WHEREWHERE condition ]condition ]
[[GROUP BYGROUP BY expr [, expr]]expr [, expr]]
[[ORDER BYORDER BY {expr} [ASC | DESC]]{expr} [ASC | DESC]]
select * from dept;select * from dept;
select deptname from dept where deptid='10';select deptname from dept where deptid='10';
select lname,fname from emp order by lname desc;select lname,fname from emp order by lname desc;
select max(salary) from emp group by positionid;select max(salary) from emp group by positionid;
select deptname from dept,emp whereselect deptname from dept,emp where
dept.deptid=emp.deptid and emp.empid='111';dept.deptid=emp.deptid and emp.empid='111';
Transaction Control:Transaction Control:
COMMITCOMMIT
ROLLBACKROLLBACK [ to {savepoint}][ to {savepoint}]
SAVEPOINTSAVEPOINT {name}{name}
commit;commit;
savepoint point1;savepoint point1;
rollback to point1;rollback to point1;
Data Control Language:Data Control Language:
GRANTGRANT [privileges][privileges]
ONON objectobject TOTO user|publicuser|public
[[WITH GRANT OPTIONWITH GRANT OPTION]]
REVOKEREVOKE [privileges][privileges]
ONON objectobject TOTO user|publicuser|public
[[CASCADE CONSTRAINTSCASCADE CONSTRAINTS]]
grant select,update on emp to XYZ ;grant select,update on emp to XYZ ;
revoke update on emp to XYZ;revoke update on emp to XYZ;
A PL/SQL Example:A PL/SQL Example:
CREATE OR REPLACE PROCEDURECREATE OR REPLACE PROCEDURE raise_salary (empno INTEGER,raise_salary (empno INTEGER,
increase REAL)increase REAL) ISIS
current_salary REAL;current_salary REAL;
salary_missing EXCEPTION;salary_missing EXCEPTION;
BEGINBEGIN
SELECT salary INTO current_salary FROM emp WHERE emp.empid =SELECT salary INTO current_salary FROM emp WHERE emp.empid =
empno;empno;
IF current_salary IS NULL THENIF current_salary IS NULL THEN
RAISE salary_missing;RAISE salary_missing;
ELSEELSE
UPDATE emp SET salary = salary + increase WHEREUPDATE emp SET salary = salary + increase WHERE emp.empidemp.empid
= empno;= empno;
END IF;END IF;
EXCEPTIONEXCEPTION
WHEN salary_missing THENWHEN salary_missing THEN
UPDATE emp SET salary=0 where emp.empid=empno;UPDATE emp SET salary=0 where emp.empid=empno;
ENDEND raise_salary;raise_salary;

More Related Content

What's hot

Add Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with SolrAdd Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with Solr
adunne
 

What's hot (20)

Stefan Hochdörfer - The NoSQL Store everyone ignores: PostgreSQL - NoSQL matt...
Stefan Hochdörfer - The NoSQL Store everyone ignores: PostgreSQL - NoSQL matt...Stefan Hochdörfer - The NoSQL Store everyone ignores: PostgreSQL - NoSQL matt...
Stefan Hochdörfer - The NoSQL Store everyone ignores: PostgreSQL - NoSQL matt...
 
Asm troubleshooting and asm scripts
Asm troubleshooting and asm scriptsAsm troubleshooting and asm scripts
Asm troubleshooting and asm scripts
 
321 Rac
321 Rac321 Rac
321 Rac
 
Oracle
OracleOracle
Oracle
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDB
 
ColdFusion ORM - Advanced : Adobe Max 2009
ColdFusion ORM - Advanced : Adobe Max 2009ColdFusion ORM - Advanced : Adobe Max 2009
ColdFusion ORM - Advanced : Adobe Max 2009
 
Msql
Msql Msql
Msql
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
 
Dmxedit
DmxeditDmxedit
Dmxedit
 
Demystifying PostgreSQL
Demystifying PostgreSQLDemystifying PostgreSQL
Demystifying PostgreSQL
 
Free Based DSLs for Distributed Compute Engines
Free Based DSLs for Distributed Compute EnginesFree Based DSLs for Distributed Compute Engines
Free Based DSLs for Distributed Compute Engines
 
Demystifying PostgreSQL (Zendcon 2010)
Demystifying PostgreSQL (Zendcon 2010)Demystifying PostgreSQL (Zendcon 2010)
Demystifying PostgreSQL (Zendcon 2010)
 
Oracle ORA Errors
Oracle ORA ErrorsOracle ORA Errors
Oracle ORA Errors
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用
 
Add Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with SolrAdd Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with Solr
 
Mysql
MysqlMysql
Mysql
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개
 
BIS and DDE In Action
BIS and DDE In ActionBIS and DDE In Action
BIS and DDE In Action
 

Viewers also liked

Learning About Google Drive
Learning About Google DriveLearning About Google Drive
Learning About Google Drive
Desiree Caskey
 
Software 100707014922-phpapp02
Software 100707014922-phpapp02Software 100707014922-phpapp02
Software 100707014922-phpapp02
Markgendy02
 
Indian railways-management-information-system
Indian railways-management-information-systemIndian railways-management-information-system
Indian railways-management-information-system
anishanish
 
Word Processing Slides
Word Processing SlidesWord Processing Slides
Word Processing Slides
iarthur
 
Applications: Word-Processing, Spreadsheet & Database
Applications: Word-Processing, Spreadsheet & DatabaseApplications: Word-Processing, Spreadsheet & Database
Applications: Word-Processing, Spreadsheet & Database
Alaa Sadik
 
Outlook Presentation
Outlook PresentationOutlook Presentation
Outlook Presentation
tamil999
 

Viewers also liked (20)

Learning About Google Drive
Learning About Google DriveLearning About Google Drive
Learning About Google Drive
 
Software 100707014922-phpapp02
Software 100707014922-phpapp02Software 100707014922-phpapp02
Software 100707014922-phpapp02
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Windows Utilities
Windows UtilitiesWindows Utilities
Windows Utilities
 
Middleware
MiddlewareMiddleware
Middleware
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
Open Source Shareware Freeware
Open Source Shareware FreewareOpen Source Shareware Freeware
Open Source Shareware Freeware
 
Shareware
SharewareShareware
Shareware
 
Indian railways-management-information-system
Indian railways-management-information-systemIndian railways-management-information-system
Indian railways-management-information-system
 
Getting started with Outlook
Getting started with OutlookGetting started with Outlook
Getting started with Outlook
 
Middleware
MiddlewareMiddleware
Middleware
 
Basic of MS Outlook
Basic of MS OutlookBasic of MS Outlook
Basic of MS Outlook
 
Role of information technology in indian railway
Role of information technology in indian railwayRole of information technology in indian railway
Role of information technology in indian railway
 
Microsoft outlook 2013
Microsoft outlook 2013Microsoft outlook 2013
Microsoft outlook 2013
 
Word Processing Slides
Word Processing SlidesWord Processing Slides
Word Processing Slides
 
Microsoft outlook 2010
Microsoft outlook 2010Microsoft outlook 2010
Microsoft outlook 2010
 
Applications: Word-Processing, Spreadsheet & Database
Applications: Word-Processing, Spreadsheet & DatabaseApplications: Word-Processing, Spreadsheet & Database
Applications: Word-Processing, Spreadsheet & Database
 
Outlook Presentation
Outlook PresentationOutlook Presentation
Outlook Presentation
 
computer hardware and software
computer hardware and softwarecomputer hardware and software
computer hardware and software
 
Report-computer hardware,system, and software
Report-computer hardware,system, and softwareReport-computer hardware,system, and software
Report-computer hardware,system, and software
 

Similar to SQL introduction

Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oracle
suman1248
 
MDI Training DB2 Course
MDI Training DB2 CourseMDI Training DB2 Course
MDI Training DB2 Course
Marcus Davage
 
Linguagem sql
Linguagem sqlLinguagem sql
Linguagem sql
Tic Eslc
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
Reka
 

Similar to SQL introduction (20)

Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oracle
 
Introducción rápida a SQL
Introducción rápida a SQLIntroducción rápida a SQL
Introducción rápida a SQL
 
Sql
SqlSql
Sql
 
A Tour to MySQL Commands
A Tour to MySQL CommandsA Tour to MySQL Commands
A Tour to MySQL Commands
 
MDI Training DB2 Course
MDI Training DB2 CourseMDI Training DB2 Course
MDI Training DB2 Course
 
Lab
LabLab
Lab
 
Beg sql
Beg sqlBeg sql
Beg sql
 
Beg sql
Beg sqlBeg sql
Beg sql
 
Graph Database Query Languages
Graph Database Query LanguagesGraph Database Query Languages
Graph Database Query Languages
 
Sqlbysandeep
SqlbysandeepSqlbysandeep
Sqlbysandeep
 
Linguagem sql
Linguagem sqlLinguagem sql
Linguagem sql
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Module02
Module02Module02
Module02
 
plsql les06
 plsql les06 plsql les06
plsql les06
 
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
الوحدة التاسعة - قاعدة البيانات وادارتها
الوحدة التاسعة - قاعدة البيانات وادارتهاالوحدة التاسعة - قاعدة البيانات وادارتها
الوحدة التاسعة - قاعدة البيانات وادارتها
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

SQL introduction

  • 2. OverviewOverview Personal DBMS Vs Client/Server DBMSPersonal DBMS Vs Client/Server DBMS Oracle 8 EnvironmentOracle 8 Environment SQL – syntax and examplesSQL – syntax and examples PL/SQL-introductionPL/SQL-introduction
  • 3. Server Gets file requests from clients Sends files to client Receives files back from clients NETWORK Client A Sends file requests to server Receives files from server Updates data Sends files back to server Client B Sends file requests to server Receives files from server Updates data Sends files back to server Personal DBMS
  • 4. Personal DBMS - ProblemsPersonal DBMS - Problems Demand on the client and the networkDemand on the client and the network Does not perform table locking automaticallyDoes not perform table locking automatically Not fault tolerant in the case of client failureNot fault tolerant in the case of client failure Do not have file based transaction loggingDo not have file based transaction logging
  • 5. Server Gets data requests from clients Adds, Deletes and updates data Sends results to clients NETWORK Client A Sends data requests to server Receives results from server Sends new data or changes to server Client B Sends data requests to server Receives results from server Sends new data or changes to server Client/server DBMS
  • 6. Client/Server DBMSClient/Server DBMS Minimal load on the client and the networkMinimal load on the client and the network Performs table locking automaticallyPerforms table locking automatically Fault tolerant in the case of client failureFault tolerant in the case of client failure File based transaction loggingFile based transaction logging
  • 7. Oracle 8 EnvironmentOracle 8 Environment SQL * PlusSQL * Plus PL/SQLPL/SQL Query BuilderQuery Builder DeveloperDeveloper Enterprise ManagerEnterprise Manager Web application serverWeb application server
  • 8. SqlplusSqlplus username/passwordusername/password ALTER USERALTER USER user-nameuser-name IDENTIFIED BYIDENTIFIED BY newpasswordnewpassword STASTART filename |RT filename | @@ filenamefilename CLCLEAREAR SCRSCREENEEN HELPHELP <command><command> SAVESAVE filename[.ext] REPLACE|APPENDfilename[.ext] REPLACE|APPEND EXITEXIT SQL*Plus commandsSQL*Plus commands
  • 9. SQLSQL Both an ANSI and ISO standardBoth an ANSI and ISO standard Types of commands:Types of commands: 1.1. Data Definition Language (DDL) : Create, Alter,Data Definition Language (DDL) : Create, Alter, Drop, Rename, TruncateDrop, Rename, Truncate 2.2. Data Manipulation Language (DML): Insert,Data Manipulation Language (DML): Insert, Delete, UpdateDelete, Update 3.3. Data Retrieval: SelectData Retrieval: Select 4.4. Transaction Control: Commit, Rollback, SavepointTransaction Control: Commit, Rollback, Savepoint 5.5. Data Control Language (DCL): Grant, RevokeData Control Language (DCL): Grant, Revoke
  • 10. PositionPosition IDID PositionPosition DescriptionDescription 11 PresidentPresident 22 ManagerManager 33 ProgrammerProgrammer 44 AccountantAccountant 55 SalesmanSalesman QualificationQualification IDID QualificationQualification DescriptionDescription 11 DoctorateDoctorate 22 MastersMasters 33 BachelorsBachelors 44 AssociatesAssociates DeptDept IDID DeptDept NameName LocationLocation 1010 FinanceFinance CharlotteCharlotte 2020 InfosysInfosys New YorkNew York 3030 MarketingMarketing WoodbridgeWoodbridge 4040 AccountantAccountant CaliforniaCalifornia DEPARTMENT POSITION QUALIFICATION
  • 11. EmpEmp IDID LastLast NameName FirstFirst NameName PositionPosition IDID SuperSuper IDID HireHire DateDate SalarySalary CommComm DeptDept IDID QualQual IDID 111111 SmithSmith JohnJohn 11 04/15/6004/15/60 265000265000 35003500 1010 11 246246 HoustonHouston LarryLarry 22 111111 05/19/6705/19/67 150000150000 10001000 4040 22 123123 RobertsRoberts SandiSandi 22 111111 12/02/9112/02/91 7500075000 1010 22 433433 McCallMcCall AlexAlex 33 543543 05/10/9705/10/97 6650066500 2020 44 543543 DevDev DereckDereck 22 111111 03/15/9503/15/95 8000080000 20002000 2020 11 200200 ShawShaw JinkuJinku 55 135135 01/03/0001/03/00 2450024500 30003000 3030 222222 ChenChen SunnySunny 44 123123 08/15/9908/15/99 3500035000 1010 33 135135 GarnerGarner StanleyStanley 22 111111 02/29/9602/29/96 4500045000 50005000 3030 55 EMPLOYEE
  • 12. Data Definition Language:Data Definition Language: CREATE TABLECREATE TABLE {table}{table} (( {column datatype [DEFAULT expr]{column datatype [DEFAULT expr] [column_constraint] ... | table_constraint}[column_constraint] ... | table_constraint} [, { column datatype [DEFAULT expr][, { column datatype [DEFAULT expr] [column_constraint] ...[column_constraint] ... )) ALTER TABLEALTER TABLE {table}{table} [[ADD|MODIFYADD|MODIFY {column datatype [DEFAULT expr] [column_constraint]}{column datatype [DEFAULT expr] [column_constraint]} [[DROPDROP drop_clause]drop_clause] DROP TABLEDROP TABLE {table} [cascade constraints]{table} [cascade constraints] DESCDESC {table}{table}
  • 13. CREATE TABLE EmpCREATE TABLE Emp (( empid Decimal(10) NOT NULL,empid Decimal(10) NOT NULL, positionid Number(2),positionid Number(2), supervisorid Number(3),supervisorid Number(3), deptid Number(2),deptid Number(2), qualid Number(1),qualid Number(1), lname varchar2(10),lname varchar2(10), fname varchar2(10),fname varchar2(10), salary Decimal(10,2),salary Decimal(10,2), hiredate Date,hiredate Date, commission Decimal(4,2),commission Decimal(4,2), PRIMARY KEY (empid),PRIMARY KEY (empid), FOREIGN KEY (positionid) REFERENCES Position(positionid),FOREIGN KEY (positionid) REFERENCES Position(positionid), FOREIGN KEY (deptid) REFERENCES Dept(deptid),FOREIGN KEY (deptid) REFERENCES Dept(deptid), FOREIGN KEY (qualid) REFERENCES Qualification(qualid)FOREIGN KEY (qualid) REFERENCES Qualification(qualid) );); ALTER TABLE EMP MODIFY Commission decimal(7,2);ALTER TABLE EMP MODIFY Commission decimal(7,2);
  • 14. Data Manipulation Language:Data Manipulation Language: INSERT INTOINSERT INTO {table | view} [ (column [, column] ...) ]{table | view} [ (column [, column] ...) ] VALUESVALUES (expr,expr ...)(expr,expr ...) UPDATEUPDATE {table | view }{table | view } SETSET { (column [, column] = { expr | }{ (column [, column] = { expr | } [[WHEREWHERE condition]condition] DELETEDELETE [[FROMFROM] {table | view} [] {table | view} [WHEREWHERE condition]condition]
  • 15. INSERT INTO Dept( deptid,deptname,location) VALUES(50,'IT','Dallas'); INSERT INTO Emp(empid, lname,fname,positionid, supervisorid,hiredate, salary,deptid,qualid) VALUES(227,'howser','Barbara',4,111,'25-AUG-83',45000,10,3); UPDATE dept SET deptname='Sales' WHERE deptID=50; DELETE FROM dept WHERE deptid='50';
  • 16. Data Retrieval:Data Retrieval: SELECTSELECT [DISTINCT | ALL] {table|view}[DISTINCT | ALL] {table|view} FROMFROM {table | view}{table | view} [[WHEREWHERE condition ]condition ] [[GROUP BYGROUP BY expr [, expr]]expr [, expr]] [[ORDER BYORDER BY {expr} [ASC | DESC]]{expr} [ASC | DESC]] select * from dept;select * from dept; select deptname from dept where deptid='10';select deptname from dept where deptid='10'; select lname,fname from emp order by lname desc;select lname,fname from emp order by lname desc; select max(salary) from emp group by positionid;select max(salary) from emp group by positionid; select deptname from dept,emp whereselect deptname from dept,emp where dept.deptid=emp.deptid and emp.empid='111';dept.deptid=emp.deptid and emp.empid='111';
  • 17. Transaction Control:Transaction Control: COMMITCOMMIT ROLLBACKROLLBACK [ to {savepoint}][ to {savepoint}] SAVEPOINTSAVEPOINT {name}{name} commit;commit; savepoint point1;savepoint point1; rollback to point1;rollback to point1;
  • 18. Data Control Language:Data Control Language: GRANTGRANT [privileges][privileges] ONON objectobject TOTO user|publicuser|public [[WITH GRANT OPTIONWITH GRANT OPTION]] REVOKEREVOKE [privileges][privileges] ONON objectobject TOTO user|publicuser|public [[CASCADE CONSTRAINTSCASCADE CONSTRAINTS]] grant select,update on emp to XYZ ;grant select,update on emp to XYZ ; revoke update on emp to XYZ;revoke update on emp to XYZ;
  • 19. A PL/SQL Example:A PL/SQL Example: CREATE OR REPLACE PROCEDURECREATE OR REPLACE PROCEDURE raise_salary (empno INTEGER,raise_salary (empno INTEGER, increase REAL)increase REAL) ISIS current_salary REAL;current_salary REAL; salary_missing EXCEPTION;salary_missing EXCEPTION; BEGINBEGIN SELECT salary INTO current_salary FROM emp WHERE emp.empid =SELECT salary INTO current_salary FROM emp WHERE emp.empid = empno;empno; IF current_salary IS NULL THENIF current_salary IS NULL THEN RAISE salary_missing;RAISE salary_missing; ELSEELSE UPDATE emp SET salary = salary + increase WHEREUPDATE emp SET salary = salary + increase WHERE emp.empidemp.empid = empno;= empno; END IF;END IF; EXCEPTIONEXCEPTION WHEN salary_missing THENWHEN salary_missing THEN UPDATE emp SET salary=0 where emp.empid=empno;UPDATE emp SET salary=0 where emp.empid=empno; ENDEND raise_salary;raise_salary;