You are on page 1of 34

UNIT-2 DATABASE MANAGEMENT SYSTEM

RELATION MODEL

Relational data model presented by Codd in 1970. It is based on set theory and order predicate logic. Relation is derived from set theory of mathematics. In this model, data is stored in relations. Relation is a formal term for table. A table in a database has uni ue table name that identifies its contents. !ach table called an intersection of ro"s and columns. #he organi$ation of data into relational tables is %no"n as the logical vie" of the database. A basic understanding of the relational model is necessary to effectively use relational database soft"are such as &racle,'icrosoft ()* (erver,(ybase, "hich are based on the relational model.

Characteristics of Relational Mo el!


#o eliminate all parent child relationships +represents data in ro"s,columns forms-. !ach tables is an independent entity and there is no physical relationship bet"een tables. #hey have a built.in support for uery language li%e A/(I ()* or )0!. Relational model of data management is based on set theory. #he user interface used in R' is non procedural because only "hat needs to be done is specified and not ho" it has to be done.

"rinci#le co$#onents o relational $o el! #he relational model consists of follo"ing three basic components1 %& Data str'ct're 2& Data inte(rit) *& Data $ani#'lation

The relational ata str'ct're!

Relation is a formal term of table. Ro". tuples, Column.attribute, /umber of tuples. cardinality, /umber of attributes. degree. A domain is pool of values from "hich the values of specific attributes of specific relations are ta%en.

Data Inte(rit) Integrity constraints provide a means of ensuring that changes made to the database by authori$ed users do not result in a loss of data consistency. #he main types of integrity constraints are1 2omain constraints o 'ost elementary form of integrity constraints. o (pecify the set of values that can be associated "ith an attributes. o !asily tested by the system+ ne" data items is entered -. /3**( o Represents a value for an attribute that is currently un%no"n or is not applicable for this tuple. o It can be ta%en to mean the logical value un%no"n. o It is a value that is not applicable to particular tuple. !nterprise constraints o Additional rules specified by the users or database administrators of a db. Referential integrity o A value that appears in one relation for a given set of attributes also appears

for a certain set of attributes in another relation. Referential integrity in the !Rmodel It arises fre uently. If "e are eri+in( relational , sche$e by constructing tables fro$ ER ia(ra$s then every relation arising from a relationship set has referential inte(rit) constraints & E-a$#le!

Referential inte(rit) in S.L 3sing ()*,primary %ey, candidate %ey and foreign %ey are defined as part of the create table statement as given belo"1 E-a$#le CR!A#! #A0*! depost4branch5name char4167, acc5no char4107,cust5name char4807 /&# /3**,balance integer467, primary %ey4 acc5no,cust5name7,foreign %ey 4branch5name7 references 0ranch, foreign %ey 4cust5name7 references Customer79

!ntity integrity o In a base relation, no attributes of a primary %ey can be null

A +anta(es of Relational Mo el (tructural Independence Conceptual (implicity 2esign, implementation, maintenance and usage ease :ood for ad.hoc re uests (imple to navigate :reater fle;ibility Disa +anta(es of Relational Mo el (ignificant hard"are and soft"are overheads /ot as good for transaction process modeling as hierarchical and net"or% models 'ay have slo"er processing times than hierarchical and net"or% models. T/E CATALOG

!very 20'( provide a catalog or dictionary function. #he catalog is the place "here all of the various schemas and all of the corresponding mappings are %ept. It is one of the fundamental components of the system.

#o perform this chec%, the system catalog has to store1


o o o

#he names of users authori$ed to use the 20'( #he names of the data items in the database. #he data items that each user can access, the types of access allo"ed1 for e;ample, insert, update, delete or read access. #he names of the data items in the database, #he types and si$es of the data items #he constraints on each data items

o o o

#he catalog contains detailed information 4'eta data7 regarding the various ob<ects that are of interest to the system itself.

TY"ES #he data types are a classification of a particular type of information. It is easy for programmer to distinguish bet"een different types of data. Relational model supports follo"ing data types1 1. Character4n7 8. =archar4n7 or character varying4n7 >. /umeric4p, 7 ?. Integer 6. (mall int @. Real,double precision 7. Alaot4n7 B. 2ate 9. #ime 10. #ime stamp
A type is set of values.

2efine o"n types! TY"E0t)#e na$e10#ossi,le re#resentation12 2elete types1 DRO" TY"E0t)#e na$e12

3EYS

Cey is a field or set of fields that uni uely I2 tuples in a relation. Aor every relation , "e need a %ey.

In some cases entire tuple is also used as a %ey. #here is no duplicate tuples "ithin a relation. (o "e need to be able to identify one or

more attributes called relation 4e)s& %& S'#er 4e)- An attribute or set of attributes that uni uely identifies a tuple "ithin a relation is called super %ey. 2& Can i ate 4e)- A super %ey has no proper subset is a super %ey "ithin a relation is called candidate %ey. It having 8 properties i.e., 3ni ueness, Irreducibility.+minimal super%ey*& Co$#osite 4e)- If a %ey consists of more than one attributes then it is called as composite %ey 5& "ri$ar) 4e)- #he candidate %ey that is selected to identify tuples uni uely "ithin the relation is called as primary %ey. 6& Alternate 4e)s- #he candidate %ey that are not selected to be the primary %ey. 7& 8orei(n 4e)- An attribute or set of attributes, "ithin one relation that matches the candidate %ey of some relation is called foreign %ey. RELATIONAL ALGEBRA A 9'er) lan('a(e is a lan('a(e in :hich a 'ser re9'ests infor$ation fro$ the ,& .'er) lan('a(e can ,e classifie as "roce 'ral lan('a(es #he user instructs the system to perform a se uence od operations on the database to compute the desired result Non #roce 'ral lan('a(es #he user describes the desired information "ithout giving a specific procedure for obtaining that information. RELATIONAL ALGEBRA Relational Al(e,ra is a theoretical language "ith operations that "or% on one or more relations to define another relation "ithout changing the original relation. 8or$al efinition of the relational al(e,ra! A basic e;pression in the relational algebra consists of either one of the follo"ing1
A relation in the database

A constant relation+it is "ritten by listing its tuples "ithin DE,for e;. D4A.181 Coimbatore , 60074A.>?6, salem,?0007E

*et E1 and E2 be relational algebra e;pressions. #hen, follo"ing , al are relational algebra e;pression1 E1

E2

E1-E2 E1E2 P(E1) "here F is a predicate on attributes in E1 S (E1)"here s is a list consisting of some of the attributes in !1 x(E1) "here ; is the ne" name for the result of !1 #he relational algebraic operations are divided into t"o groups1 3nary operations. select, pro<ect, rename, <oin and division 0inary operation. union, intersection, Cartesian product, and set difference !;amples1 there are t"o relations 2epositor Anu Arvind (athish /ithu (iva ;i< UNION

0orro"er Adams (athish =ino (iva Gari #irchy (alem #rivandrum !rode 'umbai

#heni Cbe (alem &oty !rode

#he result of the operation is the relation that includes all tuples that are either in table 1 or table 8 or in both. 2uplicates are eliminated. It is denoted by E1

E2

!;amples1 find the names of all ban% customers "ho have an account or loan or both

#he result of union is 1 2epositor Anu Arvind (athish /ithu (iva Adams =ino Gari ;ii< INTERSECTION #he result of intersection operation is a relation that includes all tuples that are in both the tables . #he intersection is denoted by E1

0orro"er
#heni Cbe (alem &oty !rode #irchy #rivandrum 'umbai

E2

!;ample1 find the names of customer "ho have both an account and loan. 2epositor (athish (iva ;iii< DI88ERENCE #he difference operation is denoted by table 1.table 8. #he result is the relation that contains all tuples in table 1 but not in table 8. !;ample 2epositor H0orro"er 2epositor

0orro"er
(alem erode

-0orro"er

Anu Arvind /ithu

#heni Cbe ooty

;i+<CARTESIAN "RODUCT It is also %no"n as cross product or cross <oins It is denoted by IJK #he result of Cartesian product of t"o relation "hich have J and Lcolumns is a realtion that has JML columns. #he resulting relation "ill have one tuple or each combination of tuples from each participating relation. Gence if the relations have n and m tuples respectively, then the CAR#!(IA/ FR&23C# "ill have nNm tuples. !;ample1 Consider t"o relations1 Fublisher5info and 0oo%5info Fublisher5info Fub5code F18> F7B9 F?6@ /ame *a;mi charu pearson 0oo%5info 05I2 0111 0??? #itle (! 20'(

#he relation publisher5info has 8 columns and > tuples. #he realtion 0oo%5info has 8 columns and 8 tuples. (o the Cartesian product has ? columns 48M87 and @ tuples 4>N87. #he Cartesian product of publisher5info and 0oo%5info is Fublisher5info J 0oo%5info Fublisher5I2 F18> /ame *a;mi 0oo%5I2 0111 #itle (!

F7B9 F?6@ F18> F7B9 F?6@ The select o#eration!

charu pearson *a;mi charu pearson

0111 0111 0??? 0??? 0???

(! (! 20'( 20'( 20'(

#he select operation selects tuple that satisfy a given predicate. #he select operation is represented as follo"s1 O Pselect conditionQ4 R 7 #he symbol O is used to denote the select operator and the Pselection condition Q is an e;pressrion specified on the attributes of the relation R.the e;pression specified in the selection condition is made up of number of clauses of the form1 < attribute name > <comparison operator> <constant value> r < attribute name > <comparison operator> <attribute value> Rhere,

Pattribute nameQ is the name of an attribute4column7 of the relation R. Pcomparison operatorQ is one of the follo"ing comparison operators1S,T,U,V,Q,P. Pconstant valueQ is the constant value from the attribute domain. Clauses are connected by 0oolean operators A/2,&R,and /&# to form general selection condition. title 20'( (! &&F( author (ilber Fressman balagurus"am y publisher 'cgra" Fress mill year 8018 1999 8000 Frice @00 ?00 680

0oo%5id 0BB 08@ 099

!;amples1
1. #o display boo%s published in year 8000

(olution1 O yearS8000 4boo%7 &utput1 0oo%5id 099 title &&F( author publisher year 8000 Frice 680

balagurus"amy mill

8. (elect the tuples for all boo%s "hose publishing year is 8000 or price is greater than >00.

(olution1 O 4yearS8000 7 &R 4price Q>007 4boo%7 &utput1 0oo%5id 0BB 08@ 099 The #ro=ect o#eration! #he pro<ect operation selects certain columns from a table "hile discarding others. It removes any duplicate tuples from the result relation. #he pro<ect operation is represented by 1 WPattribute listQ4R7 #he symbol pi is used to denote the pro<ect operation and the attribute list is a list of attributes from the attributes of the relation R. the result of the pro<ect operation has only the attributes specified in the attributes list and in the same order as they appear in the list. Gence the degree4number of columns7 of the result is e ual to the number of attributes specified in the attributes list. title 20'( (! &&F( author (ilber Fressman balagurus"am y publisher 'cgra" Fress mill year 8018 1999 8000 Frice @00 ?00 680

!;amples 1. 2isplay all titles "ith author name. Wtitle,author 4boo%7 Title 20'( (! &&F( A'thor (ilber Fressman balagurus"amy

8. #o display all boo% titles "ith authors and price Wtitle,author,price 4boo%7 Title 20'( (! &&F( A'thor (ilber Fressman "rice @00 ?00

balagurus"amy 680

Co$#osition of select an #ro=ect o#eration #he relational operations select and pro<ect can be combined to form a complicated uery. !;amples1 #o display the titles of boo%s having price greater than >00. Wtitle 4O price Q >00 4boo%77 Title 20'( (! &&F( The rena$e o#eration In relational algebra, "e can rename either the relation or thr attributes or both. #he general rename operation can ta%e any of the follo"ing forms. i7 X(4ne" attribute names7 4 R 7

ii7 X(4 R7 iii7 X4ne" attribute names74 R 7 #he symbol X 4rho7 is used to denote the R!/A'! operator. I(K is the ne" relation and IRK is original relation. !;amples1 i7 X renamedtemp40name,Aname.pyear,bprice7

4boo% 7+ both relation name and the attribute names are

ii7 Xtemp4 boo%7+ only the relation name is renamediii7 X4bname,aname,pyear,bprice74 R 7+ only the attributes names are renamedADDITIONAL O"ERATIONS IN RELATIONAL ALGEBRA

(et intersection /atural <oin 2ivision operation Assignment operation

Nat'ral =oin o#eration! It is a binary operation that allo"s us to combine certain selection and a Cartesian product into one operation. It is denoted by the <oin symbol
It forms a cartesian product of its t"o arguments, performs a selection forcing e uality on those attributes that appear in both relation schemes and finally removes duplicated attributes. !;amples1 Consider t"o relations1 i7 ii7 !5code !001 !008 !008> employee, "ith attribute !5code and !5name salary, "ith attributes !5code and (alary !5code !001 !008 !008> (alary !5salary 80000 60000 8000

employee !5name Gari om Yay

#o display the names of all employess "ith salary, "e need to combine the employee and salary relations using Cartesian product as follo"s1

W!5name,(alary 4Oemployee,!5codeS salary.!5code 4employee Z salary77 #he above uery is re"ritten using natural.<oin as follo"s W!5name,(alary 4employee
#he output of the uery is1 employee !5name !5salary Gari 80000 &m 60000 Yay 8000 salary7

Di+ision! It defines a relation over the attributes C that consists of the set of tuples from R that match the combination of every tuple in (. [for all\ S)nta-! R ]( Acco'nt!
Acc5no C?6 08@B6 GGB9 De#ositor! C5name =ishnu (iva muthu Branch! 05name Cbe 'tp Athur 05city Coimbatore mettupalayam (alem Assets 600000 ?0000000 6900000 Acc5no C?6 08@B6 GGB9 05name Cbe 'tp athur 0alance 600 ?00 690

Assi(n$ent! It is convenient at times to "rite a relational algebra e;pression by assigning parts of it to temporary relation variables. It is denoted by ^ E>TENDED RELATIONAL ALGEBRA O"ERATIONS! 1. :enerali$ed pro<ection 8. Aggregate function %& Generali?e #ro=ection! It e;tends the pro<ection operation by allo"ing arithmetic functions to be used in the pro<ection list. WA1,A8,_,A/4!7 Rhere !1 realtion algebra e;pression !1"#2$#n1 An arithmetic e;pression involving constants and attributes of ! !;ample Wname, total,6 as percentage4student7

2& A((re(ate f'nction! It ta%es a collection of values and return single value as a result.
sum(salary)

(Employee_salary)

O'ter =oin It deal "ith missing information T)#es!

A. *eft outer <oin 0. Right outer <oin C. Aull outer <oin


Mo ification of the ata,ase! 2ifferent operations that modify the contents of the database are1

2eletion

r r-E

%&ere r is a relation an' E is relational al(ebra )uer*

Insertion

r rE

%&ere r is a relation an' E is relational al(ebra )uer*

3pdating r#1"#2"$#n(r)

DOMAIN RELATIONAL CALCULUS It uses the variable that ta%es their values from domain of attributes. It is closely related to the tuple relational calculus. It serves as the theoretical basis of the "idely used )0! language , <ust as relational algebra serves as the basis for the ()* language. 8or$al efinition! An e;pression in the domain relational calculus is of the form DPx1"x2"$"xn>+P(x1"x2"$xn), Rhere x1"x2"$xn MQ domain variables .

P SQ the case in the tuple relational calculus. An ato$ in the relational calc'l's has one of the follo:in( for$s!

Px1"x2"$"xn> r -&ere r is a relation on n attributes an' x1"x2"$"xn are 'omain variables or 'omain constants. x * -&ere x an' * are 'omain variables an' is aomparison operator . x c" -&ere x is a 'omain variable " is comparison operator an' c is a constant in t&e 'omain o# t&e attribute #or -&ic& x is a 'omain variable.

@e ,'il '# for$'lae fro$ ato$s ,) 'sin( the follo:in( r'les!


an atom is a formula. If P1 is formula, then so are F1 and 4F17. If P1 and P2 are formulae, then so are F1F8,F1F8,A/2 F1F8 If F14;7 is a formula in ;, "here ; is free domain variable , then ; 4F14;77 and ; 4F14;77 Are also formulae.

!;ample ueries1 Aind the loan5number, branch5name, and amount for loans of over `1800 H DPl, b, a Q a Pl, b, a Q loan a Q 1800E b Aind the names of all customers "ho have a loan of over `1800 H DPcQ a l, b, a 4Pc, l Q borro"er Pl, b, a Qloan aQ 18007E TU"LE RELATIONAL CALCULUS It is non procedural uery language. It describes the desired information "ithout giving a specific procedure for obtaining that information. A uery can e;pressed in tuple relational calculus as , DtaF4t7E i.e., it is the set of all tuples t such that predicate F is true for t. In t'#le relational calc'l's A

t+A-. denotes the value of tuple on attribute A t r H denotes tuple t in relation r. Consider the follo"ing relations1 loan *oan5no 0ranch5name *11 *1? *16 *1@ *17 *8> *9> 2epositor Cust5name Gayes Yohnson Yohnson Yones lindsay (mith turner 0orro"er Cust5name Adams Curry Yac%son <ones (mith (mith Rilliams !;amples1 Acc5no A108 A101 A801 A817 A888 A816 A>06 *oan5no *.1@ *.9> *.16 *.17 *.11 *.8> *.17 Round Gill 2o"nto"n Ferryridge Ferryridge 2o"nto"n Red"ood 'ainus

Amount 900 1000 16800 1600 1?000 8680 8@00

1. Aind all tuples from the depositor. Dtat depositor E 8. Aind the loan.no,branch5name and amount for loans of over 1600 D tat loan t+amount-Q1600E >. Aind loan5no of each loan "ith loan amount Q1600 D ta s loan 4t +loan5no-S s +loan5no-s+amount-Q16007E ?. Aind name and account numbers of all customer Dta s 2epositor 4t+cust5name- S s+cust5name- t+Acc5no- S s+Acc5no- E

8or$al efinition of t'#le relational calc'l's! A tuple.relational calculus e;pression is of the form, D t a F4t7 E Rhere F is a formula, several tuple variables may appear in a formula. A tuple variable is said to be free variables unless it is ualified by a or .4 there e;ists , for all7. #hus in t laonscustomer+ t+branch5name- S s+branch5name-7 t is a free variable s is a bound variable A t'#le relational for$'la is ,'ilt '# o't of ato$s& An ato$ has one of the follo:in( ter$s

s r B "here s is a tuple variable and r is relation sC-D 'C)DB "here s and u are tuple variables, ; is an attribute on "hich s is defines , y is an attributes on "hich u is defined,and is comparison operator. sC-D cB "here s is a tuple variable , ; is an attributes on "hich s is defined , is comparison operator and c is aconstant in the domain of attribute ;.

@e ,'il '# for$'lae fro$ ato$s ,) 'sin( the follo:in( r'les

An atom is a formula

If F1 is a formula , then so are F1 and 4F17. If F1 and F8 are formulae then so are F1F8, F1F8 and F1F8 . If F14s7 is a formula containing a free tuple variable s and r is a relation then sr4F14s7 and sr4F14s77 are also formulae.

E9'i+alence in t'#le relational calc'l's


"%"2 E 1 ;;"%<;"2<< t r;"%;t<< E 1 t r; "%;t<< "%"2 E1 ;"%< "2

S.L 8UNDAMENTALS (tructural )uery *anguage 4()*7 is the standard command set used to communicate "ith the relational database management systems. All tas%s related to relational data management creating tables, uerying the database for information, modifying the data in the database, deleting them, granting access to users and so on can be done using ()* Characteristics of S.L! ()* usage by its very nature is e;tremely fle;ible, It uses free form synta; that gives the user the ability to structure ()* statements in a "ay best suited to admins. !ach ()* re uest is parsed by the R20'( before e;ecution, to chec% for proper synta; and to optimi$e the re uest, 3nli%e certain programming languages, there is no need to start ()* statements in a particular column or to be finished in a single line. #he same ()* re uest can be"ritten in a variety of "ays

A +anta(e of S.L!

It is a high level language that provides greater degree of abstraction. Increased acceptance and availability of ()*. (imple and easy to learn

()* can handle comple; situations.

S.L ata t)#es! CGAR4n7.fi;ed length string of e;actly InK character =ARCGAR4n7. varying length string A*&A#. floating point number S.L o#erators! Arithmetic operators.Q 4 ,, N, ., M7 Comparisonoperators.Q4 S,Q,P,PS,QS,I/,A/L,A**,(&'!,0!#R!!/,!JI(#(7 *ogical operators.Q 4A/2, &R , /&#7 (et operators.Q 4 3/I&/,3/I&/A**,I/#!R(!C#,'I/3(7 T)#es of S.L co$$an s! ()* statements are divided into follo"ing types, Data Definition Lan('a(e;DDL<- used to create, alter and delete database Data Mani#'lation Lan('a(e;DML<- used to insert, modify and delete the data Data .'er) Lan('a(e ;D.L< - enables the users to uery one or more tables to get the information they "ant. Data Control Lan('a(e;DCL<-controls the user access to the database Transaction Control State$ents ;TCS< . manage all the changes made by the 2'* statements.

Data Definition Lan('a(e;DDL<! #he operations are, Create, Alter, #runcate, 2rop

Create. create ne" base table (ynta;1Create table table5name9 E-a$#le1 Create table student9

Alter. alter the e;isting table (ynta;1 Alter table tablename9

E-a$#le1 Alter table boo%9

#runcate. if there is no further use of records stored in a table and the structures has to be retained then the records alone can be deleted. S)nta-! #runcate table tablename9 E-a$#le1#runcate table boo%9 Reuse1 truncate table student reuse storage. 2!(C. vie" the structure of the table (ynta;1 2esc tablename

2rop. deleted the already e;isting base table. S)nta-! drop table tablename9 E-a$#le1 drop table boo%9

Data Mani#'lation Lan('a(e ;DML<! 2'* Commands are used to manipulate the data in the database. #his is done either by retrieving information from e;isting ro"s, entering ne" ro"s, changing e;isting ro"s or removing un"anted ro"s from tables in the database. 2'* Commands are1 (!*!C#, I/(!R#, 3F2A#! and 2!*!#!.

(elect. (electing a ro" from a table. #he (!*!C# statement is used to retrieve information from the database.

S)nta-! (!*!C# column name1, column name8_ AR&' tablename +RG!R! conditionE-a$#le! (!*!C# N AR&' course9

Insert. Inserting a ro" into a #able. A ne" ro" can be added to a table by means of the I/(!R# command. S)nta-! I/(!R# I/#& tablename 4column1, column8 _7 =A*3!( 4value1, value8 _7

3pdate. 3pdating a ro" or ro"s in a table. !;isting ro"s in a table can be modified using the 3F2A#! command. S)nta-! 3F2A#! tablename

(!# column name1 S value1, column name8Svalue8, ___ +RG!R! conditionE-a$#le! 3F2A#! course (!# course name S IIntroduction to &racleK RG!R! course id S 11@9

2elete. 2eleting Ro"s from a #able. #he 2!*!#! command is used to

remove e;isting ro"s from a table S)nta-! 2!*!#! AR&' tablename +RG!R! condition-9 E-a$#le! 2!*!#! AR&' course RG!R! course id S 11@9

Transaction Control Lan('a(e ;TCL<! #ransactional control is the ability to manage various transactions that may occur "ithin a relational database management system. Rhen a transaction is e;ecuted and completes successfully, the target table is not immediately changed, although it may appear so according to the output. Rhen a transaction successfully completes, there are transactional control commands that are used to finali$e the transaction. #here are three commands used to control transactions1 %< 2< *< COMMIT ROLLBAC3

SAFE"OINT

17 C&''I# Command. #he commit command saves all transactions to the database since the last C&''I# or R&**0ACC command.

S)nta-! commit +"or%-9 E-a$#le!()*Q C&''I# R&RC9 87 R&**0ACC Command. #he rollbac% command is the transactional control command used to undo transactions that have not already been saved to the database. #he rollbac% command can only be used to undo transactions S)nta-! ()*Qrollbac% +"or%-9 E-a$#le! ()*QR&**0ACC R&RC9 >7 (A=!F&I/# Command. A savepoint is a point in a transaction that you can roll the transaction bac% to "ithout rolling bac% the entire transaction. S)nta-! ()*Q(A=!F&I/# Set O#erators It is used to combine the results of t"o ueries into single one. 1. 3nion.union all is very similar to union9 ho"ever, it dismisses duplicate ro"s found across different select statements. 8. 3nion all. union all selects all ro"s from all select statements. >. Intersect. intersect only returns the ro"s that are found in all select statements. ?. 'inus. minus returns all ro"s from the first select statement e;cept those "ho are duplicated in a follo"ing select statement. Goins #he purpose of <oin is to combine the data spread across table. 1. Inner Yoin 4simple <oin7 . Chances are, youcve already "ritten an ()* statement that uses an inner <oin. It is the most common type of <oin. Inner <oins return all ro"s from multiple tables "here the <oin condition is met. d 8. &uter Yoin. Another type of <oin is called an outer <oin. #his type of <oin returns all ro"s from one table and only those ro"s from a secondary table "here the <oined fields are e ual 4<oin condition is met7. #he &uter <oin can be of three types. 1. *eft &uter Yoin 8. Right &uter Yoin >. Aull &uter Yoin

>. (elf Yoin. (ometime "e need to <oin a table to itself. #his type of <oin is called (elf <oin. It is one of the types of inner <oin "here both the columns belong to the same table. In this Yoin, "e need to open t"o copies of a same table in the memory. ?. /atural <oin. A natural <oin is a <oin statement that compares the common columns of both tables "ith each other. &ne should chec% "hether common columns e;ist in both tables before doing a natural <oin. S',9'er) /esting of ueries, one "ithin the other is called as sub uery. A statement containing a sub uery is called as parent statement. INTEGRITY 2ata integrity refers to the correctness and completeness of a data in a database. 2ata integrity falls into these categories1 1. !ntity Integrity1 !ntity integrity defines a ro" as a uni ue entity for a particular table. !ntity integrity enforces the integrity of the identifier column or the primary %ey of a table. 8 things,
o o

3/I)3! constraints FRI'ARL C!L constraints,

8. 2omain Integrity1 2omain integrity is the validity of entries for a given column. 8 things,
o o

CG!CC constraints /&# /3** constraints

>. Referential Integrity1 Referential integrity preserves the defined relationships bet"een tables "hen records are entered or deleted. TRIGGERS! It defines an action the database should ta%e "hen some database related event occurs. M'tatin( tri((er- it is a trigger that triggers itself. T)#es of tri((ers!

%& Ro: le+el tri((ers . #rigger once for each ro" in a transaction. It is created by using the for each ro" clause in the create trigger command. 2& State$ent le+el tri((ers.it e;ecute once for each transaction. #hey are the default type of triggers created using create trigger command. *& Before an after tri((ers . since the events that e;ecute triggers are database transactions, it can e;ecuter immediately before or after I/(!R#, 3F2A#! and 2!*!#!. "'r#ose of tri((ers! #o generate data automatically. #o enforce comple; integrity constraints #o maintain replicate tables. S)nta-! Create +or replace- tri((er trigger5name +0efore,After+2elete,Insert,3pdate +of column5name-&n +user- table5name +Aor each ro"-+Rhen conddition+( l bloc%-9 SECURITY A 20'( should provide a mechanism to ensure that only authori$ed users can access the database. ()* provides the :RA/# and R!=&C! statements to allo" security to be set up on the tables in the database. %& A'thori?ation i entifiers- #here are assigned to database users by the 20A and identify user. 2& O:nershi#- !ach ob<ect that is created in ()* has an o"ner. *& "ri+ile(es- there are the actions that a user is permitted to carry out on a given base table or vie". #he privileges are i& Select- to retrieve data from a table

ii& Insert- inserts ne" ro"s into tables iii& U# ate- modify ro"s of data from a table i+& Delete-delete ro"s of data from a table +& References- references columns of a named table in integrity +i& Usa(e- to use domains, character sets and translations

constraints

Grantin( #ri+ile(es to other 'sers 1 :rant statement is used to grant privileges on database ob<ects to specific users. S)nta-! :RA/# +privilege list, A** privileges&n ob<ect name #o Dauthori$ation id list,F30*ICE +RI#G :RA/# &F#I&/-

ALL #ri+ile(es- It is used to grant all privileges to user instead of having to specify the si; privileges individually. Re+o4in( #ri+ile(es fro$ 'sers1 A revo%e statement is used to ta%e a"ay all or some of the privileges that "ere previously granted to a user. S)nta-! R!=&C! +:RA/# &F#I&/ A&R-D privilege list,A** privilegesE&n ob<ectname AR&' Dauthori$ation id list,F30*ICE+R!(#RIC#,CA(CA2!-

ADFANCED S.L 8EATURES 'any of the more comple; features "ere introduced in relatively recent versions of the ()* standard and may not be supported by all database systems.

Create ta,le e-tensions! Create table _ li%e it is used to support application often re uire creation of tables that have the same schema as an e;isting table. More on S',9'eries! #he (ub ueries returns only one value. (uch (ub ueries are called scalar sub uery. %& S',9'eries in the select cla'se 2& S',9'eries in the fro$ cla'se

Advanced constructs for database update1

%& S',9'eries in the '# ate cla'se 2& Mer(e constr'cts& EMBEDDED S.L A language in "hich ()* ueries are embedded is referred to as a host language, and the ()* structures permitted in the host language called embedded ()*. S)nta-! !J!C ()* Pembedded ()* statementQ9 0efore e;ecuting any ()* statements, 1st connect to the database by using E>EC S.L CONNECT! 'serna$e USING! connect strin(2 ()* CA. ()* communications Area to report run time errors to the application program. E>EC S.L INCLUDE s9lca2 Rhenever statement. It is a directive to the precompiler to automatically generate code to handle errors after every ()* statement. /ost lan('a(e +aria,les! All host variables must be declared to ()* in a BEGIN DECLARE SECTIONHH&& END DECLARE SECTION bloc%.

Retrie+in( ata 'sin( c'rsors ! It divides ueries into t"o groups, (ingle ro" ueries and 'ulti ro" ueries. A cursor identifies the current ro" in the set of ro"s returned by the uery. #his allo"s the program to process the ro"s one at a time.

#he follo"ing statements let you define and manipulate a cursor1 1. 2eclare cursor . the 2!C*AR! C3R(&R statement is to define a cursor by giving it a name and associating it "ith a uery, as the follo"ing e;ample sho"s. S)nta-! !J!C ()* 2!C*AR! cursorname C3R(&R A&R (!*!C# statement9 8. &pen . the &F!/ statement is to e;ecute the uery and identify the active set. S)nta-1 !J!C ()* &F!/ cursorname9

>. Aetch . the A!#CG statement to retrieve ro"s from the active set and specify the output host variables that "ill contain the results. S)nta-! !J!C ()* A!#CG cursorname I/#& Dhost variable+indicator vari-+,-E ?. Close. Rhen done Aetching ro"s from the active set, you C*&(! the cursor to free the resources, such as storage, ac uired by &pening the cursor. S)nta-! !J!C ()* C*&(! cursorname9 DYNAMIC S.L #he dynamic ()* component of ()* allo"s programs to construct and submit ()* ueries at run time. 1. !;ecute immediate statement. #he ()* ueries e;ecute only once "e use this. S)nta-! !J!C ()* !J!C3#! I''!2IA#! 8. Frepare and !;ecute statements. #he ()* uery e;ecute more than once "e use this. S)nta-%1 !J!C ()* FR!FAR! statement/ame AR&' 4host variable, string literal7 S)nta- 21 !J!C ()* !J!C3#! statement/ame >. #he ()* 2escriptor Area 4()*2A7.place holders are one "ay to pass parameters to the !J!C3#! statement. An alternative is through a dynamic data structure called the ()*2A. ?. 2escribe statement. It ,returns descriptive information about a prepared ()* statement. S)nta-! !J!C ()* 2!(CRI0! (!*!C# statement

MISSING IN8ORMATION Any of the domains can also hold missing data. 3sers do not %no" the value of some item, so it may not be entered. 'issing information is defined as null values. Gere "e are having 8 special operators, 1. I( /3** for presence of nulls 8. I( /&# /3** for absence of null. FIE@S It is a virtual relation that does not necessarily e;isting the database but can be produced upon re uest by a particular user, at the time of re uest. %& Creatin( a Fie: (ynta;1 CR!A#! =I!R vie" name A( (!*!C# columns AR&' table RG!R! predicates9 2& U# atin( a Fie: (ynta;1 CR!A#! &R R!F*AC! =I!R vie" name A( (!*!C# columns AR&' table RG!R! predicates9 *& Dro##in( a Fie:! (ynta;1 2R&F =I!R vie" name9 5& Fie: resol'tion! #he merging of loo% up the definition and translate the re uest into an e uivalent re uest against the source tables of vie" and then perform the re uest. A +anta(es of +ie:s 2ata independence Reduced comple;ity Convenience

Customi$ation currency 2ata integrity Improved security Disa +anta(e of +ie:s 3pdate restriction (tructure restriction Ferformance Fie: $ateriali?ation It is used to store the vie" as a temporary table in the database "hen the vie" is first ueried and maintains the currency of the vie" as the underlying base tables are updated. INTRODUCTION TO DISTRIBUTED DATABASE A distributed database appears to a user as a single database but is, in fact, a set of databases stored on multiple computers. #he data on several computers can be simultaneously accessed and modified using a net"or%. !ach database server in the distributed database is controlled by its local 20'(, and each cooperates to maintain the consistency of the global database. Distri,'te DBMS1 #he soft"are system "hich permitted to manage the distributed database and also ma%es the distribution transparent to users. Distri,'te ata,ase Architect're!

It consists of a single logical database that is split into a number of fragments. !ach fragment I stored one or more computers under the control of a separate 20'(. 3sers access it through application. #he applications are1 Local a##lication an Glo,al a##lication ItKs have one global application 1. Gomogeneous 220'(. each 20 having same vendor

8. Geterogeneous 220'(. atleast 1 20 having different vendor Distri,'te #rocessin(

2istributed 20 applications use distributed transactions to access both local and remote data.

It includes, 1. 2ata fragmentation Gori$ontal fragmentation =ertical fragmentation 8. #ransparency Aragmentation #ransparency Replication #ransparency *ocation #ransparency >. 2istributed transaction *ocal transaction :lobal transaction A +anta(e of DDBMS! !conomics 'odular gro"th Improved performance Improved reliability Improved availability Improved shareability Disa +anta(e of DDBMS! Cost (ecurity Comple;ity

*ac% of standard Characteristics of DDBMS! Aragment may be replicated #he data is split into number of fragments. 8'nctions of istri,'te DBMS! 2ata trac%ing (ecurity 2istributed data recovery CLIENTISERFER DATABASE! #he client. server model consists of > parts, 1. Client. it is the machine running in the front end application. 8. (erver. it is the machine that runs the 20'(. (oft"are and handles it >. /et"or%. it enables remote data access through client.server e server.server communication A +anta(e! Increased performance Increased consistency Costs reduced both communication e hard"are cost T:o-tier client-ser+er architect're! #he traditional client, server environment that divides the application into the graphical user interface 4client7 and the data 4server7.

It provides a basic separation of tas%s #ier 1 H client #ier 8. server Three tier architect're! #oday the most "idely accepted form of client, server systems is the >.tier architecture. #he components of this architecture are1 #he presentation 4:3I7 or user services. 0usiness rules or business services 2ata server or data services

In all three.tired architecture , all layers interact "ith each other. #he client "or%s as a uery head and rules define ho" the uery ought to be addressed and "or%ed on. #he database provides the ans"er and the contents of the database. Advantage of > tiers1 Added modularity *oad balancing *ess e;pensive Application maintenance is centrali$ed.

You might also like