You are on page 1of 30

IITT COLLEGE OF ENGINEERING

DBMS
PRACTICAL FILE

SUBMITTED BY Ms. MEENAKSHI SHARMA DUSHMANTA NATH


(CSE-DEPARTMENT) IT-5TH SEM

SUBMITTED TO

8130111301

!!!!! 1 !!!!!

INDE"
SR NO. E"PERIMENT DATE SIGNATURE

01

INTRODUCTION TO ORACLE

02

DATA TYPES OF S#L

03

S#L COMMANDS

04

ENHANCING PERFORMANCE

05

GRANTING AND RE$OKING PERMISSIONS

06

%OINS

07

CONSTRAINTS

08

FUNCTIONS

!!!!! & !!!!!

INTRODUCTION TO ORACLE
CLIENT SER$ER COMPUTING ARCHITECTURE It consists of two or more computers designated as client machine running an application program which communicates with remote computer designated as server machine which serves request from client machine In !asic model of client server computing" #$%&' resides on server machine (he application program which resides on client machine interfaces with client software called middleware that are responsi!le for communicating request ) results !etween their application programs and #$%&'

CLIENTS CLIENTS LAN ' (AN CLIENTS

RDBMS SER$ER

DATA STORAGE

PRINTERS

CLIENT (he *lient is the front +,$ application of a data!ase which interacts with the server (he *lient has more responsi!ilit- for accessing the data" it concentrates on the requests (he processing and presentation is managed !- the server SER$ER (he 'erver e.ecutes the /racle software and these with the function required for simultaneous and shared data e.cess (he server receives and processes the '0l and 123'02 declaration and that originates in the client application

!!!!! 3 !!!!!

(here are two t-pes of *lient 'erver &odel are (wo tier *lient 'erver &odel (hree tier client 'erver &odel (wo tier *lient 'erver &odel4 It improves the scala!ilit- !- allowing upto 1005s of user and is verfle.i!le for data sharing *lient requests services whereas the server it provides its services (here is one limitation of this tier i e the design of this architecture scales up (here are three components of client of this tier4 6ser '-stem interface 1rocessing &anagement $ata!ase &anagement (hree (ier *lient 'erver &odel4 7hen the less software is on the client" there is less worr- a!out securit- 'ince the importance software is on a server and in a more controlled environment (he support and installation cost of maintaining the software on a single server is much less than tr-ing to maintain the same software on 1005s of 1*5s AD$ANTAGES OF CLIENT SER$ER MODEL It allows the user to wor8 in e.tensi!le form It can wor8 on an- t-pe of operating s-stem eg 6,I9" 2I,69" 7in :8 It provides the facilit- to esta!lish the lin8 !etween remote data!ases It provides the facilit- of fast accessing of information and processing of data %etter application performance and networ8 usage i e it reduces the networ8 time It is multiplatform and centrali;ed $istri!uted computing as the servers act as a focal point for data management 1rovides fle.i!ilit- and full utili;ation of all resources (he same data!ase is shared !- different clients

DISAD$ANTAGES OF CLIENT SER$ER MODEL %ottlenec84 If a significant portion of application la-er is moved to a server" the server ma!ecome a !ottle nec8 in the processing and distri!ution of data to the client 'erver limited resources will !e in over higher demanding !- the increasing no of resource consumers

!!!!! ) !!!!!

'ecurit- features4 It has to ta8e care of the securit- of the data!ase from unauthori;ed access ORACLE /racle is one of the powerful #$%&' product that provide efficient solutions for data!ase applications /racle is the product of /racle *orporation which was founded !- 2<7#+,*+ +22I'I/, in 1:77 (he first commercial product of oracle was delivered in 1:70 (he first version of oracle 2 0 was written in assem!l- language ,owada-s commonl- used versions of oracle are /#<*2+ 8" 8i ) :i /racle 8 and onwards provide tremendous increase in performance" features and functionalitFEATURES OF ORACLE *lient3'erver <rchitecture 2arge data!ase and 'pace &anagement *oncurrent 1rocessing =igh transaction processing performance =igh <vaila!ilit &an- concurrent data!ase users *ontrolled availa!ilit /penness industr- standards &anagea!le securit $ata!ase enforced integrit $istri!uted s-stems 1orta!ilit *ompati!ilitORACLE SER$ER TOOL /racle is a compan- that produces most widel- used server !ased multi>user #$%&' /racle server is a program installed on server hard>dis8 drive (his program must !e loaded in #<& to that it can process the user requests /racle server ta8es care of following functions /racle server tools are also called as !ac8 end ?unctions of server tool4 6pdates the data #etrieves the data sharing

!!!!! 5 !!!!!

&anages the data sharing <ccepts the quer- statements 123'02 and '02 +nforce the transaction consistencORACLE CLIENT TOOL /nce /racle engine is loaded into sever memor- user would have to log in to engine in order to wor8 done *lient tools are more useful in commercial application development It provides facilities to wor8 on data!ase o!@ects (hese are more commonlused in commercial applications /racle client tools are also called front end DDL * DATA DEFINATION LANGUAGE (he '02 sentences that are used to create these o!@ects are called $$25s or $ata $efinition 2anguage (he sql provides various commands for defining relation schemas" deleting relations" creating inde.es and modif- relation schemas $$2 is part of sql which helps a user in defining the data structures into the data!ase ?ollowing are the various $$2 commands are <lter ta!le ) *reate ta!le ) drop ta!le *reate inde. ) drop inde. *reate view ) drop view DML * DATA MANIPULATION LANGUAGE (he '02 sentences used to manipulate data within these o!@ects are called $&25s or $ata &anipulation 2anguage It is language that ena!les users to access or manipulate data as organi;ed !- appropriate data model %- data manipulation we have #etrieval of information stored in data!ase Insertion of new information into data!ase $eletion of information from data!ase &odification of data stored in data!ase (wo t-pes of $&2 are 1rocedural $&2 ,on>procedural $&2 ?ollowing are $&2 commands are 'elect 6pdate

!!!!! !!!!!

$elete Insert

DCL * DATA CONTROL LANGUAGE (he '02 sentences" which are used to control the !ehavior of these o!@ects" are called $*25s or $ata *ontrol 2anguage It is language used to control data and access to the data!ase ?ollowing are some $*2 commands are *ommit #oll!ac8 'ave point 'et transaction

DATA TYPES OF S#L

!!!!! + !!!!!

CHAR , (his data t-pe is used to store character strings values of fi.ed length (he si;e in !rac8ets determines the num!er of characters the cell can hold (he ma.imum num!er of characters Ai e the si;eB this data t-pe can hold is 255 characters '-nta. is *=<#A'IC+B +.ample is *=<# A20B $ARCHAR , (his data t-pe is used to store varia!le length alphanumeric data (he ma.imum this data t-pe can hold is 4000 characters /ne difference !etween this data t-pe and the *=<# data t-pe is /#<*2+ compares D<#*=<# values using non>padded comparison semantics i e the inserted values will not !e padded with spaces '-nta. is D<#*=<#A'IC+B +.ample is D<#*=<# A20B /# D<#*=<#2 A20B NUMBER , (he ,6&%+# data t-pe is used to store num!ers Afi.ed or floating pointB ,um!ers of virtuall- an- magnitude ma-!e stored up to 38 digits of precision ,um!ers as large as : :: E 10 to the power of 124" i e followed !- 125 ;eros can !e stored (he precision" A1B" determines the ma.imum length of the data" whereas the scale" A'B" determines the num!er of places to the right of the decimal If scale is omitted then the default is ;ero If precision is omitted values are stored with their original precision up to the ma.imum of 38 digits '-nta. is ,6&%+# A1" 'B +.ample is ,6&%+# A10" 2B LONG , (his data t-pe is used to store varia!le length character strings containing up to 2F% 2/,F data can !e used to store arra-s of !inar- data in values '-nta. is 2/,F A'IC+B +.ample is 2/,F A20B DATE , (his data t-pe is used to represent data and time (he standard format id $$>&&>GG as in 13>H62>85 (o enter dates other than the standard format" use the appropriate functions $ate (ime stores date in the 24>hour format %- default" the time in a date field is 12400400 am" if no time portion is specified (he default date for a date field is the first da- of the current month '-nta. is $<(+ LONG RA( , 2/,F #<7 data t-pes are used to store !inar- data" such as <'*II format 2/,F values cannot !e inde.ed" and the normal character functions such as '6%'(# cannot !e applied to 2/,F

!!!!! 8 !!!!!

$igiti;ed picture or image $ata loaded into columns of these data t-pes are stored without an- further conversion 2/,F #<7 data t-pe can contain up to 2F% Dalues stored in columns having 2/,F #<7 data t-pe cannot !e inde.ed '-nta. is 2/,F#<7 A'IC+B RA( , It is used to hold strings of !-te oriented data $ata t-pe can have a ma.imum length of 255 !-tes '-nta. is #<7A'IC+B TRANSACTION STATEMENTS COMMIT, < */&&I( ends the current transaction and ma8es permanent an- changes made during the transaction <ll transactional loc8s acquired on ta!les are released '-nta. is */&&I( Iwor8J Icomment te.tJK 7here 7or8 is optional and comment te.t is used to specif- comment ROLLBACK , < #/22%<*L does e.actl- the opposite of */&&I( It ends the transaction !ut undoes an- changes made during the transaction <ll transactional loc8s acquired on ta!les are released '-nta. is #/22%<*L I7/#LJ I(/ I'<D+1/I,(J save pointJ 7here 7/#L is optional and is provided for <,'I compati!ilit- '<D+1/I,( is optional and is used to roll!ac8 a partial transaction" as far as the specified save point '<D+1/I,( is a save point created during the current transaction

SA$EPOINT , '<D+1/I,( mar8s and saves the current point in the processing of a transaction 7hen a '<D+1/I,( is used with a #/22%<*L statement" parts of a transaction can !e undone <n active save point is one that is specified since the last */&&I( or #/22%<*L '-nta. is '<D+1/I,( savepointnameK 7here 'ave point is an identifier and it is not to declared in declare section

!!!!! - !!!!!

S#L COMMANDS
CREATE TABLE, < ta!le is !asic unit of storage It is composed of rows and columns (o create a ta!le we will name the ta!le and the columns of the ta!le 7e follow the rules to name ta!les and columns4> It must !egin with a letter and can !e up to 30 characters long It must not !e duplicate and not an- reserved word

!!!!! 10 !!!!!

'-nta. to create a ta!le is *#+<(+ (<%2+ ta!lename AcolumnMname1 datat-pe Asi;eB" columnMname2 datat-pe Asi;eB NBK +.ample is *#+<(+ (<%2+ student Arollno num!er A4B" name varchar2 A15BBK SELECT , (he select command of sql lets -ou ma8e queries on the data!ase < quer- is a command that is given certain specified information from the data!ase ta!les It can !e used to retrieve a su!set of rows or columns from one or more ta!les '-nta. to create a ta!le is '+2+*( OcolumnMname1P"OcolumnMname2P ?#/& Ota!lenamePK +.ample is '+2+*( empno" ename" sal from empK CREATE TABLE FROM ANOTHER TABLE , 7e can create a ta!le !- appl-ing as su!quer- clause from another clause It will create the ta!le as well as insert the rows returned from su!quer- '-nta. to create ta!le from another ta!le is *#+<(+ (<%2+ ta!lenameAOcolumn1P"Ocolumn2P"NNB <' '+2+*( Ocolumn1P"Ocolumn2P ?#/& Ota!lenamePK +.ample is *#+<(+ (<%2+ studAempno"ename"salar-B <' '+2+*( empno"ename"sal ?#/& empK ALTER TABLE , <fter creating a ta!le one ma- have need to change the ta!le either !- add new columns or !- modif- e.isting columns /ne can do so !- using alter ta!le command '-nta. to add a column is <2(+# (<%2+ ta!lename <$$Acol1 datat-pe"col2 datat-peBK '-nta. to modif- a column is <2(+# (<%2+ ta!lename &/$I?GAcol1 datat-pe"col2 datat-peBK

DROP TABLE , (o remove the definition of oracle ta!le" the drop ta!le statement is used '-nta. to drop ta!le is $#/1 (<%2+ ta!lename

!!!!! 11 !!!!!

RENAME , /ne can change the name of a ta!le !- rename command '-nta. to rename ta!le is #+,<&+ oldname (/ newname DELETE , /ne can delete data fron ta!le !- using delete from statement (he delete statement removes rows from ta!le !ut it doesn5t release storage space '-nta. of delete rows from ta!le is $+2+(+ ?#/& ta!lename 7=+#+ OconditionPK DESCRIBE , (o find information a!out columns li8e column name" their data t-pes and other attri!utes of a ta!le we can use $+'*#I%+ command '-nta. to descri!e ta!le is $+'*#I%+ ta!lenameK INSERT , (o add new rows in an e.isting oracle ta!le the insert command is used '-nta. to add new fields is I,'+#( I,(/ ta!lenameAcol1"col2"col3" B D<26+'Avalue1"value2"value3BK +.ample is I,'+#( I,(/ emplo-eeAempMid"ename"desg"!asicMpa-B D<26+'A100001"5&/=I(5"5&<,<F+#5"55000BK UPDATE , (he update command ena!les user to change the values of e.isting rows '-nta. to update value of ta!le is 61$<(+ ta!lename '+( col1Qvalue1"col2Qvalue2K +.ample is 61$<(+ empMinfo '+( salar- Qsalar- R100K DISTINCT CLAUSE , (he distinct 8e-word duplicates all rows from results of a select statement '-nta. to remove distinct rows is '+2+*( $I'(I,*( Ocol1P"Ocols2P ?#/& ta!lenameK +.ample is '+2+*( $I'(I,*( @o! ?#/& empK (HERE CLAUSE , (he where clause specifies the criteria for selection of rows to !e returned '-nta. is

!!!!! 1& !!!!!

'+2+*( Ocol1P"Ocol2P ?#/& ta!lename 7=+#+ OcondPK +.ample is '+2+*( ename"sal ?#/& emp 7=+#+ sal P 2000K ORDER BY CLAUSE , Gou can sort the results of quer- ina specific order using order !clause It allows sorting of quer- results !- one or more columns It can !e done either in ascending or descending '-nta. to sort result of quer- is '+2+*( E ?#/& ta!lename /#$+# %G col1"col2"col3K +.ample is '+2+*( E ?#/& emp /#$+# %G ename descK GROUP BY CLAUSE , (he group clause is sued in select statement to divide the ta!le into groups Frouping can !e done !- column name or wih aggregate functions in which case the aggregate producing a value for each group '-nta. is '+2+*( col1"col2 ?#/& ta!lename F#/61 %G OcolPK +.ample is '+2+*( deptt"avgAsalar-B ?#/& empMinfoF#/61 %G depttK HA$ING CLAUSE , (he having clause filters the group values created !- group !- clause (his clause can precede the group !- clause !ut it is more logical if we place group !- first '-nta. is '+2+*( col1"col2 ?#/& ta!lename F#/61 %G OcolP =<DI,F OconditionPK +.ample is '+2+*( deptt"ma.Asalar-B ?#/& empMinfo F#/61 %G deptt =<DI,F ma.Asalar-B P 12000K IN, In operator is used to chec8 a value as search from a domain of multiple values to perform a quer- ,ot In acts as reverse of In '-nta. is '+2+*( Ocol1P"Ocol2P ?#/& ta!lename 7=+#+ OcolP I, Avalue1"value2"value3BK

!!!!! 13 !!!!!

+.ample is '+2+*( ename"address"cit-"state ?#/& emplo-ee 7=+#+ deptt I, AScomp5"5electronics5"5english5BK ALL , It retains duplicate output rows <ll is essentiall- a clarifier rather than a functional argument '-nta. is '+2+*( <22 Ocolumn1P"Ocolumn2P ?#/& Ota!lenamePK +.ample is '+2+*( <22 cit- ?#/& suppliersK SET OPERATORS 'et 8e-words are used to com!ine information of similar t-pe from one or more than one ta!le 'et operations and the operators are !ased on set theor- It consumes two or more queries into one result (he t-pes of set operators are4> UNION , (he union clause merges the outputs of multiple queries into a single set of rows and columns It com!ines rows returned !- two select statements !- eliminating duplicate rows '-nta. is '+2+*( OstatementP 6,I/, '+2+*( OstatementsPK +.ample is '+2+*( designation ?#/& empMinfo 7=+#+ depttQ5comp5 6,I/, '+2+*( designation ?#/& empMinfo 7=+#+ depttQ5eco5K INTERSECT , (he intersect operator com!ines two select statements and return onlthose rows that are returned !- !oth queries '-nta. is '+2+*( OstatementP I,(+#'+*( '+2+*( OstatementsPK +.ample is '+2+*( designation ?#/& empMinfo 7=+#+ depttQ5comp5 I,(+#'+*( '+2+*( designation ?#/& empMinfo 7=+#+ depttQ5eco5K

!!!!! 1) !!!!!

MINUS , It com!ines the result of two queries and returns onl- those values that are selected !first quer- !ut not in second quer- '-nta. is '+2+*( OstatementP &I,6' '+2+*( OstatementsPK +.ample is '+2+*( desgination ?#/& empMinfo 7=+#+ depttQ5comp5 &I,6' '+2+*( desgination ?#/& empMinfo 7=+#+ depttQ5eco5K

ENHANCING PERFORMANCE
$./0s , < view is ver- commonl- used data!ase o!@ect that is derived at runtime < view contains data of its own Its contents are derived from another ta!le (he command for creating view is *#+<(+ DI+7 command +diting in the ta!les are automaticall- reflected in the views It is virtual ta!le ) does not have an- data of its own '-nta. to create a view is

!!!!! 15 !!!!!

*#+<(+ I/# #+12<*+J DI+7 view name <' su! querI7I(= *=+*L /1(I/,J I7I(= #+<$ /,2GJK +.ample is *#+<(+ DI+7 mohit <' '+2+*( empno" ename" sal" comm ?#/& empK (-pes of views are as follows4 Hoin Diew4> It is defined as view that has more than one ta!le specified in from clause and does not contain following clauses i e distinct" aggregation" group !- (his t-pe of view allows update" insert and delete command to change data in ta!le '-nta. is *#+<(+ /# #+12<*+ DI+7 mohit <' '+2+*( ename" empno" sal ?#/& emp" dept 7=+#+ emp deptno Q dept deptnoK (he views to !e updatea!le must not include the following are 'et operators " aggregate functions $istinct operator " rownum pseudo columns Froup !- clause " having clause Inline Diew4 > /racle also offers an inline view that is ver- hand- and inline view is part of '02 statements It allows -ou in !od- of '02 statement to define '02 for view that '02 statement will use to resolve its quer &ateriali;ed Diew4 > 'napshot also called materiali;ed view It is defined as cop- of part of ta!le or entire ta!le It reflects the current status of ta!le that is !eing copied (he original status ta!le is also called master ta!le (wo t-pes are #ead onl- and update #ead>onl- does not allow changes to !e made in view It simpl- pu!lishes and su!scri!es the replications It allows changes in local cop- which periodicall- updates master ta!le S/12/34/s , /racle provides an o!@ect called a 'equence that can generate numeric values (he value generated can have a ma.imum of 38 digits < sequence can !e defined to generate num!ers in ascending or descending order provide intervals !etween num!ers *aching of sequence num!ers in memor< sequence is a data!ase o!@ect used to generate unique integers for use as primar- 8e-s '-nta. is *#+<(+ '+06+,*+ sequence name II,*#+&+,( %G integervalue '(<#( 7I(= integervalue

!!!!! 1 !!!!!

&<9D<26+ integervalue 3 ,/&<9D<26+ &I,D<26+ integervalue 3 ,/&I,D<26+ *G*2+ 3 ,/*G*2+ *<*=+ integervalue 3 ,/*<*=+ /#$+# 3 ,//#$+#J +.ample is *#+<(+ '+06+,*+ mohit I,*#+&+,( %G 1 '(<#( 7I(= 1 &I,D<26+ 1 &<9D<26+ :::: *G*2+K I35/6/s , Inde. is a wa- to store and search records in the ta!le (hese are used to improve the speed with which records can !e located and retrieved from the ta!le /racle retrieves rows in ta!le in one of two wa-s are4 %- #/7I$ %- full ta!le scan (he creation and dropping of inde. doesn5t affect the storage of data in the underl-ing ta!les Inde.es are primaril- used for 2 reasons are4 (o ensure the uniqueness of the inde.ed column5s values (o enhance performance '-nta. to create an inde. is *#+<(+ I,$+9 Oinde. nameP /, Ota!lenamePAcolumn nameBK '-nta. to drop an inde. is $#/1 I,$+9 Oinde. namePK (he t-pes of inde.es are4> 6,I06+ 4 It doesn5t allow duplicate values for inde.ed columns +.ample is *#+<(+ 6,I06+ I,$+9 mohit /, +&1 AenameBK $612I*<(+ 4 It allows duplicate values for inde.ed columns +.ample is

!!!!! 1+ !!!!!

*#+<(+ $612I*<(+ I,$+9 mohit /, +&1 AenameBK */&1/'I(+ 4 multi column inde.es +.ample is *#+<(+ 6,I06+ I,$+9 mohit /, +&1 Aename" salBK ?6,*(I/,<2 4 perform some functions on fields and then inde.es it +.ample is *#+<(+ I,$+9 mohit /, +&1 AsalR100BK

GRANTING AND RE$OKING PERMISSIONS


GRANT , (he Frant statement provides various t-pes of access to data!ase o!@ects such as ta!les" views and sequences < privilege is consent to e.ecute an action or to access another user o!@ect (hese consents can !e given !- grant statement '-nta. is F#<,( To!@ect privilegesU /, o!@ect name (/ username I7I(= F#<,( /1(I/,JK (he 7I(= F#<,( /1(I/, allows the grantee to in turn grant o!@ect privileges to other users

!!!!! 18 !!!!!

O78/49 :;.<.=/>/s +ach o!@ect privileges that is granted authori;es the grantee to 1erform some operation on the o!@ect (he user can grant all the privileges or grant onl- specific o!@ect privileges ALTER allows the grantee to change the ta!le definition with the <2(+# (<%2+ command DELETE INDE" allows the grantee to remove the records from the ta!le with the $+2+(+ command allows the grantee to create an inde. on the ta!le with the *#+<(+ I,$+9 command INSERT allows the grantee to add records to the ta!le with the I,'+#( *ommand SELECT allows the grantee to quer- the ta!le with the '+2+*( *ommand UPDATE allows the grantee to modif- the records in the ta!les with the 61$<(+ command +.ample to grant select ) insert privileges on ta!le item to user named as mohit F#<,( '+2+*(" I,'+#( /, item (/ mohitK +.ample to grant all privileges on ta!le +&1 to user named as chi8u F#<,( <22 /, +&1 (/ mohitK RE$OKE , 1rivileges once given can !e denied to a user using the #+D/L+ command (he o!@ect owner can revo8e privileges granted to another user < user of an o!@ect who is not the owner" !ut has !een granted the F#<,( privilege" has the power to #+D/L+ the privileges from a grantee (he #+D/L+ statement is used to den- the grant given on an o!@ect '-nta. is #+D/L+ To!@ect privilegesU /, o!@ect name

!!!!! 1- !!!!!

?#/& usernameK +.ample to revo8e select ) insert privileges on ta!le item to user named as mohit #+D/L+ '+2+*(" I,'+#( /, item (/ mohitK +.ample to revo8e all privileges on ta!le +&1 to user named as chi8u #+D/L+ <22 /, +&1 (/ mohitK PATTERN MATCHING '02 includes string matching operator 2IL+ for comparison on character string using patterns (he LIKE predicate allows for a comparison of one string with another string value" which is not identical (his is achieved !- using wildcard characters (he patterns are case sensitive and that is uppercase letters do not match lower case characters (he 8e-word ,/( 2IL+ is used to select those rows that do not match the specified pattern of characters (wo wildcard characters that are availa!le are4 ?or character data t-pes4 (he percent sign AVB matches an- string (he 6nderscore AMB matches an- single character +.ample is '+2+*( E ?#/& +&1 7=+#+ ename 2IL+ SM%V5K '+2+*( E ?#/& +&1 7=+#+ ename 2IL+ S&/=MM5K RANGE SEARCHING %+(7++, operator acts as range searching operator (o get a range of values from a quer-" -ou ma- use !etween operators Gou must specif- the lower and upper limit for range search '-nta. is '+2+*( Ocol1P"Ocol2P ?#/& ta!le name 7=+#+ OcolP %+(7++, lower limit and upper limitK +.ample is '+2+*( empname" deptt" !asic pa- ?#/& emplo-ee 7=+#+ !asic pa- %+(7++, 5000 and 10000K

!!!!! &0 !!!!!

%OINS
< H/I, can !e recogni;ed in sql select statement if its has more than one ta!le after from 8e-word (his @oin condition is !ased on primar- 8e-s and foreign 8e-s (here must !e n>1 @oin conditions for n @oins to ta!les If @oin condition is omitted then the result is *artesian product '-nta. is '+2+*( Wlist of columnsX ?#/& ta!le1" ta!le2 7=+#+ WconditionXK (-pes of @oins are E12. 8?.3 , It returns all rows from ta!les where there is a match (a!les are @oined on columns that have the same datat-pe ) si;e in ta!le It is also 8nown as equalit- @oin or simple @oin or inner @oin '-nta. is '+2+*(field1"field2 ?#/& ta!le1"ta!le2 7=+#+ ta!le1 fieldQta!le2 fieldK

!!!!! &1 !!!!!

+.ample is '+2+*(ename" dname ?#/& emp" dept 7=+#+ emp deptnoQdept deptnoK C@;9/s.?3 8?.3 , 7hen the @oin condition is omitted the result is *artesian @oin of two or more ta!les in which all the com!inations of rows will !e displa-ed <ll the rows are @oined to all rows of the second ta!le '-nta. is '+2+*( field1" field2 ?#/& ta!le1" ta!le2K +.ample is '+2+*(ename" dname ?#/& emp" deptK O29/; 8?.3 , 7hile using equi @oin we see that if there e.ists certain rows in one ta!le which don5t have corresponding values in the second ta!le thn those rows will not !e selected 7e can forcefull- select those rows !- outer @oin (he rows for those columns will have ,622 values '-nta. is '+2+*( ta!le1 col" ta!le2 col ?#/& ta!le1" ta!le2 7=+#+ ta!le1 col ARB Q ta!le2 colK +.ample is '+2+*( empno" ename" emp deptno" dname ?#/& emp" dept 7=+#+ emp deptno ARB Q dept deptnoK S/=A %?.3 , (he self @oin can !e seen as @oin of two copies of the same ta!le (he ta!le is not actuall- copied !ut sql performs the command as though it were +.ample is '+2+*( e ename" m ename ?#/& emp e" emp m 7=+#+ e mgrQe empnoK

SUB#UERIES
< su! quer- is a form of an '02 statement that appears inside another '02 statement It is also termed as nested quer- (he statement containing a su! quer- is called a parent statement (he parent statement uses the rows returned !- the su! quer- It can !e used !- the following commands4 (o insert records in a target ta!le (o create ta!les and insert records in the ta!le created (o update records in a target ta!le (o create views

!!!!! && !!!!!

(o provide values for conditions in 7=+#+" =<DI,F" I, etc used with '+2+*(" 61$<(+" and $+2+(+ statements (-pes of su! queries are S.3>=/ ;?0 , It returns one row from inner nested quer- +.ample is '+2+*( deptno ?#/& emp 7=+#+ ename Q5&I22+#5K M2=9.:=/ ;?0 , 'u!queries that return more than one row called multiple row queries /perators li8e I,"<22"<,G are used +.ample is '+2+*( ename"sal"deptno ?#/& emp 7=+#+ sal I, A'+2+*( minAsalB ?#/& emp F#/61 %G deptnoBK M2=9.:=/ 4?=2B3 , It returns more than one column +.ample is '+2+*( ordid " prodid " qt- ?#/& item 7=+#+ Aqt-"prodidB I, A'+2+*( prodid"qt- ?#/& item 7=+#+ ordid Q 605 <,$ ordid OP 605BK

CONSTRAINTS
*onstraints are the rules that restrict the data values inserted in columns

of a ta!le It helps in maintaining integrit- of ta!le at data!ase level instead of application level <ll applicat

can ta8e advantage of these glo!al constraints" rather than !uilding similar logic in individual applicati *olumn level constraint (a!le level constraint *olumn level constraint 4 *olumn constraints are specified as part of column definition to constrain single column (a!le level constraint 4 (a!le constraints is specified at end of create ta!le statement to constraint more than one column

*onstraints can constrain single column or group of columns in a ta!le *onstraints can !e specified as two t-p

!!!!! &3 !!!!!

?ollowing are the constraints used in ta!les are NULL'NOT NULL , 'pecifies if the column must contain value or might not contain an- %default all columns in a ta!le allows nulls" ie <!sence of a value in a column ,/( ,622 specifies that all rows in the ta!le to have value for specified column <ll ,/( ,622 columns are mandator- fields '-nta. is */26&,M,<&+ $<(<M(G1+A'IC+B ,/( ,622 +.ample is *#+<(+ (<%2+ emplo-eeAempname varchar2A25B ,/( ,622B K UNI#UE , 'pecifies that all values in a column must !e unique Dalues in field cannot !e duplicated &ore than one ,ull value can !e inserted in the column 6nique constraint can !e placed on multiple columns '-nta. is */26&,M,<&+ $<(<M(G1+A'IC+B 6,I06+ 6,I06+ */26&,M,<&+ $<(<M(G1+A'IC+B +.ample is *#+<(+ (<%2+ deptAdeptt varchar2A25B 6,I06+BK *#+<(+ (<%2+ deptAdeptt varchar2A25B"6,I06+AdeptBBK PRIMARY KEY , 1rimar- 8e- refers to one or more column values in a ta!le that can uniquelidentif- each row in a ta!le < primar- 8e- column cannot contain nulls and is unique !- default '-nta. is */26&, $<(<M(G1+A'IC+B 1#I&<#G L+G >> at column level 1#I&<#G L+G */26&, $<(<M(G1+A'IC+B >> at ta!le level +.ample is *#+<(+ (<%2+ deptAdeptt varchar2A25B 1#I&<#G L+GBK *#+<(+ (<%2+ deptAdeptt varchar2A25B"1#I&<#G L+GAdeptBBK FOREIGN KEY , < foreign 8e- is a one or more column with values !ased on the primar- 8evalues from another ta!le < foreign 8e- constraint specifies that the values stored in foreign column correspond to values of the primar- 8e- in the other ta!le ?oreign 8e- is also 8nown as referential integrit- constraint (he ta!le containing foreign 8e- is 8nown as $ependent ta!le and the ta!le that is referenced !- foreign 8e- is called #eferenced ta!le '-nta. is */26&, $<(<M(G1+A'IC+B #+?+#+,*+' (<%2+ >> at column level >> at column level >> at ta!le level

!!!!! &) !!!!!

?/#+IF, L+G */26&, $<(<M(G1+A'IC+B #+?+#+,*+' (<%2+ +.ample is *#+<(+ (<%2+ deptAdeptt varchar2A25B #+?+#+,*+' empMinfoBK *#+<(+ (<%2+ deptAdeptt varchar2A25B"1#I&<#G L+GAdeptB ?/#+IF, L+GAdeptB #+?+#+,*+' empMinfoBK

FUNCTIONS
?unctions ma8e the result of the quer- easier and are used to manipulate the data values ?ollowing are the functions are
'tring or character functions ,um!er functions <ggregate functions or group functions $ate functions *onversion functions

CC@;@49/; M@3.:2=@9.?3 A2349.?3s <scii 4 It returns the <'*II decimal equivalent of a character passed as an argument +.ample is select asciiAS!5Bfrom dualK

!!!!! &5 !!!!!

*hr 4 (his function gives the result as a character corresponding to the value in the data!ase set +.ample is select char A:7B from dualK concatA.1".2B 4 (his function concates the string .1 with .2 (his function is equivalent to the Y Y operator +.amples select concatASmohit5"5garg5Bfrom dualK instr 4(his function returns the first position of the character . in the string +.ample is select instrASmohit5"5o5B from dualK length 4 It returns the length of the string . +.ample is select length ASmohit5B from dualK

lpad 4 It pads the leading spaces to the left side of the column char1 with the char2" so that the total width !ecomes equal to the value n If char2 is a!sent" it pads the char1 on the left side with !lan8 spaces to the total width of n +.ample is select lpadAdname"12"5E5B from deptK 2trim 4 It removes all the !lan8 spaces from the left side of the stringif no char is specified If we give a char" then it removes the leading occurrences of that charcter from the string +.ample is select ltrimAdname 5'5B from deptK #pad 4 (his function pads the leading spaces to the right side of the column char1 with the char2" so that the total width !ecomes equl to the value n +.ample is select rpadAdname"12"5E5Bfrom deptK #trim 4 (his function removes all the !lan8 spaces from the right side if no char is specified +.ample is select rtrimAdname"5'5B from deptK #eplace 4 7here c1"c2"c3 and c3 are all character string this function returns c1 with all occurenes of c2 replaced with c3" the default value of c3 is ,622 +.ample is select replace Auptown"5up5"down5Bfrom dualK

!!!!! & !!!!!

'u!str 4 It returns the su!string from ;" of length equal to - starting at position . +.ample is select su!strASmohitgarg52"5B from dualK Initcap 4 (his function returns the string with letter in caps +.ample is select initcap AdnameB from deptK 2ower 4 (his function converts the string into lower case +.ample is select lower AdnameBfrom deptK 6pper 4 It converts the string into upper case +.ample is select upperAdnameBfrom deptK (ranslate 4 (his function is used to find a char and replace it with new character +.ample is select dname" translate Adname"5+5"2B from deptK G;?2: A2349.?3s *ount 4 (his function returns the num!er of rows or non>null values for column . '-nta. is countAIdistinctYallJcolumn nameB +.ample is select countAempnoBfrom empK 'um 4 (his function ireturns the sum of values for the column . (his function is applied on columns having numeric datat-pe and it returns the numeric value '-nta. is sumAIdistinctYallJcolumn nameB +.ample is select sumAsalB from empK <vg 4 (hs function returns the average of values for the column . It ignores the null values in the column . '-nta. is avgAIdistinctYallJcolumn nameB +.ample is select avgAsalB"countAsalB from empK &in 4 (his function returns the minimum of values for the column . for all the rows '-nta. is minAIdistinctYallJcolumn nameB +.ample is select minAsalB from empK

!!!!! &+ !!!!!

&a. 4 (his function returns the ma.imum of values for the column . for all the rows '-nta. is ma.AIdistinctYallJcolumn nameB +.ample is select minAsalB"ma.AsalB from empK N2B7/; A2349.?3s <!s 4 It o!tains the a!solute value for the num!er . +.ample is 'elect a!sA>10B from dualK *eil 4 7here is a num!er (his function returns the smallest integer that is greater than or equal to n +.ample is select ceil A: 8B" ceil A>32 85B from dualK *os 4 It returns trigonometric cosine of the num!er n +.ample is select cosA45B from dualK +.p 4 It returns the e raised to the . power +.ample is select e.p A4B from dualK ?loor 4 (his function returns the largest integer that is less than or equal to n +.ample is select floor A: 8B" floor A>32 85B from dualK &od 4 It returns the remainder when . is divided !- the num!er +.ample is select mod A10 3B"mod A10 5Bfrom dualK 1ower 4 (his function returns the value of . raised to the power of - (he argument - should !e an integer +.ample is select power A2" 3B from dualK

!!!!! &8 !!!!!

#ound 4 It rounds off . to the decimal precision of - If - is negative" rounds to the precision of places to the left of the decimal point +.ample is select round A55 84:"1 B" roundA55 84:B from dualK 'ign 4 (his function returns the sign of the value . If . is a negative num!er it returns >1 otherwise it returns 1 +.ample is select sign A>2B from dualK 'qrt 4 (his function returns the square root of the given num!er . +.ample is select sqrtA36B from dualK

D@9/ A2349.?3s <ddMmonths 4 It adds the months in specified date with the function '-nta. is <$$M&/,(='Adate"mB where date refers to date ) m is num!er value +.ample is select addMmonthsAs-sdate"2B from dualK 2astMda- 4 It returns the last da- of given month which is specified with function '-nta. is 2<'(M$<GAdB where d is date +.ample is select lastMda-As-sdateB from dualK &onthsM!etween 4 It computes ) returns the num!er of months !3w two dates '-nta. is &/,(='M%+(7++,Adate1"date2B +.ample is select monthsM!etweenA513>mar>055"501>dec>055B from dualK

!!!!! &- !!!!!

,e.tMda- 4 It returns the date of first da- of the wee8 specified in a string after the !eginning date '-nta. is ,+9(M$<GAdate"chB where ch refers to character value +.ample is select ne.tMda-A513> mar>055"5sunda-5B from dualK

!!!!! 30 !!!!!

You might also like