Professional Documents
Culture Documents
Types of Databases :-
----------------------
=> OLTP is used to run business and OLAP is used to analyze business.
C create
R read
U update
D delete
Evolution of DBMS :-
---------------------
CUST
CID NAME ADDR => columns,fields,attributes
10 sachin mum
11 rohit del
12 ravi hyd => row,record,tuple
=> every table must contain primary key to uniquely identity the
records.
Ex :- ACCNO,EMPID,CUSTID,AADHARNO,PANNO
ORDERS CUST
ORDID ORD_DT DEL_DT CID(FK) CID(Pk) NAME ADDR
1000 20- 25- 10 10 sachin mum
1001 21- 28- 11 11 rohit del
1002 22- 29- 12 12 ravi hyd
RDBMS features :-
-----------------
A atomocity
C consistency
I isolation
D durability
NoSQL :-
-------
MongoDB
cassandra
RDBMS :-
CUST
CID NAME HNO STREET CITY STATE PIN
EMP
EMPID ENAME HNO STREET CITY STATE PIN
ORDBMS :-
ADT :- ADDR(HNO,STREET,CITY,STATE,PIN)
CUST
CID NAME ADDR
EMP
EMPID ENAME ADDR
summary :-
what is database ?
types of databases ?
what is dbms ?
types of dbms ?
what is rdbms ?
what is ordbms ?
---------------------------------------------------------------------
24-apr-21 ORACLE
=> ORACLE is basically rdbms product from oracle corp and also
supports features of ordbms and used to create and to manage database.
Development Administration
versions of ORACLE :-
---------------------
i => internet
g => grid
c => cloud
1 on premises server
2 on cloud server
26-apr-21
client/server architecture :-
-------------------------------
SERVER :-
1 DB
2 INSTANCE
CLIENT :-
---------
1 connects to server
2 submit requests to server
3 recieves response from server
client tools :-
---------------
https://www.oracle.com/database/technologies/oracle-database-software-
downloads.html#19c
https://blog.toadworld.com/2018/09/26/how-to-install-oracle-database-18c-on-windows
SQL :-
-------
27-arp-21
SQL
DDL DML DQL TCL DCL
create insert select commit grant
alter update rollback revoke
drop delete savepoint
truncate insert all
rename merge
flashback
purge
schema :-
----------
SERVER
DATABASE
USERS
TABLES
DATA
SERVER
ORCL
sys dba
system/TIGER dba
scott normal user
username :- system
password :- TIGER
OR
username :- system/TIGER
username :- system/TIGER
syntax :-
Example :-
=> above command creates a new user but user is dummy because
user is not having permissions.
28-apr-21
Datatypes in ORACLE :-
----------------------
Datatypes
CHAR NUMERIC DATE BINARY
ASCII UNICODE number(p) date bfile
char nchar number(p,s) timestamp blob
varchar2 nvarchar2
long nclob
clob
char(size) :-
-------------
ex :- NAME CHAR(10)
vijay-----
wasted
ravi------
wasted
=> in char datatype extra bytes are wasted so char is not recommended
for variable length fields and it is recommended for fixed length
fields.
ex :- STATE_CODE CHAR(2)
AP
TS
MH
COUNTRY_CODE CHAR(3)
IND
USA
AUS
VARCHAR2(size) :-
-----------------
=> allows character data upto 4000 chars.
=> recommended for variable length fields.
ex :- NAME VARCHAR2(10)
vijay-----
released
ravi------
released
PANNO CHAR(10)
VEHNO CHAR(10)
=> ascii char occupies 1 byte but a unicode char occupies 2 bytes.
NUMBER(p) :-
-------------
ex :- EMPID NUMBER(4)
10
100
1000
10000 => not accepted
NUMBER(P,S) :-
--------------
ex :- SALARY NUMBER(7,2)
5000
5000.50
50000.50
500000.50 => not accepted
5000.507 => accepted => 5000.51
5000.503 => accepted => 5000.50
DATE :-
-------
EX :- DOB DATE
TIMESTAMP :-
-----------
T TIMESTAMP
28-APR-21 5:03:20.123
--------- ------- ----
DATE TIME MS
BFILE / BLOB :-
---------------
29-apr-21 :-
Rules :-
---------
emp123 valid
123emp invalid
emp 123 invalid
emp*123 invalid
emp_123 valid
Example :-
EMP
EMPID ENAME JOB SAL HIREDATE
DESC :- (DESCRIBE)
-------------------
EX :- SQL>DESC emp ;
empid NUMBER(4),
ename VARCHAR2(10),
job VARCHAR2(10),
sal NUMBER(7,2),
hiredate DATE
Ex :-
SQL>COMMIT;
INSERTING NULLS :-
------------------
method 1 :-
method 2 :-
30-apr-21
Displaying Data :-
------------------
SQL = ENGLISH
queries = sentences
clauses = words
Operators in ORACLE :-
-----------------------
WHERE clause :-
---------------
SELECT columns/*
FROM tabname
WHERE condition ;
condition :-
-------------
=> OPERATOR must be any relational operator like > >= < <= = <>
=> if cond = true then row is selected
=> if cond = false then row is not selected
Examples :-
compound condition :-
---------------------
01-may-21
=> display employees working as clerk and earning more than 4000 ?
=> display employees earning more than 5000 and less than 10000 ?
Example :-
STUDENT
SID SNAME S1 S2 S3
1 A 80 90 70
2 B 30 60 50
IN operator :-
---------------
BETWEEN operator :-
--------------------
Question :-
a ERROR
b RETURNS ROWS
c RETURNS NO ROWS
d NONE
ANS :- c
NOTE :- use BETWEEN operator with lower and upper but not with
upper and lower.
03-may-21 :-
SELECT *
FROM emp
WHERE job IN ('clerk','manager')
AND
sal BETWEEN 5000 and 10000
AND
hiredate BETWEEN '01-JAN-21' AND '31-DEC-21' ;
scenario :-
products
prodid pname price category brand
SELECT *
FROM products
WHERE category='mobiles'
and
brand in ('realme','redmi','samsung')
and
price between 10000 and 20000 ;
2
CUST
CID NAME GENDER AGE ADDR CITY STATE
SELECT *
FROM cust
WHERE gender='M'
AND
city IN ('hyd','mum','del')
AND
age BETWEEN 20 AND 30 ;
LIKE operator :-
-----------------
wildcard chars :-
----------------
=> display employees where 'A' is the 2nd char in their name ?
DD-MON-YY
Question :-
-----------
A ERROR
B returns no rows
C returns clerk,manager,salesman rows
D returns only clerk
ANS :- D
ANS :- C
IS operator :-
--------------
summary :-
04-MAY-21
Display db name ?
Display version ?
ORDER BY clause :-
-------------------
=> ORDER BY clause is used to sort data based on one or more columns
either in ascending or in descending order.
SELECT columns/*
FROM tabname
[WHERE condition]
ORDER BY <col> [ASC/DESC]
SELECT empno,ename,job,sal,deptno
FROM emp
ORDER BY ename ASC ;
=> arrange employee list sal wise desc order ?
SELECT empno,ename,job,sal,deptno
FROM emp
ORDER BY sal DESC ;
=> arrange employee list experience wise and employee having max
experience should be displayed first ?
SELECT empno,ename,hiredate,sal,deptno
FROM emp
ORDER BY hiredate ASC ;
NOTE :-
SELECT *
FROM emp
ORDER BY 6 DESC;
=> above query sorts data based on 6th column i.e. SAL.
SELECT empno,ename,job,sal,deptno
FROM emp
ORDER BY 6 DESC; => ERROR
SELECT empno,ename,job,sal,deptno
FROM emp
ORDER BY 4 DESC ;
SELECT empno,ename,job,sal,deptno
FROM emp
ORDER BY 5 ASC;
=> arrange employee list dept wise asc and with in dept sal wise
desc order ?
SELECT empno,ename,sal,deptno
FROM emp
ORDER BY deptno ASC,sal DESC ;
1 A 3000 20 6 F 5000 10
2 B 2000 10 5 E 4000 10
3 C 4000 30 ==========> 2 B 2000 10
4 D 6000 20 4 D 6000 20
5 E 4000 10 1 A 3000 20
6 F 5000 10 3 C 4000 30
scenario :-
STUDENTS
SNO SNAME M P C
1 A 80 90 70
2 B 60 50 70
3 C 90 70 80
4 D 90 80 70
SELECT *
FROM STUDENTS
ORDER BY (M+P+C)/3 DESC,M DESC,P DESC ;
4 D 90 80 70
3 C 90 70 80
1 A 80 90 70
2 B 60 50 70
SELECT sno,sname,m,p,c,(m+p+c)/3
FROM students
ORDER BY (m+p+c)/3 DESC,m DESC,p DESC ;
INSERT
UPDATE
DELETE
INSERT ALL
MERGE
NULL assignment =
NULL comparision IS
=> increment sal by 20% and comm by 10% those working as salesman
and joined in 1981 year ?
UPDATE emp
SET sal = sal + (sal*0.2) , comm = comm + (comm*0.1)
WHERE job='SALESMAN'
AND
hiredate LIKE '%81';
=> increment salaries by 10% those having more than 40 years of expr ?
UPDATE emp
SET sal=sal+(sal*0.1)
WHERE (SYSDATE-HIREDATE)/365 > 40 ;
06-may-21
DELETE command :-
------------------
FLASHBACK :-
------------
Example :-
SELECT *
FROM emp
AS OF TIMESTAMP(SYSDATE-INTERVAL '5' MINUTE);
=> get the data that exists 5 mins back and insert that data into
current emp table ?
-------------------------------------------------------------------
CREATE
ALTER
DROP
TRUNCATE
RENAME
FLASHBACK
PURGE
ALTER command :-
----------------
1 add columns
2 drop columns
3 rename column
4 modify a column
incr/decr field size
changing datatype
Adding columns :-
-----------------
=> after adding by default the new column is filled with NULLs.
to insert data into this new column use UPDATE command.
Droping column :-
-----------------
Renaming a column :-
---------------------
rename alias