SlideShare a Scribd company logo
1 of 78
RDBMS
M.G. Mona Visalakshi
 DATA : Collection of Information
 DATABASE : Collection of interrelated data in
contiguous locations in the form of table.
 DBMS : is a set of program that enable users to
create and maintain a database.
 RDBMS : It supports largest of databases .It also
provide access to many concurrent users.
DataBase Management System
(DBMS)
Database system consists of two parts :
DBMS : is a set of program that organizes
and maintains the information.
Database Application : the program that
allows us to view, retrieve and update
information stored in the DBMS.
Data Structure
Name Roll_no Address
Anu CA101 Madurai
Hari CA114 Chennai
Table (ie) contain rows & column
(eg) : students_details -------- Entity
---Attributes
Table Properties
Formal Relational
 Tuple
 Cardinality
 Attribute
 Degree
 Primary Key
Informal Equivalents
 Row, Record
 No. of rows
 Column, Field
 No. of Column
 Unique identifier
Relationship among data
One – to – One.
One – to – Many. (or Many – to – One)
Many – to – Many.
Relational DataBase Management
System
(RDBMS)
The DBMS whose designed is based on
relational theory in mathematics is called
RDBMS.
RDBMS packages are Oracle, Sybase and
Informix etc.
It supports largest of databases .It also
provide access to many concurrent users.
Difference between DBMS &
RDBMS
DBMS: It allows only one person to access
the database at a given time.
RDBMS: It allows many users
simultaneously to access the database.
ORACLE
 Oracle is an Object Relational Database
Management system (ORDBMS)
 Oracle database offers capabilities of both
relational and object oriented database systems.
 Oracle products are based on a concept called
Client/Server Technology
Tools of Oracle
SQL * Plus : Structured Query Language, we can
store, retrieve, edit and run SQL commands.
PL/SQL : PL/SQL block can contain any number
of SQL statement integrated with flow of control
statement.
Forms : For generating and executing forms
based applications.
Reports : For displaying and printing reports.
Structured Query Language
(SQL)
Oracle’s database language is SQL which is
used for storing and retrieving information.
A table is a primary database object of SQL
that is used to store data.
SQL supports the following commands.
DDL, DML,TCL
DataType
Character
Number
Date
Raw
LOB (CLOB,BLOB)
BFILE
Character Datatype
 Char(n)
1. fixed length character
string,
2. it store alphanumeric
values,
3. size is between 1-255
bytes.
 (eg) name char(25)
 varchar(n)
1. variable length character
string,
2. it store alphanumeric
values
3. size is between 1-2000
bytes.
 (eg) roll_no varchar2(6)
Back
Number Datatype
we can store +ve, -ve, zero, fixed point,
floating point.
Syntax :
Column_name number { p=38, s=0}
Column_name number(p)
Column_name number(p,s)
(eg) age number(2)
price number(5,2)
Back
Date Datatype
It is use to store date and time.
It has fixed length of 7 bytes
Default date datatype is “dd-mon-yy”
To view the system date sysdate()
(eg) dt_adm date
Back
Raw & Long raw datatype
It use to store byte oriented data like binary
data or byte string. (graphic images and
digitized sound)
The maximum size of datatype is 255 bytes.
Only storage and retrieval of data are possible,
manipulation of data cannot be done.
The maximum size of long raw datatype is
2GB.
Back
Data Definition Language
(DDL)
1. Create – to create new table
Syntax :
Sql> create table <table_name>
(column definition1,
column definition2……….);
(eg)
Sql> create table stud_det
(name char(10), roll_no varchar2(6),
age number(2));
Data Definition Language
(DDL)
2. Alter – to modify the existing (or) add new field.
Syntax :
Sql> alter table <table_name> modify or add
(column definition1, …….);
(eg)
Sql> alter table stud_det modify (name char(20));
Sql> alter table stud_det add (address varchar2(20));
Data Definition Language
(DDL)
3. Drop – to drop the table structure.
Syntax :
Sql> drop table <table_name> ;
(eg)
Sql> drop table stud_det ;
Data Definition Language
(DDL)
4. Truncate – values in the table are deleted
Syntax :
Sql> truncate table <table_name> ;
(eg)
Sql> truncate table stud_det ;
Data Manipulation Language
(DML)
1. insert – to add one or more rows to a table.
Syntax :
Sql> insert into <table_name> values
(list of data);
(eg)
Sql> insert into stud_det values
(‘Arul’,’08CA01’,20,’madurai’);
Data Manipulation Language
(DML)
To insert more than one record to a table.
(eg)
Sql> insert into stud_det values
(‘&name’,’&roll_no’,&age,’&address’);
Sql>/
Sql> enter the name:
enter the rollno:
enter the age:
Data Manipulation Language
(DML)
2. Select – query is a request for information.
Syntax : To view the whole table.
Sql> select * from <table_name>;
Syntax : To view the particular column.
Sql> select <column_name> from <table_name>;
Syntax : To view only the particular row.
Sql> select <column_name> from <table_name> where
<column_name>=‘values’;
Data Manipulation Language
(DML)
Syntax : To view Selecting distinct row .
Sql> select distinct<column_name> from
<table_name>;
To order the column name in ascending order.
Sql>select name from stud_det where course=‘MCA’
order by name;
To order the column name in descending order.
Sql>select * from stud_det order by name,roll_no desc;
Data Manipulation Language
(DML)
3. update – to alter the column values in a table.
Syntax :
Sql> update <table_name> set
<column_name>=‘value’ where condition;
(eg)
Sql> update item set price=100.50 where prod_id=101;
Sql> update item set price=100.50 where prod_id
in(select prod_id from product);
Data Manipulation Language
(DML)
4. delete – to delete particular rows.
Syntax :
Sql> delete from <table_name> where
condition;
(eg)
Sql> delete from stud_det where
roll_no=’08CA01’;
Transaction Control Language
(TCL)
1. commit – to end a transaction.
Syntax :
Sql>commit work;
Or
Sql>commit;
Transaction Control Language
(TCL)
2. rollback – it is used to undo the current
transaction.
Syntax :
Sql> rollback to savepoint save_pt;
Transaction Control Language
(TCL)
3. savepoint – it is used to identify a point in a transaction to
which we can later rollback
Syntax :
Sql> savepoint save_pt;
(eg)
Sql> update order_info set total=7000 where id=101;
Sql>savepoint sp1;
Sql> update order_info set total=7200 where id=102;
Sql>savepoint sp2;
Sql>rollback to savepoint sp1;
Data Control Language (DCL)
1. Grant – the user wants to share an object with others, the
appropriate privilege can be granted on that particular
object
Syntax :
Sql> grant privileges on<object_name> to <username>;
Object_name – table_name
Privileges – insert, select, update, delete
(eg)
Sql> grant select, insert on customer to accounts;
Data Control Language (DCL)
2. Revoke –to withdraw the privileges which has
been granted to a user.
Syntax :
Sql> revoke privileges on<object_name> from
<username>;
(eg)
Sql> revoke select, insert on customer from
accounts;
Integrity Constraints
A mechanism used by oracle to prevent
invalid data entry into the table.
Domain integrity constraints.
Entity integrity constraints.
Referential integrity constraints.
Domain Integrity Constraints.
‘not null’ constraint
(eg)
Sql> create table customer (cust_id number(6)
constraint cust not null, name varchar2(20));
‘check’ constraint
(eg)
Sql> create table order_info (order_id number(4)
constraint checkit check (order_id>100),
orderdate date, price number(7,2));
Entity Integrity Constraints.
‘unique’ constraint
To prevent the duplicate values of a specified
column.
This constraint can also allow null values.
(eg)
Sql> create table price (prod_id number(6)
constraint prod_cons unique, stdprice
number(6,2), minprice number(8,2));
Entity Integrity Constraints.
‘primary key’ constraint
To avoid the duplicate values of a specified
column.
This constraint does not allow null values.
(eg)
Sql> create table price (prod_id number(6)
constraint prod_cons primary key,
stdprice number(6,2), minprice
number(8,2));
Referential Integrity Constraint
It establishes relationship between the two table
have the same column.
Column in the parent table as primary key and
same column in the child table as foreign key.
(eg) create table product (prod_id number(6)
constraint prd_fk references price (prod_id),
prod_name varchar2(20));
On delete cascade clause
The rows under the referenced key column in
a parent table are deleted, then all rows in
the child table with dependent foreign key
column will also be deleted automatically.
(eg) create table product (prod_id number(6)
constraint prd_fk references price
(prod_id)on delete cascade, prod_name
varchar2(20));
Operators in SQL
Arithmetic operator
Comparison operator
Logical operator
Operators in SQL
1. Arithmetic operator:
To perform calculation based on values.
+, -, *, and /
(eg)
Sql> select prodid, stdprice, minprice,
stdprice + minprice from price where prodate=‘4-
june-07’;
Sql> select ordid, itemid, 100*(actualprice+qty) from
item where prodid=111;
Operators in SQL
2. Comparison operator
To compare one expression with another.
= , != , < , > , <= , >= , between, not,
in (to match with any value in the list),
like (to match a character pattern) and
is null (to check whether it is null).
Operators in SQL
2. Comparison operator
(eg)
Sql> select * from order_info where total>7000;
Sql> select * from order_info where not (custid=2
or custid=4);
Sql> select * from order_info where shipdate
in(’22-jan-07’,’03-feb-07’);
Operators in SQL
2. Comparison operator
LIKE operator which is used to search a character
pattern. The LIKE operator recognizes special
character like % and _
(eg)
Sql> select name, address, city from customer where
name like ‘v%’;
Sql> select * from customer where name like ‘v_e’;
Operators in SQL
3. Logical operator
To Combine the result of two conditions to
produce a single result.
AND , NOT and OR
(eg)
Sql> Select * from order_info where shipdate=
‘4-jan-07’ and total<9000;
SQL * Plus Functions
 Single Row Function
1. Date function
2. Numeric function
3. Character function
4. Conversion function
5. Miscellaneous function
 Group Function.
 Count Function
 Group by Clause
 Having Clause
Date Function
i) add_months :
Format – add_months(d,n)
d – date, n – no. of months
(eg)
Sql> select doadm,add_months(doadm,2) from student;
o/p -> 10-oct-00
15-nov-00
do_adm
10-aug-00
15-sep-00
Date Function
ii) last_day : It return the day of corresponding to the last day of
the month.
Format – last_day(d)
(eg)
Sql> select last_day(doadm) from student;
o/p -> 31-aug-00
31-aug-00
doadm
10-aug-00
15-sep-00
Date Function
iii) months_between : It is used to find the number of months
between two dates
Format – months_between(d1,d2)
d1 & d2 – date
(eg)
Sql> select months_between(dojoin,doadm) from student;
o/p -> 1.35
4.83
do_adm dojoin
25-sep-00 05-nov-00
15-may-00 10-oct-00
Date Function
iv) next_day :
Format – next_day(d,day)
d – date, day – any weekday
Sql> select next_day(doadm, ‘Friday’) from student;
v) Round : the date is round to the nearest date
format – (d [fmt])
d – date, fmt – year (or) month (or) day
Sql> select round(doadm, ‘year’) from student where
name=‘kumar’;
Character Function
Function Input Output
Initcap(char) Select initcap(‘hello’) from dual; Hello
Lower(char) Select lower(‘FUN’) from dual; Fun
Upper(char) Select upper(‘sun’) from dual; SUN
Ltrim(char,set) Select ltrim(‘XYZadams’,’XYZ’)
from dual;
Adams
Rtrim(char,set) Select rtrim(‘XYZadams’,’ams’)
from dual;
XYZad
Numeric Function
i) Abs
ii) Ceil(n)
iii) Cosn
iv) Exp(n)
v) Power(m,n)
vi) Mod(m,n)
vii) Round(m,n)
viii) Sqrt(n)
Conversion Function
i) To_char()
It convert date to a value of varchar2 datatype.
format: to_char(d, [fmt] )
(eg) select to_char(sysdate,’dd “of” fmmonth yyyy’) from
dual;
o/p -> 15th of October 2007
i) To_date()
(eg) select to_date(‘january 15 2006,’month-dd-yyyy) from
dual;
o/p -> 15-jan-06
Group Function
 A Group function return a result based on group
of rows.
1. Avg : (eg) select avg(total) from table_name;
2. Max : (eg) select max(cutid) from table_name;
3. Min : (eg) select min(ordid) from table_name;
4. Sum : (eg) select sum(total) from table_name;
Count Function
Count(*): count all the rows, including the duplicate
and null.
Count (column_name): count the no.of values
present in the column without including null.
Count (distinct col_name): similar to
count(col_name) but eliminates duplicate value
while counting.
Count Function
(eg) itemfile
Sql> select count(*) from itemfile;
Sql> select count(Q_hand) from itemfile;
Sql> select count(distinct P_cat) from itemfile;
item P_cat Q_hand It_rate
I201 Spares 40 100.50
I202 Spares 30 200
I203 Spares 30 500
1204 accession 1000
Group by Clause
Simultaneous usage of column name and
group function .
(eg)
Sql> select P_cat from customer group by
P_cat;
Having Clause
It is used to specify certain condition on rows,
retrieved by using group by clause.
(eg)
Sql> select P_cat, max(It_rate) from itemfile
group by P_cat having P_cat not in
(‘accession’);
Set Operators and Joins
Set operator combine the result of two queries into a
single one.
Union.
Union all.
Intersect.
Minus.
Set Operators and Joins
 Student1  student2
Name R_no
X 1
Y 2
Z 3
W 4
Name R_no
Y 2
Z 3
W 4
A 5
Set Operators and Joins
 Union : It return all distinct rows and selected by both
queries.
(eg)
Sql> select r_no from student1 union select r_no from
student2;
Output:
r_no
1
2
3
4
5
Set Operators and Joins
 Union all : It return all rows selected by either query include
duplicate.
(eg)
Sql> select r_no from student1 union all select r_no from student2;
Output:
r_no
1
2
3
4
2
3
4
5
Set Operators and Joins
 Intersect : It return only rows that are common on both the
queries.
(eg)
Sql> select r_no from student1 intersect select r_no from
student2;
Output:
r_no
2
3
4
Set Operators and Joins
Minus : It return all distinct rows selected only by
the first query and not by the second.
(eg)
Sql> select r_no from student1 minus select r_no from
student2;
Output:
r_no
1
Relating Data through Join
Concept.
The purpose of a join is to combine the data spread
across tables. The join is actually perform by the
‘where’ clause which combine the specified rows
of table.
Syntax:
Sql> select column from table1, table2 where
logical expression;
Relating Data through Join
Concept.
 Simple Join:
equi-join
non equi-join
Self Join
Outer Join
Simple Join
equi-join : it is based on equalities
(eg) sql> select * from item,ord_info where
item.ordid = order_info.ordid;
non equi-join : it specifies the relationship
between columns belonging to different table by
making use of relational operators.
(eg) sql> select * from customer, order_info where
customer.cust_id > order_info.cust_id and
customer.repid =10;
Self Join
 Joining of a table to itself is known as a self
join (ie) it joins one row in a table to another.
(eg) sql> select a.itemcode, a.itemdesc,
a.qty_hand, b.max_level from itemfile a,
itemfile b where a.qty_hand < b.max_level and
a.p_cat = ‘spares’ and a.itemcode=b.itemcode;
Outer Join
 It extends the result of a simple join. An
outerjoin return all the rows returned by simple
join as well as those rows from one table that do
not match any row from the other table. The
symbol(+) represent outerjoin.
Table aliases
 To prevent ambiguity in a query we include
table name in the select statement. It is use to
make multiple table queries shorter and more
readable.
(eg)
Sql> select c.*, d.itemcode, d.qty_ord from
ord_mast c, order_det d where c.order_no =
d.order_no;
Sub Queries
Nesting of queries, one within the
other is termed as a subquery.
It is used to retrieve data from tables
which depend on the value in the
table.
Sub Queries
(eg) student
name Roll_no course doadm dojoin
A 951 MCA 15-aug-07 20-sep-07
B 933 MCA 01-sep-07 25-sep-07
C 937 MCA 25-sep-07 05-nov-07
D 940 MCA 02-jul-07 07-aug-07
Back
Sub Queries
(eg) student1
name Roll_no course doadm dojoin
C 937 MCA 25-sep-07 05-nov-07
E 901 MCA 01-oct-07 21-sep-07
F 950 MCA 15-nov-07 30-nov-07
D 940 MCA 02-jul-07 07-aug-07
Back
Sub Queries
Sql> select * from student where Roll_no = (select
Roll_no from student1 where doadm=’02-jul-07’
and course=‘MCA’);
Output:
name Roll_no course doadm dojoin
D 940 MCA 02-jul-07 07-aug-07
Sub Queries
Subqueries can also return more than one value.
We should include operators like any, all, in
(or) not in between the comparison operator and
the subquery.
Note:
‘=any’ ----- in
‘!=all’ ----- not in
Sub Queries
(eg) student
name Roll_no mark1 Mark2
A 934 59 54
B 951 46 72
C 935 76 57
D 945 70 60
Back
Sub Queries
(eg) student1
name Roll_no mark1 Mark2
E 931 78 76
C 935 76 57
G 941 63 35
H 948 61 60
Back
Sub Queries
(eg) for usage of any operator
Sql> select * from student1 where mark1 < any (select mark1
from student where mark1 between 65 and 80);
Output : for inner query Mark1
76
70
Output :
name Roll_no mark1 mark2
G 941 63 35
H 948 61 60
Sub Queries
(eg) for usage of all operator
Sql> select * from student1 where mark1 > all (select mark1
from student where mark1 <60);
Output : for inner query Mark1
59
46
Output :
name Roll_no mark1 mark2
E 931 78 76
C 935 76 45
G 941 63 35
H 948 61 60
Multiple Subqueries
A subquery itself can contain a subquery.
(eg)
Sql> select * from ven_mast where vencode =
(select vencode from ord_mast where
orderno = (select orderno from ord_details
where qty_ord=100 and itemcode=‘i203’));

More Related Content

What's hot

Most useful queries
Most useful queriesMost useful queries
Most useful queries
Sam Depp
 
PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)
Buck Woolley
 

What's hot (20)

Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
R Get Started II
R Get Started IIR Get Started II
R Get Started II
 
R Get Started I
R Get Started IR Get Started I
R Get Started I
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Most useful queries
Most useful queriesMost useful queries
Most useful queries
 
Data handling in r
Data handling in rData handling in r
Data handling in r
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Data Management in Python
Data Management in PythonData Management in Python
Data Management in Python
 
Big Data Analytics Lab File
Big Data Analytics Lab FileBig Data Analytics Lab File
Big Data Analytics Lab File
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data Structure
 
SQL
SQLSQL
SQL
 
R reference card
R reference cardR reference card
R reference card
 
PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)
 
Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schools
 

Similar to Sql

hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
SANTOSH RATH
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 

Similar to Sql (20)

Oracle 11g SQL Overview
Oracle 11g SQL OverviewOracle 11g SQL Overview
Oracle 11g SQL Overview
 
Database Management Lab -SQL Queries
Database Management Lab -SQL Queries Database Management Lab -SQL Queries
Database Management Lab -SQL Queries
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
 
Assignment#01
Assignment#01Assignment#01
Assignment#01
 
Module02
Module02Module02
Module02
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
PO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - SqlPO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - Sql
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
lovely
lovelylovely
lovely
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
6_SQL.pdf
6_SQL.pdf6_SQL.pdf
6_SQL.pdf
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
 
Module 3
Module 3Module 3
Module 3
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
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
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
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
 
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
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

Sql

  • 2.  DATA : Collection of Information  DATABASE : Collection of interrelated data in contiguous locations in the form of table.  DBMS : is a set of program that enable users to create and maintain a database.  RDBMS : It supports largest of databases .It also provide access to many concurrent users.
  • 3. DataBase Management System (DBMS) Database system consists of two parts : DBMS : is a set of program that organizes and maintains the information. Database Application : the program that allows us to view, retrieve and update information stored in the DBMS.
  • 4. Data Structure Name Roll_no Address Anu CA101 Madurai Hari CA114 Chennai Table (ie) contain rows & column (eg) : students_details -------- Entity ---Attributes
  • 5. Table Properties Formal Relational  Tuple  Cardinality  Attribute  Degree  Primary Key Informal Equivalents  Row, Record  No. of rows  Column, Field  No. of Column  Unique identifier
  • 6. Relationship among data One – to – One. One – to – Many. (or Many – to – One) Many – to – Many.
  • 7. Relational DataBase Management System (RDBMS) The DBMS whose designed is based on relational theory in mathematics is called RDBMS. RDBMS packages are Oracle, Sybase and Informix etc. It supports largest of databases .It also provide access to many concurrent users.
  • 8. Difference between DBMS & RDBMS DBMS: It allows only one person to access the database at a given time. RDBMS: It allows many users simultaneously to access the database.
  • 9. ORACLE  Oracle is an Object Relational Database Management system (ORDBMS)  Oracle database offers capabilities of both relational and object oriented database systems.  Oracle products are based on a concept called Client/Server Technology
  • 10. Tools of Oracle SQL * Plus : Structured Query Language, we can store, retrieve, edit and run SQL commands. PL/SQL : PL/SQL block can contain any number of SQL statement integrated with flow of control statement. Forms : For generating and executing forms based applications. Reports : For displaying and printing reports.
  • 11. Structured Query Language (SQL) Oracle’s database language is SQL which is used for storing and retrieving information. A table is a primary database object of SQL that is used to store data. SQL supports the following commands. DDL, DML,TCL
  • 13. Character Datatype  Char(n) 1. fixed length character string, 2. it store alphanumeric values, 3. size is between 1-255 bytes.  (eg) name char(25)  varchar(n) 1. variable length character string, 2. it store alphanumeric values 3. size is between 1-2000 bytes.  (eg) roll_no varchar2(6) Back
  • 14. Number Datatype we can store +ve, -ve, zero, fixed point, floating point. Syntax : Column_name number { p=38, s=0} Column_name number(p) Column_name number(p,s) (eg) age number(2) price number(5,2) Back
  • 15. Date Datatype It is use to store date and time. It has fixed length of 7 bytes Default date datatype is “dd-mon-yy” To view the system date sysdate() (eg) dt_adm date Back
  • 16. Raw & Long raw datatype It use to store byte oriented data like binary data or byte string. (graphic images and digitized sound) The maximum size of datatype is 255 bytes. Only storage and retrieval of data are possible, manipulation of data cannot be done. The maximum size of long raw datatype is 2GB. Back
  • 17. Data Definition Language (DDL) 1. Create – to create new table Syntax : Sql> create table <table_name> (column definition1, column definition2……….); (eg) Sql> create table stud_det (name char(10), roll_no varchar2(6), age number(2));
  • 18. Data Definition Language (DDL) 2. Alter – to modify the existing (or) add new field. Syntax : Sql> alter table <table_name> modify or add (column definition1, …….); (eg) Sql> alter table stud_det modify (name char(20)); Sql> alter table stud_det add (address varchar2(20));
  • 19. Data Definition Language (DDL) 3. Drop – to drop the table structure. Syntax : Sql> drop table <table_name> ; (eg) Sql> drop table stud_det ;
  • 20. Data Definition Language (DDL) 4. Truncate – values in the table are deleted Syntax : Sql> truncate table <table_name> ; (eg) Sql> truncate table stud_det ;
  • 21. Data Manipulation Language (DML) 1. insert – to add one or more rows to a table. Syntax : Sql> insert into <table_name> values (list of data); (eg) Sql> insert into stud_det values (‘Arul’,’08CA01’,20,’madurai’);
  • 22. Data Manipulation Language (DML) To insert more than one record to a table. (eg) Sql> insert into stud_det values (‘&name’,’&roll_no’,&age,’&address’); Sql>/ Sql> enter the name: enter the rollno: enter the age:
  • 23. Data Manipulation Language (DML) 2. Select – query is a request for information. Syntax : To view the whole table. Sql> select * from <table_name>; Syntax : To view the particular column. Sql> select <column_name> from <table_name>; Syntax : To view only the particular row. Sql> select <column_name> from <table_name> where <column_name>=‘values’;
  • 24. Data Manipulation Language (DML) Syntax : To view Selecting distinct row . Sql> select distinct<column_name> from <table_name>; To order the column name in ascending order. Sql>select name from stud_det where course=‘MCA’ order by name; To order the column name in descending order. Sql>select * from stud_det order by name,roll_no desc;
  • 25. Data Manipulation Language (DML) 3. update – to alter the column values in a table. Syntax : Sql> update <table_name> set <column_name>=‘value’ where condition; (eg) Sql> update item set price=100.50 where prod_id=101; Sql> update item set price=100.50 where prod_id in(select prod_id from product);
  • 26. Data Manipulation Language (DML) 4. delete – to delete particular rows. Syntax : Sql> delete from <table_name> where condition; (eg) Sql> delete from stud_det where roll_no=’08CA01’;
  • 27. Transaction Control Language (TCL) 1. commit – to end a transaction. Syntax : Sql>commit work; Or Sql>commit;
  • 28. Transaction Control Language (TCL) 2. rollback – it is used to undo the current transaction. Syntax : Sql> rollback to savepoint save_pt;
  • 29. Transaction Control Language (TCL) 3. savepoint – it is used to identify a point in a transaction to which we can later rollback Syntax : Sql> savepoint save_pt; (eg) Sql> update order_info set total=7000 where id=101; Sql>savepoint sp1; Sql> update order_info set total=7200 where id=102; Sql>savepoint sp2; Sql>rollback to savepoint sp1;
  • 30. Data Control Language (DCL) 1. Grant – the user wants to share an object with others, the appropriate privilege can be granted on that particular object Syntax : Sql> grant privileges on<object_name> to <username>; Object_name – table_name Privileges – insert, select, update, delete (eg) Sql> grant select, insert on customer to accounts;
  • 31. Data Control Language (DCL) 2. Revoke –to withdraw the privileges which has been granted to a user. Syntax : Sql> revoke privileges on<object_name> from <username>; (eg) Sql> revoke select, insert on customer from accounts;
  • 32. Integrity Constraints A mechanism used by oracle to prevent invalid data entry into the table. Domain integrity constraints. Entity integrity constraints. Referential integrity constraints.
  • 33. Domain Integrity Constraints. ‘not null’ constraint (eg) Sql> create table customer (cust_id number(6) constraint cust not null, name varchar2(20)); ‘check’ constraint (eg) Sql> create table order_info (order_id number(4) constraint checkit check (order_id>100), orderdate date, price number(7,2));
  • 34. Entity Integrity Constraints. ‘unique’ constraint To prevent the duplicate values of a specified column. This constraint can also allow null values. (eg) Sql> create table price (prod_id number(6) constraint prod_cons unique, stdprice number(6,2), minprice number(8,2));
  • 35. Entity Integrity Constraints. ‘primary key’ constraint To avoid the duplicate values of a specified column. This constraint does not allow null values. (eg) Sql> create table price (prod_id number(6) constraint prod_cons primary key, stdprice number(6,2), minprice number(8,2));
  • 36. Referential Integrity Constraint It establishes relationship between the two table have the same column. Column in the parent table as primary key and same column in the child table as foreign key. (eg) create table product (prod_id number(6) constraint prd_fk references price (prod_id), prod_name varchar2(20));
  • 37. On delete cascade clause The rows under the referenced key column in a parent table are deleted, then all rows in the child table with dependent foreign key column will also be deleted automatically. (eg) create table product (prod_id number(6) constraint prd_fk references price (prod_id)on delete cascade, prod_name varchar2(20));
  • 38. Operators in SQL Arithmetic operator Comparison operator Logical operator
  • 39. Operators in SQL 1. Arithmetic operator: To perform calculation based on values. +, -, *, and / (eg) Sql> select prodid, stdprice, minprice, stdprice + minprice from price where prodate=‘4- june-07’; Sql> select ordid, itemid, 100*(actualprice+qty) from item where prodid=111;
  • 40. Operators in SQL 2. Comparison operator To compare one expression with another. = , != , < , > , <= , >= , between, not, in (to match with any value in the list), like (to match a character pattern) and is null (to check whether it is null).
  • 41. Operators in SQL 2. Comparison operator (eg) Sql> select * from order_info where total>7000; Sql> select * from order_info where not (custid=2 or custid=4); Sql> select * from order_info where shipdate in(’22-jan-07’,’03-feb-07’);
  • 42. Operators in SQL 2. Comparison operator LIKE operator which is used to search a character pattern. The LIKE operator recognizes special character like % and _ (eg) Sql> select name, address, city from customer where name like ‘v%’; Sql> select * from customer where name like ‘v_e’;
  • 43. Operators in SQL 3. Logical operator To Combine the result of two conditions to produce a single result. AND , NOT and OR (eg) Sql> Select * from order_info where shipdate= ‘4-jan-07’ and total<9000;
  • 44. SQL * Plus Functions  Single Row Function 1. Date function 2. Numeric function 3. Character function 4. Conversion function 5. Miscellaneous function  Group Function.  Count Function  Group by Clause  Having Clause
  • 45. Date Function i) add_months : Format – add_months(d,n) d – date, n – no. of months (eg) Sql> select doadm,add_months(doadm,2) from student; o/p -> 10-oct-00 15-nov-00 do_adm 10-aug-00 15-sep-00
  • 46. Date Function ii) last_day : It return the day of corresponding to the last day of the month. Format – last_day(d) (eg) Sql> select last_day(doadm) from student; o/p -> 31-aug-00 31-aug-00 doadm 10-aug-00 15-sep-00
  • 47. Date Function iii) months_between : It is used to find the number of months between two dates Format – months_between(d1,d2) d1 & d2 – date (eg) Sql> select months_between(dojoin,doadm) from student; o/p -> 1.35 4.83 do_adm dojoin 25-sep-00 05-nov-00 15-may-00 10-oct-00
  • 48. Date Function iv) next_day : Format – next_day(d,day) d – date, day – any weekday Sql> select next_day(doadm, ‘Friday’) from student; v) Round : the date is round to the nearest date format – (d [fmt]) d – date, fmt – year (or) month (or) day Sql> select round(doadm, ‘year’) from student where name=‘kumar’;
  • 49. Character Function Function Input Output Initcap(char) Select initcap(‘hello’) from dual; Hello Lower(char) Select lower(‘FUN’) from dual; Fun Upper(char) Select upper(‘sun’) from dual; SUN Ltrim(char,set) Select ltrim(‘XYZadams’,’XYZ’) from dual; Adams Rtrim(char,set) Select rtrim(‘XYZadams’,’ams’) from dual; XYZad
  • 50. Numeric Function i) Abs ii) Ceil(n) iii) Cosn iv) Exp(n) v) Power(m,n) vi) Mod(m,n) vii) Round(m,n) viii) Sqrt(n)
  • 51. Conversion Function i) To_char() It convert date to a value of varchar2 datatype. format: to_char(d, [fmt] ) (eg) select to_char(sysdate,’dd “of” fmmonth yyyy’) from dual; o/p -> 15th of October 2007 i) To_date() (eg) select to_date(‘january 15 2006,’month-dd-yyyy) from dual; o/p -> 15-jan-06
  • 52. Group Function  A Group function return a result based on group of rows. 1. Avg : (eg) select avg(total) from table_name; 2. Max : (eg) select max(cutid) from table_name; 3. Min : (eg) select min(ordid) from table_name; 4. Sum : (eg) select sum(total) from table_name;
  • 53. Count Function Count(*): count all the rows, including the duplicate and null. Count (column_name): count the no.of values present in the column without including null. Count (distinct col_name): similar to count(col_name) but eliminates duplicate value while counting.
  • 54. Count Function (eg) itemfile Sql> select count(*) from itemfile; Sql> select count(Q_hand) from itemfile; Sql> select count(distinct P_cat) from itemfile; item P_cat Q_hand It_rate I201 Spares 40 100.50 I202 Spares 30 200 I203 Spares 30 500 1204 accession 1000
  • 55. Group by Clause Simultaneous usage of column name and group function . (eg) Sql> select P_cat from customer group by P_cat;
  • 56. Having Clause It is used to specify certain condition on rows, retrieved by using group by clause. (eg) Sql> select P_cat, max(It_rate) from itemfile group by P_cat having P_cat not in (‘accession’);
  • 57. Set Operators and Joins Set operator combine the result of two queries into a single one. Union. Union all. Intersect. Minus.
  • 58. Set Operators and Joins  Student1  student2 Name R_no X 1 Y 2 Z 3 W 4 Name R_no Y 2 Z 3 W 4 A 5
  • 59. Set Operators and Joins  Union : It return all distinct rows and selected by both queries. (eg) Sql> select r_no from student1 union select r_no from student2; Output: r_no 1 2 3 4 5
  • 60. Set Operators and Joins  Union all : It return all rows selected by either query include duplicate. (eg) Sql> select r_no from student1 union all select r_no from student2; Output: r_no 1 2 3 4 2 3 4 5
  • 61. Set Operators and Joins  Intersect : It return only rows that are common on both the queries. (eg) Sql> select r_no from student1 intersect select r_no from student2; Output: r_no 2 3 4
  • 62. Set Operators and Joins Minus : It return all distinct rows selected only by the first query and not by the second. (eg) Sql> select r_no from student1 minus select r_no from student2; Output: r_no 1
  • 63. Relating Data through Join Concept. The purpose of a join is to combine the data spread across tables. The join is actually perform by the ‘where’ clause which combine the specified rows of table. Syntax: Sql> select column from table1, table2 where logical expression;
  • 64. Relating Data through Join Concept.  Simple Join: equi-join non equi-join Self Join Outer Join
  • 65. Simple Join equi-join : it is based on equalities (eg) sql> select * from item,ord_info where item.ordid = order_info.ordid; non equi-join : it specifies the relationship between columns belonging to different table by making use of relational operators. (eg) sql> select * from customer, order_info where customer.cust_id > order_info.cust_id and customer.repid =10;
  • 66. Self Join  Joining of a table to itself is known as a self join (ie) it joins one row in a table to another. (eg) sql> select a.itemcode, a.itemdesc, a.qty_hand, b.max_level from itemfile a, itemfile b where a.qty_hand < b.max_level and a.p_cat = ‘spares’ and a.itemcode=b.itemcode;
  • 67. Outer Join  It extends the result of a simple join. An outerjoin return all the rows returned by simple join as well as those rows from one table that do not match any row from the other table. The symbol(+) represent outerjoin.
  • 68. Table aliases  To prevent ambiguity in a query we include table name in the select statement. It is use to make multiple table queries shorter and more readable. (eg) Sql> select c.*, d.itemcode, d.qty_ord from ord_mast c, order_det d where c.order_no = d.order_no;
  • 69. Sub Queries Nesting of queries, one within the other is termed as a subquery. It is used to retrieve data from tables which depend on the value in the table.
  • 70. Sub Queries (eg) student name Roll_no course doadm dojoin A 951 MCA 15-aug-07 20-sep-07 B 933 MCA 01-sep-07 25-sep-07 C 937 MCA 25-sep-07 05-nov-07 D 940 MCA 02-jul-07 07-aug-07 Back
  • 71. Sub Queries (eg) student1 name Roll_no course doadm dojoin C 937 MCA 25-sep-07 05-nov-07 E 901 MCA 01-oct-07 21-sep-07 F 950 MCA 15-nov-07 30-nov-07 D 940 MCA 02-jul-07 07-aug-07 Back
  • 72. Sub Queries Sql> select * from student where Roll_no = (select Roll_no from student1 where doadm=’02-jul-07’ and course=‘MCA’); Output: name Roll_no course doadm dojoin D 940 MCA 02-jul-07 07-aug-07
  • 73. Sub Queries Subqueries can also return more than one value. We should include operators like any, all, in (or) not in between the comparison operator and the subquery. Note: ‘=any’ ----- in ‘!=all’ ----- not in
  • 74. Sub Queries (eg) student name Roll_no mark1 Mark2 A 934 59 54 B 951 46 72 C 935 76 57 D 945 70 60 Back
  • 75. Sub Queries (eg) student1 name Roll_no mark1 Mark2 E 931 78 76 C 935 76 57 G 941 63 35 H 948 61 60 Back
  • 76. Sub Queries (eg) for usage of any operator Sql> select * from student1 where mark1 < any (select mark1 from student where mark1 between 65 and 80); Output : for inner query Mark1 76 70 Output : name Roll_no mark1 mark2 G 941 63 35 H 948 61 60
  • 77. Sub Queries (eg) for usage of all operator Sql> select * from student1 where mark1 > all (select mark1 from student where mark1 <60); Output : for inner query Mark1 59 46 Output : name Roll_no mark1 mark2 E 931 78 76 C 935 76 45 G 941 63 35 H 948 61 60
  • 78. Multiple Subqueries A subquery itself can contain a subquery. (eg) Sql> select * from ven_mast where vencode = (select vencode from ord_mast where orderno = (select orderno from ord_details where qty_ord=100 and itemcode=‘i203’));