SlideShare a Scribd company logo
1 of 27
Download to read offline
Nibble Matrix
By Kamlesh Kumar Singh
Database - Collection of data files.
DataFile - collection of records(rows).
Record(rows) - collection of fields.
Field = set of informations.
DBMS - Database Management System.
A System which manage the database.
Database Handler - each & every database has one database handler - that handle uthe database.
DBMS - Database Management System. - Access / FoxPro / Excel
RDBMS - Relational Database Management System. - SQL Server / Oracle upto 7.3 / sybase / MySQL.
ORDBMS - Object Relational Database Management System. - Oracle8
oracle8 - Object, user define composite data types.
OODBMS - Object Oriented Database Management System. - Oracle 8i & 9i & 10G
i - internet programming. - java is a kind of internet programming.
need for java - JVM , Oracle8i - JVM include - SQLJ - SQL Java programming.
SQL - Structured Query Language - common language for all Databases.
SQL -
DDL - create / alter / drop, truncate
DML - delete / insert / update
DCL - grant / revoke
DRL - select statement
TCL - commit / rollback / savepoint.
Codd's Rules - 12 rules + 1 zero rule = 13 rules .
Codd's -
< 6 rules support - DBMS
>= 6 rules support - RDBMS.
Oracle support 12.5 rules.
.5 not supported by oracle that is view updation.
views -
simple view & complex view
auto updation - simple views updatable but complex view - not auto updatable.
work with Oracle
env -
SQLPLUS - Oracle env
ISQLPLUS - in 9i , for use oracle with web browser. ie - http://localhost/isqlplus
--to create own database table.
1- without constraints 2 - with constraints
constraints -
not null - user can't insert into null values.
unique - not null + not duplicate
primary key - not null + not duplicate = can ref with other table
foreign or reference key - child records.
check - condition check at the DML operator(insert & update) time.
default - if user not spacify value for a column then
default value to be inserted.
constraints name -
database server assign (auto) user (explicit)
data type
number(4) - int only
number(7,2) - floating value 99999.99
char - fixed length
varchar & varchar2 - dynamic , but has max limit
lob - upto 4 gb
long - upto 2 gb
date - for date & time.
user define composite data type - Object.
- to add constraints in table .
1 - at the table creation time
2 - after table creation.
-- to create a table without constraints.
create table semp
(
empno number(4),
ename varchar(20),
sal number(7,2),
deptno number(2)
)
-- to create a table with constraints.
create table femp
(
empno number(4) constraints myno primary key,
ename varchar(20) not null,
sal number(7,2) constraints mysal check(sal> 5000),
deptno number(2) default(10) check(deptno in(10,20,30,40))
)
- to insert default value in table column
insert into cemp(empno,ename,sal) values(1003,'Amar',9299);
- to add extra column in table
alter table cemp add jdate date
- to change the column size
alter table cemp modify sal number(8,2)
*** but for decreasing column size table should be empty
- to add constraint after table creation.
alter table bemp add constraints mys check(sal<50000)
- to enable or desable constaints
- for disable
alter table cemp disable constraints mysal;
- for enable
alter table femp enable constraints mysal;
*** for enabling constraints condition must be fullfil
- to drop a constraints
alter table femp drop constraints mysal
- to set unused column
alter table cemp set unused column jdate
- to drop all unused columns
alter table cemp drop unused columns
- to drop an column
alter table cemp drop column deptno
- to rename table
rename cemp to cc;
- to create synonym
create synonym c for femp
- to create table with foreign key
create table fincr
(
empno number(4) references femp(empno),
amount number(5)
)
-
create table fbonus
(
empno number(4) references femp(empno) on delete cascade,
amount number(5) )
on delete cascade option - if parent record deleted then child record auto deleted.
else delete child record first then parent record deleted.
Joins - to select data from more then one tables.
type -
1- Equi Join - when common column exist in both tables.
select empno,ename,sal,e.deptno,dname from emp e,dept d
where e.deptno=d.deptno
2- Non Equi Join - when common column not exist in both table.
select empno,ename,sal,grade from emp,salgrade
where sal between losal and hisal
3- Cross Join - table join without any condition.
result - Ist table each row * each row of IInd table
select empno,ename,sal,e.deptno,dname from emp e,dept d
4- Outer Join - like equi join.
Left Outer join - display those record also which r
exist in IInd not exist in Ist.
select empno,ename,sal,e.deptno,dname from emp e,dept d
where e.deptno=d.deptno(+)
10
20
30
40 - not 50
Right outer join - display those record also which r
exist in Ist not exist in IInd.
select empno,ename,sal,e.deptno,dname from emp e,dept d
where e.deptno(+)=d.deptno
10
20
30
50 - not 40
5- Self Join - when one table use a multiple table.
- list of all emp with his/her manager name.
select e.ename,m.ename as manager from emp e,emp m
where e.mgr = m.empno
- List of all emp whose sal > their manager.
select e.ename,m.ename as manager from emp e,emp m
where e.mgr = m.empno and e.sal > m.sal
- List of all emp who join company before their manager.
VIEWS :->
-----
* A view is a logical table based on a table or another view.
* A view contains no data of its own. but it is like a window
through witch data from table can be viewed or change.
* The tables on which a view is based are called base tables.
* the view is stored as a select statement in the data dictionary.
* the changes in the table are automatically reflected in the views.
Advantages of a view : ->
* to make a complex queries easy.
* to allow data independence .
* securities.
views types ->
1> Simple 2> complex
Deff. between Simple & complex views : -
------------------------------------
Feature Simple Complex
1> no. of tables one one or more
2> contain function no yes
3> contain groups no yes
of data
4> DML through views yes not allowed
view type
simple view - with single table
complex view - with more then one table or with functions
read only view - read only.
force view - view created without having base table
in line view - when select statement pass as a object in from clause
Q1. -> create a view, amit, that contains details of employees in deptno 10 .
Ans.
create or replace view amit as select empno,ename,sal,deptno from emp
where deptno=10;
with read only option. - > to used for create a read only view
---------------------
Q2. -> create read only view for employees of dept 10 ?
Ans. ->
create view nnn as select empno,ename,sal from emp
where deptno=10 with read only;
with check option --> when the WITH CHECK OPTION CLAUSE is used , any DML statement that
----------------- manipulate rows that can be not be selected by a VIEW ,are rejected
** to create a view with check option -
create view a2 as select empno,ename,sal,deptno from emp
where deptno=10 with check option;
* in this view we can insert only in dept 10 not in any other depts.
* to select data from a view
select * from viewname;
* to create a complex view .
CREATE VIEW CCC3 AS SELECT EMPNO,ENAME,SAL,E.DEPTNO,D.DNAME FROM EMP E,DEPT D
* create table with keys(primary key , Foreign key)
-->with Primary key
CREATE TABLE M_DEPT
(
DEPTNO NUMBER(2) CONSTRAINTS DE PRIMARY KEY,
DNAME VARCHAR2(10) NOT NULL
);
--> with foreign key
CREATE TABLE M_EMP
(
EMPNO NUMBER(4) PRIMARY KEY,
ENAME VARCHAR2(10),
SAL NUMBER(7,2),
DEPTNO NUMBER(2),
FOREIGN KEY(DEPTNO) REFERENCES M_DEPT(DEPTNO)
);
--> create view
CREATE VIEW CCC4 AS SELECT EMPNO,ENAME,SAL,E.DEPTNO,D.DNAME FROM M_EMP E,M_DEPT D
WHERE E.DEPTNO=D.DEPTNO
-- force view - view create without a base table.
create force view amit6 as select * from baba
--------->
The view must not contain any of the following constructs:
A set operator
A DISTINCT operator
An aggregate or analytic function
A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause
A collection expression in a SELECT list
A subquery in a SELECT list
A subquery designated WITH READ ONLY
An inline view is a SELECT statement in the FROM-clause of another SELECT statement. In-line views are
commonly used
simplify complex queries by removing join operations and condensing several separate queries into a
single query.
This feature was introduced in Oracle 7.2.
This feature is commonly referred to in the MSSQL community as a derived table, and in the Postgres
community
simply refers to it as a subselect (subselects are inline views + subqueries in Oracle nomenclature).
[edit]Examples
Example inline view:
SELECT *
FROM ( SELECT deptno, count(*) emp_count
FROM emp
GROUP BY deptno ) emp,
dept
WHERE dept.deptno = emp.deptno;
Another good example of an inline view is:
SELECT a.last_name, a.salary, a.department_id, b.maxsal
FROM employees a,
( SELECT department_id, max(salary) maxsal
FROM employees
GROUP BY department_id ) b
WHERE a.department_id = b.department_id
AND a.salary = b.maxsal;
Materialized view or snapshot-> it is one kind of physical table not a logical table.
automatic updation not allowed.
*to create a Materialized view ->
create materialized view cc2 as select * from m_emp;
or
create snapshot cc2 as select * from m_emp
-to drop a materialized view
drop materialized view viewname
* Materialized view not created if table does not contain a primary key constraint.
* for creating materialized view user should have dba privileges.
the DBA can create a user by using the create user command, once a user
is created the DBA can grant the specific system privileges to a user.
Schema - collection of Objects such as tables / views & sequences.
user schema - collection of users Object.
Data Securities -
System Securities - System privileges - gain access to the database.
Data Securities - Object privileges - manipulates the content of
the database Objects.
Object privileges vary from Object to Objects.
Role - group of privileges , role is a kind of intermediate user.
oracle server provide the 3 standard role.
connect - to connect with database
resource - to use the data base resources
dba - for DBA task (database Administration )
- to create user define role -
create role baba;
grant create session,create table , create procedure to baba;
grant baba to singh;
-- TO DROP A ROLE
DROP ROLE BABA
Grant - to assign the privileges
revoke - to remove the privileges.
System privileges -
create session - for connect
create table - for create table
create view - for view creation
create sequence - for sequence creation
create procedure. - for function , procedure & package creation
unlimited tablespace
Object privileges -
privileges table view sequence procedure
alter y - y -
delete Y Y - -
execute - - - Y
index Y - - -
insert Y Y - -
references Y - - -
select Y Y Y -
update Y Y - -
=
all
public - for all users
** for DBA - user should have DBA privilege.
-- to display list of all existsing.
select * from all_user.
-- to create a new user
create user username identified by password
-- to change the password
alter user username identified by password;
-- for connecting user should have connect / create session
privilege.
-- to assign Object privileges -
grant select , insert , update on emp to singh.
grant all on emp to public - for all user
public - for all users
grant select , insert , update on emp to singh
-- TO DROP A USER
DROP USER USERNAME
DROP USER USERNAME CASCADE - DROP USER WITH ALL RELATED LINKS
- for assign Object privileges
grant select,insert , update on emp to singh;
grant select,insert , update on emp to public; -- to assign select , insert & update
privilege for all user.
grant all on emp to public; -- to assign all privileges for all user.
-- to revoke the Object privileges -
revoke select , insert , update on emp from singh;
with grant Option - Object privileges granted with grant option r
revoked when the granter's previleges is revoked.
sequence - sequence is used for auto number generation ,for serial no ,
rollno / empno & more.
syn -
create sequence my
start witn 1001
increment by 1
minvalue 1001
maxvalue 1010
cycle
cache 3
attributes for sequence -
nextval - next value from sequence
currval - current value in sequence
-- to alter seqnence
alter sequence mys
increment by 2
maxvalue 1020
cycle
select ab.nextval from dual
-- to use sequence in table
insert into emp values(ab.nextval,'&name',&sal)
-- to drop a sequence
drop sequence ab;
-- to display list of all sequence
select * from user_sequences;
Temporary Table :-
---------------
used for Temporary result.data exist only for the duration of a transction or session .
only visible with in a single transaction or session. no redo generated.
created in user's temporary tablespace.
syn:-
create global temporary table ab
(
eno number(4) primary key,
ename char(22)
)
on commit delete rows
this table is for transction duration.
* no data segment created.
Indexing - An Oracle Server Index is a Schema Object that can speed
up the retrieval of row by using a pointer. Indexes can be
created explicit & implicit.
if U do not have index on the column, then a full table scan will occur.
implicit index - ORACLE itself creates indexes at the time of
table creation, if a table definition contains a PRIMARY KEY.
Explicit Index - that is created by user.
create [UNIQUE] index INDEXNAME on TABLENAME[COLNAME];
*** to display list of all user indexes.
select * from user_indexes;
CLUSTERING -
=> Clusters r used for performance improvement.
=> Clustering is a method of storing tables that r related and
often accessed together.
=> A cluster is group of rows from separate tables storing in the
same disk block.
=> Clustered tables must have a common column called cluster column.
=> to Cluster tables the user must own the tables.
*** if table is the part of cluster can't be partition.
steps for creating clusters -
=> creating cluster
create cluster cname(colname datatype)
=> creating cluster tables
create table tname
(
colname datatype primary key,
colname datattype
)cluster cname(colname)
create table tname
(
colname datatype references tname(colname),
colname datattype
)cluster cname(colname)
=> creating cluster indexes.
=> In a clustered index, the actual data is stored in the indexed order.
=> Each Unique cluster key value is stored only once in the each data
block.
=> they save disk space and improve perforence for many operations.
syn -
create index iname on cluster cname;
=> to drop an cluster
drop cluster cname;
*** cluster not deleted if cluster is not empty.
drop cluster cname including tables ;
drop cluster cname including tables cascade constraints ;
=>

More Related Content

What's hot (18)

SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statas
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
Introduction to MySQL - Part 2
Introduction to MySQL - Part 2Introduction to MySQL - Part 2
Introduction to MySQL - Part 2
 
Les09
Les09Les09
Les09
 
Sql analytic queries tips
Sql analytic queries tipsSql analytic queries tips
Sql analytic queries tips
 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
 
3. writing MySql plugins for the information schema
3. writing MySql plugins for the information schema3. writing MySql plugins for the information schema
3. writing MySql plugins for the information schema
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Assignment#02
Assignment#02Assignment#02
Assignment#02
 
Les11
Les11Les11
Les11
 
My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 
Dbmsmanual
DbmsmanualDbmsmanual
Dbmsmanual
 
Oracle training in hyderabad
Oracle training in hyderabadOracle training in hyderabad
Oracle training in hyderabad
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 

Similar to Database Oracle Basic

Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQLsuriyae1
 
Sql Queries
Sql QueriesSql Queries
Sql Querieswebicon
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sqlN.Jagadish Kumar
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
Mysqlppt
MysqlpptMysqlppt
MysqlpptReka
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentArun Sial
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricksYanli Liu
 
MYSQL
MYSQLMYSQL
MYSQLARJUN
 
MS SQL Server.ppt
MS SQL Server.pptMS SQL Server.ppt
MS SQL Server.pptQuyVo27
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)Ehtisham Ali
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-noteLeerpiny Makouach
 

Similar to Database Oracle Basic (20)

ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Oracle
OracleOracle
Oracle
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Chapter8 my sql revision tour
Chapter8 my sql revision tourChapter8 my sql revision tour
Chapter8 my sql revision tour
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
Dbms
DbmsDbms
Dbms
 
MYSQL
MYSQLMYSQL
MYSQL
 
MS SQL Server.ppt
MS SQL Server.pptMS SQL Server.ppt
MS SQL Server.ppt
 
Oracle sql tuning
Oracle sql tuningOracle sql tuning
Oracle sql tuning
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
 
Sql for dbaspresentation
Sql for dbaspresentationSql for dbaspresentation
Sql for dbaspresentation
 
Sql server introduction to sql server
Sql server introduction to sql server Sql server introduction to sql server
Sql server introduction to sql server
 

More from Kamlesh Singh

More from Kamlesh Singh (8)

ReactJS
ReactJSReactJS
ReactJS
 
Angular js book
Angular js bookAngular js book
Angular js book
 
Smart machines
Smart machinesSmart machines
Smart machines
 
Spring roo-docs
Spring roo-docsSpring roo-docs
Spring roo-docs
 
Oops Concept Java
Oops Concept JavaOops Concept Java
Oops Concept Java
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Java Basic day-1
Java Basic day-1Java Basic day-1
Java Basic day-1
 
Jvm
JvmJvm
Jvm
 

Recently uploaded

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Database Oracle Basic

  • 1. Nibble Matrix By Kamlesh Kumar Singh Database - Collection of data files. DataFile - collection of records(rows). Record(rows) - collection of fields. Field = set of informations. DBMS - Database Management System. A System which manage the database. Database Handler - each & every database has one database handler - that handle uthe database. DBMS - Database Management System. - Access / FoxPro / Excel RDBMS - Relational Database Management System. - SQL Server / Oracle upto 7.3 / sybase / MySQL. ORDBMS - Object Relational Database Management System. - Oracle8 oracle8 - Object, user define composite data types. OODBMS - Object Oriented Database Management System. - Oracle 8i & 9i & 10G i - internet programming. - java is a kind of internet programming. need for java - JVM , Oracle8i - JVM include - SQLJ - SQL Java programming. SQL - Structured Query Language - common language for all Databases. SQL - DDL - create / alter / drop, truncate DML - delete / insert / update
  • 2. DCL - grant / revoke DRL - select statement TCL - commit / rollback / savepoint. Codd's Rules - 12 rules + 1 zero rule = 13 rules . Codd's - < 6 rules support - DBMS >= 6 rules support - RDBMS. Oracle support 12.5 rules. .5 not supported by oracle that is view updation. views - simple view & complex view auto updation - simple views updatable but complex view - not auto updatable. work with Oracle env -
  • 3. SQLPLUS - Oracle env ISQLPLUS - in 9i , for use oracle with web browser. ie - http://localhost/isqlplus --to create own database table. 1- without constraints 2 - with constraints constraints - not null - user can't insert into null values. unique - not null + not duplicate primary key - not null + not duplicate = can ref with other table foreign or reference key - child records. check - condition check at the DML operator(insert & update) time. default - if user not spacify value for a column then default value to be inserted. constraints name - database server assign (auto) user (explicit)
  • 4. data type number(4) - int only number(7,2) - floating value 99999.99 char - fixed length varchar & varchar2 - dynamic , but has max limit lob - upto 4 gb long - upto 2 gb date - for date & time. user define composite data type - Object. - to add constraints in table . 1 - at the table creation time 2 - after table creation. -- to create a table without constraints. create table semp ( empno number(4), ename varchar(20), sal number(7,2), deptno number(2) ) -- to create a table with constraints.
  • 5. create table femp ( empno number(4) constraints myno primary key, ename varchar(20) not null, sal number(7,2) constraints mysal check(sal> 5000), deptno number(2) default(10) check(deptno in(10,20,30,40)) ) - to insert default value in table column insert into cemp(empno,ename,sal) values(1003,'Amar',9299); - to add extra column in table alter table cemp add jdate date - to change the column size alter table cemp modify sal number(8,2) *** but for decreasing column size table should be empty
  • 6. - to add constraint after table creation. alter table bemp add constraints mys check(sal<50000) - to enable or desable constaints - for disable alter table cemp disable constraints mysal; - for enable alter table femp enable constraints mysal; *** for enabling constraints condition must be fullfil - to drop a constraints alter table femp drop constraints mysal - to set unused column alter table cemp set unused column jdate - to drop all unused columns
  • 7. alter table cemp drop unused columns - to drop an column alter table cemp drop column deptno - to rename table rename cemp to cc; - to create synonym create synonym c for femp - to create table with foreign key create table fincr ( empno number(4) references femp(empno), amount number(5) ) - create table fbonus
  • 8. ( empno number(4) references femp(empno) on delete cascade, amount number(5) ) on delete cascade option - if parent record deleted then child record auto deleted. else delete child record first then parent record deleted. Joins - to select data from more then one tables. type - 1- Equi Join - when common column exist in both tables. select empno,ename,sal,e.deptno,dname from emp e,dept d where e.deptno=d.deptno 2- Non Equi Join - when common column not exist in both table. select empno,ename,sal,grade from emp,salgrade where sal between losal and hisal 3- Cross Join - table join without any condition. result - Ist table each row * each row of IInd table select empno,ename,sal,e.deptno,dname from emp e,dept d
  • 9. 4- Outer Join - like equi join. Left Outer join - display those record also which r exist in IInd not exist in Ist. select empno,ename,sal,e.deptno,dname from emp e,dept d where e.deptno=d.deptno(+) 10 20 30 40 - not 50 Right outer join - display those record also which r exist in Ist not exist in IInd. select empno,ename,sal,e.deptno,dname from emp e,dept d where e.deptno(+)=d.deptno 10 20 30 50 - not 40 5- Self Join - when one table use a multiple table.
  • 10. - list of all emp with his/her manager name. select e.ename,m.ename as manager from emp e,emp m where e.mgr = m.empno - List of all emp whose sal > their manager. select e.ename,m.ename as manager from emp e,emp m where e.mgr = m.empno and e.sal > m.sal - List of all emp who join company before their manager. VIEWS :-> ----- * A view is a logical table based on a table or another view. * A view contains no data of its own. but it is like a window through witch data from table can be viewed or change. * The tables on which a view is based are called base tables. * the view is stored as a select statement in the data dictionary. * the changes in the table are automatically reflected in the views. Advantages of a view : -> * to make a complex queries easy. * to allow data independence . * securities.
  • 11. views types -> 1> Simple 2> complex Deff. between Simple & complex views : - ------------------------------------ Feature Simple Complex 1> no. of tables one one or more 2> contain function no yes 3> contain groups no yes of data 4> DML through views yes not allowed view type simple view - with single table complex view - with more then one table or with functions read only view - read only. force view - view created without having base table
  • 12. in line view - when select statement pass as a object in from clause Q1. -> create a view, amit, that contains details of employees in deptno 10 . Ans. create or replace view amit as select empno,ename,sal,deptno from emp where deptno=10; with read only option. - > to used for create a read only view --------------------- Q2. -> create read only view for employees of dept 10 ? Ans. -> create view nnn as select empno,ename,sal from emp where deptno=10 with read only; with check option --> when the WITH CHECK OPTION CLAUSE is used , any DML statement that ----------------- manipulate rows that can be not be selected by a VIEW ,are rejected
  • 13. ** to create a view with check option - create view a2 as select empno,ename,sal,deptno from emp where deptno=10 with check option; * in this view we can insert only in dept 10 not in any other depts. * to select data from a view select * from viewname; * to create a complex view . CREATE VIEW CCC3 AS SELECT EMPNO,ENAME,SAL,E.DEPTNO,D.DNAME FROM EMP E,DEPT D * create table with keys(primary key , Foreign key) -->with Primary key CREATE TABLE M_DEPT ( DEPTNO NUMBER(2) CONSTRAINTS DE PRIMARY KEY, DNAME VARCHAR2(10) NOT NULL ); --> with foreign key
  • 14. CREATE TABLE M_EMP ( EMPNO NUMBER(4) PRIMARY KEY, ENAME VARCHAR2(10), SAL NUMBER(7,2), DEPTNO NUMBER(2), FOREIGN KEY(DEPTNO) REFERENCES M_DEPT(DEPTNO) ); --> create view CREATE VIEW CCC4 AS SELECT EMPNO,ENAME,SAL,E.DEPTNO,D.DNAME FROM M_EMP E,M_DEPT D WHERE E.DEPTNO=D.DEPTNO -- force view - view create without a base table. create force view amit6 as select * from baba ---------> The view must not contain any of the following constructs: A set operator A DISTINCT operator An aggregate or analytic function A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause
  • 15. A collection expression in a SELECT list A subquery in a SELECT list A subquery designated WITH READ ONLY An inline view is a SELECT statement in the FROM-clause of another SELECT statement. In-line views are commonly used simplify complex queries by removing join operations and condensing several separate queries into a single query. This feature was introduced in Oracle 7.2. This feature is commonly referred to in the MSSQL community as a derived table, and in the Postgres community simply refers to it as a subselect (subselects are inline views + subqueries in Oracle nomenclature). [edit]Examples Example inline view: SELECT * FROM ( SELECT deptno, count(*) emp_count FROM emp GROUP BY deptno ) emp, dept WHERE dept.deptno = emp.deptno; Another good example of an inline view is: SELECT a.last_name, a.salary, a.department_id, b.maxsal FROM employees a, ( SELECT department_id, max(salary) maxsal FROM employees
  • 16. GROUP BY department_id ) b WHERE a.department_id = b.department_id AND a.salary = b.maxsal; Materialized view or snapshot-> it is one kind of physical table not a logical table. automatic updation not allowed. *to create a Materialized view -> create materialized view cc2 as select * from m_emp; or create snapshot cc2 as select * from m_emp -to drop a materialized view drop materialized view viewname * Materialized view not created if table does not contain a primary key constraint. * for creating materialized view user should have dba privileges. the DBA can create a user by using the create user command, once a user is created the DBA can grant the specific system privileges to a user.
  • 17. Schema - collection of Objects such as tables / views & sequences. user schema - collection of users Object. Data Securities - System Securities - System privileges - gain access to the database. Data Securities - Object privileges - manipulates the content of the database Objects. Object privileges vary from Object to Objects. Role - group of privileges , role is a kind of intermediate user. oracle server provide the 3 standard role. connect - to connect with database resource - to use the data base resources dba - for DBA task (database Administration ) - to create user define role - create role baba;
  • 18. grant create session,create table , create procedure to baba; grant baba to singh; -- TO DROP A ROLE DROP ROLE BABA Grant - to assign the privileges revoke - to remove the privileges. System privileges - create session - for connect create table - for create table create view - for view creation create sequence - for sequence creation create procedure. - for function , procedure & package creation unlimited tablespace
  • 19. Object privileges - privileges table view sequence procedure alter y - y - delete Y Y - - execute - - - Y index Y - - - insert Y Y - - references Y - - - select Y Y Y - update Y Y - - = all public - for all users ** for DBA - user should have DBA privilege. -- to display list of all existsing. select * from all_user. -- to create a new user
  • 20. create user username identified by password -- to change the password alter user username identified by password; -- for connecting user should have connect / create session privilege. -- to assign Object privileges - grant select , insert , update on emp to singh. grant all on emp to public - for all user public - for all users grant select , insert , update on emp to singh -- TO DROP A USER DROP USER USERNAME DROP USER USERNAME CASCADE - DROP USER WITH ALL RELATED LINKS
  • 21. - for assign Object privileges grant select,insert , update on emp to singh; grant select,insert , update on emp to public; -- to assign select , insert & update privilege for all user. grant all on emp to public; -- to assign all privileges for all user. -- to revoke the Object privileges - revoke select , insert , update on emp from singh; with grant Option - Object privileges granted with grant option r revoked when the granter's previleges is revoked. sequence - sequence is used for auto number generation ,for serial no ,
  • 22. rollno / empno & more. syn - create sequence my start witn 1001 increment by 1 minvalue 1001 maxvalue 1010 cycle cache 3 attributes for sequence - nextval - next value from sequence currval - current value in sequence -- to alter seqnence alter sequence mys increment by 2 maxvalue 1020 cycle
  • 23. select ab.nextval from dual -- to use sequence in table insert into emp values(ab.nextval,'&name',&sal) -- to drop a sequence drop sequence ab; -- to display list of all sequence select * from user_sequences; Temporary Table :- --------------- used for Temporary result.data exist only for the duration of a transction or session .
  • 24. only visible with in a single transaction or session. no redo generated. created in user's temporary tablespace. syn:- create global temporary table ab ( eno number(4) primary key, ename char(22) ) on commit delete rows this table is for transction duration. * no data segment created. Indexing - An Oracle Server Index is a Schema Object that can speed up the retrieval of row by using a pointer. Indexes can be created explicit & implicit. if U do not have index on the column, then a full table scan will occur. implicit index - ORACLE itself creates indexes at the time of table creation, if a table definition contains a PRIMARY KEY. Explicit Index - that is created by user.
  • 25. create [UNIQUE] index INDEXNAME on TABLENAME[COLNAME]; *** to display list of all user indexes. select * from user_indexes; CLUSTERING - => Clusters r used for performance improvement. => Clustering is a method of storing tables that r related and often accessed together. => A cluster is group of rows from separate tables storing in the same disk block. => Clustered tables must have a common column called cluster column. => to Cluster tables the user must own the tables. *** if table is the part of cluster can't be partition. steps for creating clusters - => creating cluster
  • 26. create cluster cname(colname datatype) => creating cluster tables create table tname ( colname datatype primary key, colname datattype )cluster cname(colname) create table tname ( colname datatype references tname(colname), colname datattype )cluster cname(colname) => creating cluster indexes. => In a clustered index, the actual data is stored in the indexed order. => Each Unique cluster key value is stored only once in the each data block. => they save disk space and improve perforence for many operations. syn - create index iname on cluster cname;
  • 27. => to drop an cluster drop cluster cname; *** cluster not deleted if cluster is not empty. drop cluster cname including tables ; drop cluster cname including tables cascade constraints ; =>