Вы находитесь на странице: 1из 23

SQL

From Wikipedia, the free encyclopedia

This article is about the database language. For the IATA code, see San Carlos Airport.

SQL
Paradigm(s) Multi-paradigm

Appeared in

1974

Designed by

Donald D. Chamberlin Raymond F. Boyce

Developer

I !"I#C

Stable release

$%&'(11 )'(11*

Typing discipline

tatic+ ,trong

Major implementations

Many

Dialects

$%--.+ $%--9+ $%9'+ $%&1999+ $%&'((/+ $%&'((-+ $%&'(11

Infl enced by

Datalog

Infl enced

0gena+ C$%+ %I1$+2indo3, 4o3er hell516

!S

Cro,,-plat7orm

"s al filename e#tensions

.,8l

$ebsite

9I !"I#C 9(7:-1&'((-& In7ormation technology ; Databa,e language, ; $% ; 4art 1& Frame3or<

) $%"Frame3or<*9

SQL

tructured $uery %anguage

%ilename e#tension

.sql application/x-sql

Internet media type

Developed by

I !"I#C

Initial release

19-.

Latest release

$%&'((- " '((-= 4 year, ago

Type of format

Databa,e

Standard(s)

I !"I#C 9(7:

!pen format&

>e,

$ebsite

5'6

SQL (

/s kju l/ "S-Q-L";[3] sometimes referred to as Structured Query Language is a special-

p!rpose pro"rammin" lan"!a"e desi"ned for mana"in" data in relational data#ase mana"ement systems ($%&'S ( )ri"inally #ased !pon relational al"e#ra and t!ple relational calc!l!s,[*] its scope incl!des data insert, +!ery, !pdate and delete, schema creation and modification, and data access control( SQL ,as one of the first commercial lan"!a"es for -d"ar F( .odd/s relational model, as descri#ed in his infl!ential 0123 paper, "4 $elational 'odel of %ata for Lar"e Shared %ata &anks"( [5] %espite not adherin" to the relational model as descri#ed #y .odd, it #ecame the most ,idely !sed data#ase lan"!a"e( [6][2] 4ltho!"h SQL is often descri#ed as, and to a "reat e7tent is, a declarati8e lan"!a"e, it also incl!des proced!ral elements( SQL #ecame a standard of the 4merican 9ational Standards :nstit!te (49S: in 01;6, and of the :nternational

)r"ani<ation for Standards (:S) in 01;2( Since then, the standard has #een enhanced se8eral times ,ith added feat!res( =o,e8er, iss!es of SQL code porta#ility #et,een ma>or $%&'S prod!cts still e7ist d!e to lack of f!ll compliance ,ith, or different interpretations of, the standard( 4mon" the reasons mentioned are the lar"e si<e and incomplete specification of the standard, as ,ell as 8endor lock-in(
'ontents
5hide6

1 ?i,tory ' $uerie,

o o
logic )/A%*

'.1 ub8uerie, '.' 1ull and three-@alued

/ Data manipulation 4 Bran,action control, : Data de7inition . Data type,

o o o o

..1 Character ,tring, ..' Bit ,tring, ../ 1umber, ..4 Date and time 7 Data control - 4rocedural eCten,ion, 9 $% !perator, 1( Critici,m

o
portability

1(.1 Cro,,-@endor

11 tandardiDation

11.1 tandard ,tructure 1' 0lternati@e, 1/ ee al,o 14 1ote, 1: Re7erence, 1. #Cternal lin<,

[edit]=istory
SQL ,as initially de8eloped at :&' #y %onald %( .ham#erlin and $aymond F( &oyce in the early 0123s( ?his 8ersion, initially called SEQUEL(Structured English Query Language , ,as desi"ned to manip!late and retrie8e data stored in :&'/s ori"inal +!asi-relational data#ase mana"ement system, System $, ,hich a "ro!p at :&' San @ose $esearch La#oratory had de8eloped d!rin" the 0123s([;] ?he acronym S-QA-L ,as later chan"ed to SQL #eca!se "S-QA-L" ,as a trademark of the AB-#ased =a,ker Siddeley aircraft company([1] ?he first Relational Database anage!ent Syste! ($%&'S ,as $%'S, de8eloped at ':? in the early 0123s,

soon follo,ed #y :n"res, de8eloped in 012* at A(.( &erkeley( :n"res implemented a +!ery lan"!a"e kno,n as QA-L, ,hich ,as later s!pplanted in the marketplace #y SQL( [1] :n the late 0123s, $elational Soft,are, :nc( (no, )racle .orporation sa, the potential of the concepts descri#ed #y .odd, .ham#erlin, and &oyce and de8eloped their o,n SQL-#ased $%&'S,ith aspirations of sellin" it to the A(S( 9a8y, .entral :ntelli"ence 4"ency, and other A(S( "o8ernment a"encies( :n @!ne 0121, $elational Soft,are, :nc( introd!ced the first commercially a8aila#le implementation of SQL, )racle CD (CersionD for C4E comp!ters( "racle #$ #eat :&'/s 4!"!st release of the SystemF3; $%&'S to market #y a fe, ,eeks([citation needed] 4fter testin" SQL at c!stomer test sites to determine the !sef!lness and practicality of the system, :&' #e"an de8elopin" commercial prod!cts #ased on their System $ prototype incl!din" SystemF3;, SQLF%S, and %&D, ,hich ,ere commercially a8aila#le in 0121, 01;0, and 01;3, respecti8ely( [03]

?his chart sho,s se8eral of the SQL lan"!a"e elements that compose a sin"le statement(

?he SQL lan"!a"e is s!#di8ided into se8eral lan"!a"e elements, incl!din"G

Clauses, ,hich are constit!ent components of statements and +!eries( (:n some cases, these are optional(
[00]

Expressions, ,hich can prod!ce either scalar 8al!es or ta#les consistin" of col!mns and ro,s of data(

Predicates, ,hich specify conditions that can #e e8al!ated to SQL three-8al!ed lo"ic (3CL or &oolean (tr!eFfalseF!nkno,n tr!th 8al!esand ,hich are !sed to limit the effects of statements and +!eries, or to chan"e pro"ram flo,(

Queries, ,hich retrie8e the data #ased on specific criteria( ?his is the most important element of SQL( Statements, ,hich may ha8e a persistent effect on schemata and data, or ,hich may control transactions, pro"ram flo,, connections, sessions, or dia"nostics(

SQL statements also incl!de the semicolon (";" statement terminator( ?ho!"h not re+!ired on e8ery platform, it is defined as a standard part of the SQL "rammar(

Insignificant whitespace is "enerally i"nored in SQL statements and +!eries, makin" it easier to format SQL code for reada#ility(

[edit]Q!eries
?he most common operation in SQL is the +!ery, ,hich is performed ,ith the declarati8e SELECT statement( SELECT retrie8es data from one or more ta#les, or e7pressions( Standard SELECTstatements ha8e no persistent effects on the data#ase( Some non-standard implementations of SELECT can ha8e persistent effects, s!ch as the SELECT INTO synta7 that e7ists in some data#ases([0D] Q!eries allo, the !ser to descri#e desired data, lea8in" the data#ase mana"ement system (%&'S responsi#le for plannin", optimi<in", and performin" the physical operations necessary to prod!ce that res!lt as it chooses( 4 +!ery incl!des a list of col!mns to #e incl!ded in the final res!lt immediately follo,in" the SELECT key,ord( 4n asterisk ("*" can also #e !sed to specify that the +!ery sho!ld ret!rn all col!mns of the +!eried ta#les( SELECT is the most comple7 statement in SQL, ,ith optional key,ords and cla!ses that incl!deG

?he FROM cla!se ,hich indicates the ta#le(s from ,hich data is to #e retrie8ed( ?he FROM cla!se can incl!de optional JOIN s!#cla!ses to specify the r!les for >oinin" ta#les(

?he WHERE cla!se incl!des a comparison predicate, ,hich restricts the ro,s ret!rned #y the +!ery( ?he WHERE cla!se eliminates all ro,s from the res!lt set for ,hich the comparison predicate does not e8al!ate to ?r!e(

?he GRO ! "# cla!se is !sed to pro>ect ro,s ha8in" common 8al!es into a smaller set of ro,s( GRO ! "# is often !sed in con>!nction ,ith SQL a""re"ation f!nctions or to eliminate d!plicate ro,s from a res!lt set( ?he WHERE cla!se is applied #efore the GRO ! "# cla!se(

?he H$%ING cla!se incl!des a predicate !sed to filter ro,s res!ltin" from the GRO ! "# cla!se( &eca!se it acts on the res!lts of the GRO ! "# cla!se, a""re"ation f!nctions can #e !sed in the H$%ING cla!se predicate(

?he OR&ER "# cla!se identifies ,hich col!mns are !sed to sort the res!ltin" data, and in ,hich direction they sho!ld #e sorted (options are ascendin" or descendin" ( Witho!t an OR&ER "#cla!se, the order of ro,s ret!rned #y an SQL +!ery is !ndefined(

?he follo,in" is an e7ample of a SELECT +!ery that ret!rns a list of e7pensi8e #ooks( ?he +!ery retrie8es all ro,s from the %oo& ta#le in ,hich the price col!mn contains a 8al!e "reater than 033(33( ?he res!lt is sorted in ascendin" order #y title( ?he asterisk (H in the select list indicates that all col!mns of the %oo& ta#le sho!ld #e incl!ded in the res!lt set( SELECT * FROM "oo' WHERE p(ic) * +,,.,, ORDER BY titl)?he e7ample #elo, demonstrates a +!ery of m!ltiple ta#les, "ro!pin", and a""re"ation, #y ret!rnin" a list of #ooks and the n!m#er of a!thors associated ,ith each #ook( SELECT "oo'.titl). COUNT/*0 AS $1t2o(s FROM "oo' JOIN "oo'3a1t2o( ON "oo'.is4n 5 "oo'3a1t2o(.is4n GROUP BY "oo'.titl)-7ample o!tp!t mi"ht resem#le the follo,in"G

Titl) ---------------------S6L Exa7pl)s an8 G1i8) T2) Jo: o; S6L $n Int(o81ction to S6L

$1t2o(s ------9 + <

!it;alls o; S6L

Ander the precondition that isbn is the only common col!mn name of the t,o ta#les and that a col!mn named title only e7ists in the %oo&s ta#le, the a#o8e +!ery co!ld #e re,ritten in the follo,in" formG SELECT titl). COUNT/*0 AS $1t2o(s FROM "oo' NATURAL JOIN "oo'3a1t2o( GROUP BY titl)=o,e8er, many 8endors either do not s!pport this approach, or re+!ire certain col!mn namin" con8entions in order for nat!ral >oins to ,ork effecti8ely( SQL incl!des operators and f!nctions for calc!latin" 8al!es on stored 8al!es( SQL allo,s the !se of e7pressions in the select list to pro>ect data, as in the follo,in" e7ample ,hich ret!rns a list of #ooks that cost more than 033(33 ,ith an additional sales'ta( col!mn containin" a sales ta7 fi"!re calc!lated at 6I of the price( SELECT is4n. titl). p(ic). p(ic) * ,.,= AS sal)s3tax FROM "oo' WHERE p(ic) * +,,.,, ORDER BY titl)-

[edit]Subqueries
Q!eries can #e nested so that the res!lts of one +!ery can #e !sed in another +!ery 8ia a relational operator or a""re"ation f!nction( 4 nested +!ery is also kno,n as a subquery( While >oins and other ta#le operations pro8ide comp!tationally s!perior (i(e( faster alternati8es in many cases, the !se of s!#+!eries introd!ces a hierarchy in e7ec!tion ,hich can #e !sef!l or necessary( :n the follo,in" e7ample, the a""re"ation f!nction $%G recei8es as inp!t the res!lt of a s!#+!eryG SELECT is4n. titl). p(ic) FROM "oo' WHERE p(ic) > $%G/SELECT p(ic) FROM "oo'0 ORDER BY titl)-

[edit]

ull and three!"alued logic #$%L&

?he idea of 9!ll ,as introd!ced into SQL to handle missin" information in the relational model( ?he introd!ction of 9!ll (or Ankno,n alon" ,ith ?r!e and False is the fo!ndation of three-8al!ed lo"ic( 9!ll does not ha8e a 8al!e (and is not a mem#er of any data domain #!t is rather a placeholder or "mark" for missin" information( ?herefore comparisons ,ith 9!ll can ne8er res!lt in either ?r!e or False #!t al,ays in the third lo"ical res!lt

(,ith the e7ception of the )$ operator - ,hen one 8al!e is ?r!e, the res!lt is ?r!e e8en if the the other 8al!e is 9!ll - see #elo, ([03] SQL !ses 9!ll to handle missin" information( :t s!pports three-8al!ed lo"ic (3CL and the r!les "o8ernin" SQL three-8al!ed lo"ic are sho,n #elo, (p and + represent lo"ical states ( [0*] ?he ,ord 9ALL is also a reser8ed key,ord in SQL, !sed to identify the 9!ll special marker( 4dditionally, since SQL operators ret!rn Ankno,n ,hen comparin" anythin" ,ith 9!ll, SQL pro8ides t,o 9!llspecific comparison predicatesG IS N LL and IS NOT N LL test ,hether data is or is not 9!ll([03] 9ote that SQL ret!rns only res!lts for ,hich the W=-$- cla!se ret!rns a 8al!e of ?r!e; i(e( it e7cl!des res!lts ,ith 8al!es of False and also e7cl!des those ,hose 8al!e is Ankno,n(

p p A(D ) Tr e %alse "n*no+n p !, ) Tr e

%alse

"n*no+n

Tr e

Brue

Fal,e En<no3n

Tr e

Brue Brue

Brue

%alse

Fal,e

Fal,e Fal,e

%alse

Brue Fal,e

En<no3n

"n*no+n En<no3n Fal,e En<no3n

"n*no+n Brue En<no3n En<no3n

(!T p p-)

Brue

Fal,e

Tr e

%alse

"n*no+n

Fal,e

Brue

Tr e

Brue

Fal,e

En<no3n

En<no3 En<no3n n

%alse

Fal,e

Brue

En<no3n

"n*no+n En<no3n En<no3n En<no3n

Ani8ersal +!antification is not e7plicitly s!pported #y SQL, and m!st #e ,orked o!t as a ne"ated e7istential +!antification([05][06][02]

?here is also the "Jro, 8al!e e7pressionK :S %:S?:9.? F$)' Jro, 8al!e e7pressionK" infi7ed comparison operator ,hich ret!rns ?$A- !nless #oth operands are e+!al or #oth are 9ALL( Like,ise, :S 9)? %:S?:9.? F$)' is defined as "9)? (Jro, 8al!e e7pressionK :S %:S?:9.? F$)' Jro, 8al!e e7pressionK "(

[edit]%ata

manip!lation

?he %ata 'anip!lation Lan"!a"e (%'L is the s!#set of SQL !sed to add, !pdate and delete dataG

INSERT adds ro,s (formally t!ples to an e7istin" ta#le, e("(G

INSERT INTO M:3ta4l) /;i)l8+. ;i)l8<. ;i)l8?0 VALUES /@t)st@. @N@. NULL0-

!&$TE modifies a set of e7istin" ta#le ro,s, e("(G

UPDATE M:3ta4l) SET ;i)l8+ 5 @1p8at)8 Aal1)@ WHERE ;i)l8< 5 @N@-

&ELETE remo8es e7istin" ro,s from a ta#le, e("(G

DELETE FROM M:3ta4l) WHERE ;i)l8< 5 @N@-

MERGE is !sed to com#ine the data of m!ltiple ta#les( :t com#ines


the INSERT and !&$TE elements( :t is defined in the SQLGD333 standard; prior to that, some data#ases pro8ided similar f!nctionality 8ia different synta7, sometimes called "!psert"(

[edit]?ransaction

controls

?ransactions, if a8aila#le, ,rap %'L operationsG

ST$RT TR$NS$CTION (or "EGIN WORB, or "EGIN TR$NS$CTION, dependin" on SQL dialect
mark the start of a data#ase transaction, ,hich either completes entirely or not at all(

S$%E TR$NS$CTION (or S$%E!OINT sa8e the state of the data#ase at the c!rrent point in
transaction

CREATE TABLE t4l3+/i8 INT0INSERT INTO t4l3+/i80 VALUES/+0INSERT INTO t4l3+/i80 VALUES/<0-

COMMITUPDATE t4l3+ SET i85<,, WHERE i85+SAVEPOINT i83+1p8UPDATE t4l3+ SET i85+,,, WHERE i85<ROLLBACK TO i83+1p8SELECT i8 FROM t4l3+-

COMMIT ca!ses all data chan"es in a transaction to #e made permanent( ROLL"$CB ca!ses all data chan"es since the last COMMIT or ROLL"$CB to #e discarded, lea8in" the
state of the data as it ,as prior to those chan"es(

)nce the COMMIT statement completes, the transaction/s chan"es cannot #e rolled #ack(

COMMIT and ROLL"$CB terminate the c!rrent transaction and release data locks( :n the a#sence of a ST$RT TR$NS$CTION or similar statement, the semantics of SQL are implementation-dependent( ?he follo,in"
e7ample sho,s a classic transfer of f!nds transaction, ,here money is remo8ed from one acco!nt and added to another( :f either the remo8al or the addition fails, the entire transaction is rolled #ack( START TRANSACTIONUPDATE $cco1nt SET a7o1nt5a7o1nt-<,, WHERE acco1nt3n174)(5+<?9UPDATE $cco1nt SET a7o1nt5a7o1ntC<,, WHERE acco1nt3n174)(5<?9DIF ERRORS5, COMMITIF ERRORS>*, ROLLBACK-

[edit]%ata

definition

?he %ata %efinition Lan"!a"e (%%L mana"es ta#le and inde7 str!ct!re( ?he most #asic items of %%L are the CRE$TE, $LTER, REN$ME, &RO! and TR NC$TE statementsG

CRE$TE creates an o#>ect (a ta#le, for e7ample in the data#ase, e("(G

CREATE TABLE M:3ta4l)/ 7:3;i)l8+ 7:3;i)l8< 7:3;i)l8? 0INT. VARCHAR/D,0. DATE NOT NULL.

PRIMARY KEY /7:3;i)l8+. 7:3;i)l8<0

$LTER modifies the str!ct!re of an e7istin" o#>ect in 8ario!s ,ays, for e7ample, addin" a col!mn to an
e7istin" ta#le or a constraint, e("(G

ALTER TABLE M:3ta4l) ADD 7:3;i)l89 NUMBER/?0 NOT NULL-

TR NC$TE deletes all data from a ta#le in a 8ery fast ,ay, deletin" the data inside the ta#le and not
the ta#le itself( :t !s!ally implies a s!#se+!ent .)'':? operation, i(e(, it cannot #e rolled #ack (data is not ,ritten to the lo"s for roll#ack later, !nlike %-L-?- (

TRUNCATE TABLE M:3ta4l)-

&RO! deletes an o#>ect in the data#ase, !s!ally irretrie8a#ly, i(e(, it cannot #e rolled #ack, e("(G

DROP TABLE M:3ta4l)-

[edit]%ata

types

-ach col!mn in an SQL ta#le declares the type(s that col!mn may contain( 49S: SQL incl!des the follo,in" data types([0;]

[edit]Character

strings

CH$R$CTER/n0 or CH$R/n0 L fi7ed-,idth n-character strin", padded ,ith spaces as needed CH$R$CTER %$R#ING/n0 or %$RCH$R/n0 L 8aria#le-,idth strin" ,ith a ma7im!m si<e
of n characters

set

N$TION$L CH$R$CTER/n0 or NCH$R/n0 L fi7ed ,idth strin" s!pportin" an international character

N$TION$L CH$R$CTER %$R#ING/n0 or N%$RCH$R/n0 L 8aria#le-,idth NCH$R strin"

[edit]'it [edit]

strings

"IT/n0 L an array of n #its "IT %$R#ING/n0 L an array of !p to n #its

umbers
INTEGER and SM$LLINT FLO$T, RE$L and &O "LE !RECISION N MERIC/precision. scale0 or &ECIM$L/precision. scale0

For e7ample, the n!m#er 0D3(*5 has a precision of 5 and a scale of D( ?he precision is a positi8e inte"er that determines the n!m#er of si"nificant di"its in a partic!lar radi7 (#inary or decimal ( ?he scale is a non-ne"ati8e

inte"er( 4 scale of 3 indicates that the n!m#er is an inte"er( For a decimal n!m#er ,ith scale S, the e7act n!meric 8al!e is the inte"er 8al!e of the si"nificant di"its di8ided #y 03 S( SQL pro8ides a f!nction to ro!nd n!merics or dates, called TR NC (in :nformi7, %&D, Most"reSQL, )racle and 'ySQL or RO N& (in :nformi7, Sy#ase, )racle, Most"reSQL and 'icrosoft SQL Ser8er
[01]

[edit](ate

and time

&$TE L for date 8al!es (e("(, <,++-,D-,? TIME L for time 8al!es (e("(, +DED+E?= ( ?he "ran!larity of the time 8al!e is !s!ally a tic& (033
nanoseconds (

TIME WITH TIME FONE or TIMETF L the same as TIME, #!t incl!din" details a#o!t the time <one
in +!estion(

TIMEST$M! L ?his is a &$TE and a TIME p!t to"ether in one 8aria#le (e("(, <,++-,D-,? +DED+E?= (

TIMEST$M! WITH TIME FONE or TIMEST$M!TF L the same as TIMEST$M!, #!t incl!din"
details a#o!t the time <one in +!estion(

SQL pro8ides se8eral f!nctions for "eneratin" a date F time 8aria#le o!t of a date F time strin" (TO3&$TE, TO3TIME, TO3TIMEST$M! , as ,ell as for e7tractin" the respecti8e mem#ers (seconds, for instance of s!ch 8aria#les( ?he c!rrent system date F time of the data#ase ser8er can #e called #y !sin" f!nctions like NOW(

[edit]%ata

control

?he %ata .ontrol Lan"!a"e (%.L a!thori<es !sers and "ro!ps of !sers to access and manip!late data( :ts t,o main statements areG

GR$NT a!thori<es one or more !sers to perform an operation or a set of operations on an o#>ect( RE%OBE eliminates a "rant, ,hich may #e the defa!lt "rant(

-7ampleG GRANT SELECT. UPDATE ON M:3ta4l) TO so7)31s)(. anot2)(31s)(REVOKE SELECT. UPDATE ON M:3ta4l)

FROM so7)31s)(. anot2)(31s)(-

[edit]Mroced!ral

e7tensions

SQL is desi"ned for a specific p!rposeG to +!ery data contained in a relational data#ase( SQL is a set#ased, declarati8e +!ery lan"!a"e, not an imperati8e lan"!a"e like . or &4S:.( =o,e8er, there are e7tensions to Standard SQL ,hich add proced!ral pro"rammin" lan"!a"e f!nctionality, s!ch as control-of-flo, constr!cts( ?hese incl!deG

So rce

'ommon (ame

% ll (ame

01 I"I ! tandard

$%"4 M $%"4er,i,tent tored Module,

Interba,e" Firebird

4 $%

4rocedural $%

IBM DB'

$% 4%

$% 4rocedural %anguage )implement, $%"4 M*

IBM In7ormiC

4%

tored 4rocedural %anguage

Micro,o7t" yba,e

B- $%

Bran,act- $%

Mimer $%

$%"4 M $%"4er,i,tent tored Module )implement, $%"4 M*

My $%

$%"4 M $%"4er,i,tent tored Module )implement, $%"4 M*

!racle

4%" $% 4rocedural %anguage" $% )ba,ed on 0da*

4o,tgre $%

4%"pg $%

4rocedural %anguage"4o,tgre $% tructured $uery %anguage )ba,ed on !racle 4%" $%*

4o,tgre $%

4%"4 M 4rocedural %anguage"4er,i,tent tored Module, )implement, $%"4 M*

:n addition to the standard SQLFMS' e7tensions and proprietary SQL e7tensions, proced!ral and o#>ectoriented pro"ramma#ility is a8aila#le on many SQL platforms 8ia %&'S inte"ration ,ith other lan"!a"es( ?he SQL standard defines SQLF@$? e7tensions (SQL $o!tines and ?ypes for the @a8a Mro"rammin" Lan"!a"e to s!pport @a8a code in SQL data#ases( SQL Ser8er D335 !ses the SQL.L$ (SQL Ser8er .ommon Lan"!a"e $!ntime to host mana"ed (9-? assem#lies in the data#ase, ,hile prior 8ersions of SQL Ser8er ,ere restricted to !sin" !nmana"ed e7tended stored proced!res that ,ere primarily ,ritten in .( Most"reSQL allo,s f!nctions to #e ,ritten in a ,ide 8ariety of lan"!a"es incl!din" Merl, Mython, ?cl, and .([D3]

[edit]SQL

)perators
Description

!perator

#8ual

GH

1ot e8ual

Ireater than

%e,, than

HF

Ireater than or e8ual

GF

%e,, than or e8ual

B#B2##1 Bet3een an inclu,i@e range

%IJ#

earch 7or a pattern

I1

Bo ,peci7y multiple po,,ible @alue, 7or a column

[edit].riticism
SQL de8iates in se8eral ,ays from its theoretical fo!ndation, the relational model and its t!ple calc!l!s(

:n that model, a ta#le is a set of t!ples, ,hile in SQL, ta#les and +!ery res!lts are lists of ro,sG the same ro, may occ!r m!ltiple times, and the order of ro,s can #e employed in +!eries (e("( in the L:':? cla!se ( F!rthermore, additional feat!res (s!ch as 9ALL and 8ie,s ,ere introd!ced ,itho!t fo!ndin" them directly on the relational model, ,hich makes them more diffic!lt to interpret( .ritics ar"!e that SQL sho!ld #e replaced ,ith a lan"!a"e that strictly ret!rns to the ori"inal fo!ndation - see, e("( The Third ani)esto(

)ther criticisms of SQL incl!deG

:mplementations are incompati#le #et,een 8endors( :n partic!lar date and time synta7, strin" concatenation, N LLs, and comparison case sensiti8ity 8ary from 8endor to 8endor( 4 partic!lar e7ception is Most"reSQL, ,hich stri8es for compliance([D0]

[edit]Cross!"endor

portability

Mop!lar implementations of SQL commonly omit s!pport for #asic feat!res of Standard SQL, s!ch as the &$TE or TIME data types( ?he most o#8io!s s!ch e7amples, and incidentally the most pop!lar commercial, proprietary SQL %&'Ss, are )racle (,hose &$TE #eha8es as &$TETIME,[DD][D3] and lacks a TIME type
[D*]

and the 'S SQL Ser8er (#efore the D33; 8ersion ( 4s a res!lt, SQL code can rarely #e ported

#et,een data#ase systems ,itho!t modifications( ?here are se8eral reasons for this lack of porta#ility #et,een data#ase systemsG

?he comple7ity and si<e of the SQL standard means that most implementors do not s!pport the entire standard(

?he standard does not specify data#ase #eha8ior in se8eral important areas (e("( inde7es, file stora"eN , lea8in" implementations to decide ho, to #eha8e(

?he SQL standard precisely specifies the synta7 that a conformin" data#ase system m!st implement( =o,e8er, the standard/s specification of the semantics of lan"!a"e constr!cts is less ,ell-defined, leadin" to am#i"!ity(

'any data#ase 8endors ha8e lar"e e7istin" c!stomer #ases; ,here the SQL standard conflicts ,ith the prior #eha8ior of the 8endor/s data#ase, the 8endor may #e !n,illin" to #reak #ack,ard compati#ility(

Soft,are 8endors often desire to create incompati#ilities ,ith other prod!cts, as it pro8ides a stron" incenti8e for their e7istin" !sers to remain loyal (see 8endor lock-in (

[edit]Standardi<ation

SQL ,as adopted as a standard #y the 4merican 9ational Standards :nstit!te (49S: in 01;6 as SQL-;6[D5] and the :nternational )r"ani<ation for Standardi<ation (:S) in 01;2( 9o,adays the standard is s!#>ect to contin!o!s impro8ement #y the @oint ?echnical .ommittee IS"*IEC +TC ,, In)or!ation technology, Subco!!ittee SC -$, Data !anage!ent and interchange ,hich affiliate to :S) as ,ell as :-.( :t is commonly denoted #y the patternG IS"*IEC ./012n3yyyy 4art n3 title, or, as a shortc!t, IS"*IEC ./01( IS"*IEC ./01 is complemented #y IS"*IEC ,-$5.3 SQL ulti!edia and Application 4ac&ages ,hich defines

SQL #ased interfaces and packa"es to ,idely spread applications like 8ideo, a!dio and spatial data( Antil 0116, the 9ational :nstit!te of Standards and ?echnolo"y (9:S? data mana"ement standards pro"ram certified SQL %&'S compliance ,ith the SQL standard( Cendors no, self-certify the compliance of their prod!cts([D6] ?he ori"inal SQL standard declared that the official pron!nciation for SQL is "es +!e!e el"( [6] 'any -n"lishspeakin" data#ase professionals still !se the nonstandard [D2] pron!nciation /sikwl/(like the ,ord "se+!el" , incl!din" %onald .ham#erlin himself([D;] ?he SQL standard has "one thro!"h a n!m#er of re8isions, as sho,n #elo,G

.ea r

(ame

Alias

'omments

19-. $%--.

$%--7

Fir,t 7ormaliDed by 01 I.

19-9 $%--9

FI4 1'7-1

Minor re@i,ion+ adopted a, FI4 1'7-1.

199' $%-9'

$%'+ FI4 1'7-'

MaKor re@i,ion )I ! 9(7:*+ Entry Level $%-9' adopted a, FI4 1'7-'.

1999 $%&1999

$%/

0dded regular eCpre,,ion matching+ recur,i@e 8uerie,+ trigger,+ ,upport 7or procedural and control-o7-7lo3 ,tatement,+ non-,calar type,+ and ,ome obKect-oriented 7eature,.

'((/ $%&'((/

$% '((/

Introduced LM%-related 7eature,+ window functions+ ,tandardiDed ,e8uence,+ and column, 3ith auto-generated @alue, )including identitycolumn,*.

'((. $%&'((.

$% '((.

I !"I#C 9(7:-14&'((. de7ine, 3ay, in 3hich $% can be u,ed in conKunction 3ith LM%. It de7ine, 3ay, o7 importing and ,toring LM% data in an $% databa,e+ manipulating it 3ithin the databa,e and publi,hing both

LM% and con@entional $%-data in LM% 7orm. In addition+ it enable, application, to integrate into their $% code the u,e o7 L$uery+ the LM% $uery %anguage publi,hed by the 2orld 2ide 2eb Con,ortium )2/C*+ to concurrently acce,, ordinary $%-data and LM% document,.5'96

'((- $%&'((-

$% '((-

%egaliDe, !RD#R B> out,ide cur,or de7inition,. 0dd, I1 B#0D !F trigger,. 0dd, the BRE1C0B# ,tatement.5/(6

'(11 $%&'(11

:nterested parties may p!rchase SQL standards doc!ments from :S), :-. or 49S:( 4 draft of SQLGD33; is freely a8aila#le as a <ip archi8e([30]

[edit]Standard

structure

?he SQL standard is di8ided into nine parts(

:S)F:-. 1325-0GD300 Mart 0G )ramewor* (SQLFFrame,ork ( :t pro8ides lo"ical concepts( :S)F:-. 1325-DGD300 Mart DG )oundation (SQLFFo!ndation ( :t contains the most central elements of the lan"!a"e and consists of #oth !andatory and optional feat!res(

:S)F:-. 1325-3GD33; Mart 3G Call!Le"el Interface (SQLF.L: ( :t defines interfacin" components (str!ct!res, proced!res, 8aria#le #indin"s that can #e !sed to e7ec!te SQL statements from applications ,ritten in 4da, . respecti8ely .OO, .)&)L, Fortran, 'A'MS, Mascal or MLF:( (For @a8a see part 03( SQLF.L: is defined in s!ch a ,ay that SQL statements and SQLF.L: proced!re calls are treated as separate from the callin" application/s so!rce code( )pen %ata#ase .onnecti8ity is a ,ell-kno,n s!perset of SQLF.L:( ?his part of the standard consists solely of !andatory feat!res(

:S)F:-. 1325-*GD300 Mart *G Persistent Stored +odules (SQLFMS' :t standardi<es proced!ral e7tensions for SQL, incl!din" flo, of control, condition handlin", statement condition si"nals and resi"nals, c!rsors and local 8aria#les, and assi"nment of e7pressions to 8aria#les and parameters( :n addition, SQLFMS' formali<es declaration and maintenance of persistent data#ase lan"!a"e ro!tines (e("(, "stored proced!res" ( ?his part of the standard consists solely of optional feat!res(

:S)F:-. 1325-1GD33; Mart 1G +anagement of External (ata (SQLF'-% ( :t pro8ides e7tensions to SQL that define forei"n-data ,rappers and datalink types to allo, SQL to mana"e e7ternal data( -7ternal data is data that is accessi#le to, #!t not mana"ed #y, an SQL-#ased %&'S( ?his part of the standard consists solely of optional feat!res(

:S)F:-. 1325-03GD33; Mart 03G ,b-ect Language 'indings (SQLF)L& ( :t defines the synta7 and semantics of SQL@, ,hich is SQL em#edded in @a8a (see also part 3 ( ?he standard also descri#es mechanisms to ens!re #inary porta#ility of SQL@ applications, and specifies 8ario!s @a8a packa"es and their contained classes( ?his part of the standard consists solely of optionalfeat!res( 4s opposed to SQLF)L& @%&. - ,hich is not part of the SQL standard - defines an 4M:(

:S)F:-. 1325-00GD300 Mart 00G Information and (efinition Schemas (SQLFSchemata ( :t defines the :nformation Schema and %efinition Schema, pro8idin" a common set of tools to make SQL data#ases and o#>ects self-descri#in"( ?hese tools incl!de the SQL o#>ect identifier, str!ct!re and inte"rity constraints, sec!rity and a!thori<ation specifications, feat!res and packa"es of :S)F:-. 1325, s!pport of feat!res pro8ided #y SQL-#ased %&'S implementations, SQL-#ased %&'S implementation information and si<in" items, and the 8al!es s!pported #y the %&'S implementations( [3D] ?his part of the standard contains #oth !andatory and optional feat!res(

:S)F:-. 1325-03GD33; Mart 03G SQL .outines and /ypes Using the 0a"a Programming Language (SQLF@$? ( :t specifies the a#ility to in8oke static @a8a methods as ro!tines from ,ithin SQL applications (/@a8a-in-the-data#ase/ ( :t also calls for the a#ility to !se @a8a classes as SQL str!ct!red !ser-defined types( ?his part of the standard consists solely of optional feat!res(

:S)F:-. 1325-0*GD300 Mart 0*G 1+L!.elated Specifications (SQLFE'L ( :t specifies SQL-#ased e7tensions for !sin" E'L in con>!nction ,ith SQL( ?he 6 LType data type is introd!ced, as ,ell as se8eral ro!tines, f!nctions, and E'L-to-SQL data type mappin"s to s!pport manip!lation and stora"e of E'L in an SQL data#ase([D1] ?his part of the standard consists solely of optional feat!res([citation needed]

:S)F:-. 1325 is complemented #y :S)F:-. 03D*1 SQL

ulti!edia and Application 4ac&ages( ?his closely

related #!t separate standard is de8eloped #y the same committee( :t defines interfaces and packa"es ,hich are #ased on SQL( ?he aim is an !nified access to typical data#ase applications like te7t, pict!res, data minin" or spatial data(

:S)F:-. 03D*1-0GD332 Mart 0G )ramewor* :S)F:-. 03D*1-DGD333 Mart DG )ull!/ext :S)F:-. 03D*1-3GD300 Mart 3G Spatial :S)F:-. 03D*1-5GD333 Mart 5G Still image :S)F:-. 03D*1-6GD336 Mart 6G (ata mining :S)F:-. 03D*1-;G7777 Mart ;G +etadata registries #+(.& (,ork in pro"ress

[edit]4lternati8es
4 distinction sho!ld #e made #et,een alternati8es to relational +!ery lan"!a"es and alternati8es to SQL( &elo, are proposed relational alternati8es to SQL( See na8i"ational data#ase and 9oSQLfor alternati8es to relationalG

(QL - o#>ect-oriented %atalo" *% Q!ery Lan"!a"e (*% QL %atalo" =?SQL - A$L #ased +!ery method :&' &!siness System 0D (:&' &S0D - one of the first f!lly relational data#ase mana"ement systems, introd!ced in 01;D

:S&L @a8a Mersistence Q!ery Lan"!a"e (@MQL - ?he +!ery lan"!a"e !sed #y the @a8a Mersistence 4M: and =i#ernate persistence li#rary

@oSQL[33] - $!ns SQL statements ,ritten as Strin"s to +!ery collections from inside @a8a code( L:9Q - $!ns SQL statements ,ritten like lan"!a"e constr!cts to +!ery collections directly from inside (9et code(

)#>ect Q!ery Lan"!a"e Q&- (Q!ery &y -7ample created #y 'oshP Qloof, :&' 0122 Q!el introd!ced in 012* #y the A(.( &erkeley :n"res pro>ect( ?!torial % S&QL - the Stack &ased Q!ery Lan"!a"e (S&QL AnQL - the Anstr!ct!red Q!ery Lan"!a"e, a f!nctional s!perset of SQL, de8eloped #y the a!thors of SQLite and .o!ch%&

EQ!ery

[edit]See

also

Book: SQL

2i<ipedia boo<, are collection, o7 article, that can be do3nloaded or ordered in print.

.erner ..L .omparison of o#>ect-relational data#ase mana"ement systems .omparison of relational data#ase mana"ement systems % (data lan"!a"e specification %* (pro"rammin" lan"!a"e (an implementation of % =ierarchical model List of relational data#ase mana"ement systems 'A'MS 9oSQL

[edit]9otes
0( D300( D( 2 ":S)F:-. 1325-0GD33;G :nformation technolo"y R %ata#ase lan"!a"es R SQL R Mart 0G Frame,ork (SQLFFrame,ork " 3( 2 &ea!lie!, 4lan (4pril D331 ( 'ary - ?reseler( ed( Learning SQL (Dnd ed( ( Se#astapol, .4, AS4G )/$eilly( :S&9 12;-3-516-5D3;3-3( *( 2 %ar,en, =!"h (D335-3*-05 ( "'ore on $elational 4l"e#ra 8ers!s .alc!l!s"( :n Mascal, Fa#ian( Database Debun&ings 5( 2 .odd, -d"ar F (@!ne 0123 ( "4 $elational 'odel of %ata for Lar"e Shared %ata &anks"( Co!!unications o) the AC (4ssociation for .omp!tin" 'achinery 3$ (6 G 322R ;2(doiG03(00*5F36D3;*(36D6;5( $etrie8ed D332-36-31( 6( S a b .happle, 'ike( "SQL F!ndamentals"( Databases( 4#o!t(com( $etrie8ed D331-30-D;( 2 Ma!l, $yan( "4 "!ided to!r of the 'icrosoft .ommand Shell"( 4rs ?echnica( $etrie8ed 03 4pril

2(

2 "Str!ct!red Q!ery Lan"!a"e (SQL "( :nternational &!siness 'achines( )cto#er D2, D336( $etrie8ed D332-36-03(

;(

2 .ham#erlin, %onald %; &oyce, $aymond F (012* ("S-QA-LG 4 Str!ct!red -n"lish Q!ery Lan"!a"e" (M%F (4roceedings o) the ,.05 AC SI7FIDET 8or&shop on Data Description, Access and

Control (4ssociation for .omp!tin" 'achinery G D*1R6*( $etrie8ed D332-36-31( 1( S a b )ppel, 4ndy (Fe#r!ary D2, D33* ( Databases De!ysti)ied( San Francisco, .4G 'cTra,-=ill )s#orne 'edia( pp( 13R0( :S&9 3-32-0*6163-5( 03( 00( 2 "=istory of :&', 012;"( I% Archi9es( :&'( $etrie8ed D332-36-31(

2 49S:F:S)F:-. :nternational Standard (:S ( %ata#ase Lan"!a"e SQLLMart DG Fo!ndation (SQLFFo!ndation ( 0111(

0D(

2 "?ransact-SQL $eference"( SQL Ser9er Language Re)erence( SQL Ser8er D335 &ooks )nline( 'icrosoft( D332-31-05( $etrie8ed D332-36-02

03( 0*( 05( SQL( 06(

S a b :S)F:-.( IS"*IEC ./012$3$//-, :SQL*Foundation:( :S)F:-.( 2 .oles, 'ichael (D335-36-D2 ( "Fo!r $!les for 9!lls"(SQL Ser9er Central ($ed Tate Soft,are ( 2 '( 9e"ri, T( Mela"atti, L( S#attella (01;1 Se!antics and proble!s o) uni9ersal ;uanti)ication in

2 Fratarcan"eli, .la!dio (0110 ( Techni;ue )or uni9ersal ;uanti)ication in SQL( $etrie8ed from 4.'(or"(

02(

2 Ba,ash, @alal (D33* Co!ple( ;uanti)ication in Structured Query Language <SQL=3 a tutorial using relational calculus - @o!rnal of .omp!ters in 'athematics and Science ?eachin" :SS9 3230-1D5; Col!me D3, :ss!e D, D33* 44.- 9orfolk, Cir"inia( $etrie8ed from ?hefreeli#rary(com(

0;( 01(

2 In)or!ation Technology > Database Language SQL( .'A (proposed re8ised te7t of %:S 1325 ]( 2 4rie @ones, $yan B( Stephens, $onald $( Mle,, 4le7 Brie"el, $o#ert F( Tarrett (D335 , SQL Functions 4rogra!!er?s Re)erence( Wiley, 0D2 pa"es(

D3(

2 Most"reSQL contri#!tors (D300 ( "Most"reSQL ser8er pro"rammin""( 4ostgreSQL .., o))icial docu!entation( post"res+l(or"( $etrie8ed D30D-33-31(

D0(

2 Most"reSQL contri#!tors (D30D ( "4#o!t Most"reSQL"(4ostgreSQL .., o))icial @ebsite( Most"reSQL Tlo#al %e8elopment Tro!p( $etrie8ed 'arch 1, D30D( "Most"reSQL prides itself in standards compliance( :ts SQL implementation stron"ly conforms to the 49S:-SQLGD33; standard"

22.

2 Lorent<, %iana; $oeser, 'ary &eth; 4#raham, S!ndeep; 4mor, 4n"ela; 4rora, Teeta; 4rora, Cikas; 4shdo,n, Lance; &aer, =ermann et al( ()cto#er D303 [0116]( "&asic -lements of )racle SQLG %ata ?ypes"( "racle Database SQL Language Re)erence ,,g Release $ <,,.$=( )racle %ata#ase %oc!mentation Li#rary( $ed,ood .ity, .4G )racle AS4, :nc( $etrie8ed %ecem#er D1, D303( "For each &$TE8al!e, )racle stores the follo,in" informationG cent!ry, year, month, date, ho!r, min!te, and second"

23.

2 Lorent<, %iana; $oeser, 'ary &eth; 4#raham, S!ndeep; 4mor, 4n"ela; 4rora, Teeta; 4rora, Cikas; 4shdo,n, Lance; &aer, =ermann et al( ()cto#er D303 [0116]( "&asic -lements of )racle SQLG %ata ?ypes"( "racle Database SQL Language Re)erence ,,g Release $ <,,.$=( )racle %ata#ase %oc!mentation Li#rary( $ed,ood .ity, .4G )racle AS4, :nc( $etrie8ed %ecem#er D1, D303( "?he datetime data types are &$TEN"

24.

2 Lorent<, %iana; $oeser, 'ary &eth; 4#raham, S!ndeep; 4mor, 4n"ela; 4rora, Teeta; 4rora, Cikas; 4shdo,n, Lance; &aer, =ermann et al( ()cto#er D303 [0116]( "&asic -lements of )racle SQLG %ata ?ypes"( "racle Database SQL Language Re)erence ,,g Release $ <,,.$=( )racle %ata#ase %oc!mentation Li#rary( $ed,ood .ity, .4G )racle AS4, :nc( $etrie8ed %ecem#er D1, D303( "%o not define col!mns ,ith the follo,in" SQLF%S and %&D data types, #eca!se they ha8e no correspondin" )racle data typeGNTIME"

D5( D6(

2 "Findin" 4id"( 6-A$ Records, ,.0BC.1( 4merican 9ational Standards :nstit!te( 2 %oll, Shelley (@!ne 01, D33D ( ":s SQL a Standard 4nymoreU"( TechRepublic?s %uilder.co!( ?ech$ep!#lic( $etrie8ed D303-30-32(

D2(

2 'elton, @im; 4lan $ Simon (0113 ( "0(D( What is SQLU"(Dnderstanding the Ee@ SQL3 A Co!plete 7uide( 'or"an Ba!fmann( p( 536( :S&9 0-55;63-D*5-3( "SQL (correctly prono!nced "ess c!e ell," instead of the some,hat common "se+!el" N"

D;(

2 Tillespie, Matrick( "Mrono!ncin" SQLG S-Q-L or Se+!elU"(4ronouncing SQL3 S2Q2L or Se;uelF( $etrie8ed 0D Fe#r!ary D30D(

D1(

S a b Wa"ner, 'ichael (D303 ( SQL*6 L3$//G 2 E9aluierung der Standard&on)or!itHt ausge@Hhlter Datenban&syste!e( %iplomica Cerla"( p( 033( :S&9 3-;366-1631-6(

33( 30(

2 SQL3$//B no@ an appro9ed IS" international standard( Sy#ase( D33;-2( 2 (Qip SQL3$//B dra)t( Whitemarsh :nformation Systems .orporation(

3D( 33(

2 IS"*IEC ./012,,3$//B3 In)or!ation and De)inition Sche!as <SQL*Sche!ata=( D33;( p( 0( 2 "@oSQL official ,e#site"( so!rcefor"e(net( $etrie8ed D30D-33-31(

Вам также может понравиться