Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

EXP.

NO: 2

INSERT, SELECT, UPDATE & DELETE COMMANDS


AIM: To study DML commands in RDBMS. DEFINITION AND SYNTAX: DATA MANIPULATION LANGUAGE (DML): The language used to manipulate data is called DML Manipulation of data includes the insertion of data into the database, modification of data stored in the database, deletion of data from the database and retrieval of data for further process. The commands used are Insert pdate Delete QUERY: !uery is a statement in the DML that re"uest the retrieval of data from database. The portion of the DML used in a !uery is called !uery language. The S#L#$T statement is used to "uery a database. INSERT: Insert command is used to insert the values into the table. There are three %ays to insert a record into the database. &. Inser !n" D# #$s !n s%e&!'!e( &)*+,ns' S-n #.: INSERT INTO #/*e0n#,e(&)*1,&)*2,22.,&)*n) 3ALUES(4#*1,4#*2,22,4#*n)5 (. Inser !n" 3#*+es: S-n #.: INSERT INTO #/*e0n#,e 3ALUES(4#*1,4#*2,22...,4#*n)5 ). Inser !n" M+* !%*e R)6s' S-n #.:

INSERT INTO #/*en#,e 3ALUES(&&)*1,$&&)*2$,$&&)*7$,22.,&&)*n)5 UPDATE: *D+T# command is used to change a value of a record in the database. S-n #.: UPDATE #/*e0n#,e SET &)*+,n n#,e 8ne6 4#*+e 9:ERE &)*+,n n#,e8s),e 4#*+e5 DELETE: The D#L#T# statement is used to delete ro%s in a table. S-n #.: DELETE FROM #/*e0n#,e 9:ERE &)*+,n n#,e8s),e 4#*+e5 SELECT: The select statement is used to "uery a database. This statement is used to retrieve the information from the database. The S#L#$T statement can be used in many %ays. They are' 1. Se*e& !n" s),e &)*+,ns: To select specified number of columns from the table the follo%ing command is used. S-n #.: SELECT &)*+,n n#,e FROM #/*e0n#,e5 (. Q+er- A** C)*+,ns' To select all columns from the table , is used instead of column names. S-n #.: SELECT ; FROM #/*e0n#,e5 ). Se*e& +s!n" DISTINCT: The DISTI-$T .ey%ord is used to return only different values /i.e. 0 this command does not select the duplicate values from the table . S-n #.:

SELECT DISTINCT &)*+,n n#,e(s) FROM #/*e0n#,e5 1. Se*e& +s!n" IN: If you %ant to get the ro%s, %hich contain certain values, the best %ay to do it is to use the I- conditional e2pression. S-n #.: SELECT &)*+,n n#,e(s) FROM #/*e0n#,e 9:ERE C)*+,n n#,e IN(4#*+e1,4#*+e2,22,4#*+e n)5 3. Se*e& +s!n" <ET9EEN' B#T4##- can be used to get those items that fall %ithin a range. S-n #.: SELECT &)*+,n n#,e FROM #/*e0n#,e 9:ERE C)*+,n n#,e <ET9EEN 4#*+e1 AND 4#*+e25 5. Ren#,!n": The select statement can be used to rename either a column or the entire table. S-n #.: Ren#,!n" # &)*+,n: SELECT &)*+,n n#,e AS ne6 n#,e FROM #/*e0n#,e5 Ren#,!n" # #/*e: SELECT &)*+,n n#,e FROM #/*e0n#,e AS ne6n#,e5 6. S)r !n"' The select statement %ith the )r(er /- C*#+se is used to sort the contents of the table either in ascending or descending order. S-n #.: SELECT &)*+,n n#,e FROM #/*e0n#,e 9:ERE C)n(! !)n ORDER <Y &)*+,n n#,e ASC=DESC5 7. T) Se*e& /- ,# &>!n" s),e %# erns' The select statement along %ith *!?e &*#+se I is used to match strings. The *!?e condition is used to specify a search pattern in a column.

S-n #.: SELECT &)*+,n n#,e FROM #/*e0n#,e 9:ERE C)*+,n n#,e LI@E AB )rCA5 B : M# &>es #n- s+/ s r!n".

C :

M# &>es # s!n"*e &>#r#& er.

8. T) Se*e& NULL 4#*+es' 4e can use the S#L#$T statement to select the 9null: values also. ;or retrieving ro%s %here some of the columns have been defined as - LLs there is a special comparison operator of the form IS<-=T>- LL. S-n #.: SELECT &)*+,n n#,e FROM #/*e0n#,e 9:ERE C)*+,n n#,e IS NULL? &@. Se*e& +s!n" AND, OR, NOT' 4e can combine one or more conditions in a S#L#$T statement using the logical operators +-D,=R,-=T. S-n #.: SELECT &)*+,n n#,e FROM #/*e0n#,e 9:ERE C)n(! !)n1 LOGICAL OPERATOR &)n(! !)n25 EXERCISES: 1. Cre# e >e ')**)6!n" #/*e 6! > >e "!4en 4#*+es: D-= & ( ) 1 3 5 D-+M# Research ;inance Mar.eting Br +dministration Maintenance M+-+A#R Madesh Santhosh +rvind Ram Se.ar -aresh

(. Cre# e >e ')**)6!n" #/*e 6! > >e "!4en 4#*+es: #ID 1@65 5@3( 3&)6 1&1) 35(@ 5&&6 6356 7@13 &@13 1111 7&15 835( &(13 )531 &@@& -+M# D=B ram (EmayE7) c. 7EsepE7( .arthi. 8EFanE7& saranya3EfebE7@ a.alya 5EmarE7) arvind &(EdecE68 balu &&EnovE7& san.ar &EFanE7@ dilip (3EoctE7( sunil (&EdecE7& raghav &5EfebE66 gayatri (8EfebE71 sai )@EmarE7( tila. 8EaugE7& varun &(EFulE67 +DDR#SS chennai chennai mumbai hyderabad cochin chennai chennai .ovai trichy delhi chennai delhi chennai S#C m f m f f m m m m m m f f m m D#SIA e2ecutive sr.engineer attender s%eeper attender s%eeper cashier cleaner sr.engineer cashier e2ecutive e2ecutive cashier e2ecutive sr.engineer D#-= M+RIST+ S+L+RD ) & 3 5 3 5 ( 5 & ( ) ) ( ) & s m s s s m m s m m m s s s m &@@@@ &3@@@ 1@@@ (3@@ 3@@@ )@@@ 7@@@ )3@@ &3@@@ 3@@@ 7@@@ 73@@ 53@@ 73@@ (@@@@

7.In&re#se >e s#*#r- )' >e e,%*)-ee /- Rs.DEE 6>)se (e% n) !s D F.In&re#se >e s#*#r- )' ,#r?e !n" e.e&+ !4es /- Rs.2DEE D. L!s >e e,%*)-ee (e #!*s 6>)se #((ress !s n+** G.L!s >e e,%*)-ee (e #!*s 6>) /e*)n"s ) H&>enn#!$ I.L!s >e e!( , n#,e #n( #((ress ')r >e e,%*)-ees 6>)se s#*#r- !s #/)4e 1EEEE #n( /e*)6 2EEEEJ K. F!** >e n+** 4#*+es !n >e #((ress '!e*( )' >e e,%*-ee #/*e /-$...$ L.L!s >e e!(, n#,e, #((ress ,(e% n) )' >e e,%*)-ees 6>)se n#,e s #r s 6! > e! >er A )r M 1E.L!s >e e,%*)-ees 6>)se (es!"n# !)n !s &#s>!er )r(ere( /- n#,e. 11. Ren#,e >e '!e*( e!( #s e,%!( #n( n#,e #s e,%n#,e. 12.L!s >e e,%*)-ees 6>) /e*)n"s ) (e*>! )r(ere( /- (e% n) !n (es&en(!n" )r(er. 17. L!s >e n+,/er )' re&)r(s )' e,%*)-ee #/*e 1F.L!s >e ,#.!,+, #n( ,!n!,+, s#*#r- )' >e e,%*)-ees 6>)se (e% n) !s 1 1D. L!s >e n#,e, #((ress #n( (es!"n# !)n ')r >e e,%*)-ees 6>)se s#*#r- !s /e*)6 IEEE.

You might also like