SQL ( Structured Querry Language) là ngôn ngữ được sử dụng cho các hệ quản trị CSDL quan hệ. Ngôn ngữ SQL chuẩn được đưa ra bởi ANSI ( American National Standards Institute) và ISO ( International Standards Organization) với phiên bản mới nhất hiện nay là phiên bản SQL_ 92 ( phiên bản được đưa ra năm 1992). Mặc dù có nhiều ngôn ngữ khác nhau được đưa ra các hệ quản trị CSDL quan hệ....
Giaùo trỗnh thổỷc haỡnh SQL 7UDQJ *,lv,7+,j8 64/6WUXFWXUHG4XHU\/DQJXDJHODQJQQJÔFVGXÊQJFKRFDFKÊTXDQ WUF VGOLÊX TXDQKÊ 1JQ QJ 64/ FKXQ ÔF D UD EL $16,$PHULFDQ 1DWLRQDO 6WDQGDUGV ,QVWLWXGH YD ,62 ,QWHUQDWLRQDO 6WDQGDUGV 2UJDQL]DWLRQ YL SKLQ EDQ PL QKÂW KLÊQ QD\ OD SKLQ EDQ 64/ SKLQ EDQ ÔF D UD QP 0ÊFGXFRQKLXQJQQJNKDFQKDXÔFDUDFKRFDFKÊTXDQWU&6'/ TXDQKÊ64/ODQJQQJÔFVGXÊQJUÔQJUDLKLÊQQD\WURQJUÂWQKLXKÊWKÂQJ &6'/WKQJPDÊLQK2UDFOH64/6HUYHU'%0LFURVRIW$FFHVV7KQJTXD64/ QJLVGXÊQJFRWKGĂGDQJQKQJKDÔFGOLÊXWKDRWDFYLGOLÊX0ÊW NKDF\ODQJQQJFRWQKNKDLEDRQQQRGĂVGXÊQJYDFXQJYYÊ\PDWUQQ SKELÂQ *LDRWULQKQD\QKPFXQJFÂSFKREDÊQWDLOLÊXWKDPNKDRWQJÂL\XY FDFFXOÊQK JLDRWDF 64/ V GXÊQJFKRKÊ TXDQ WU &6'/ 0LFURVRIW64/ 6HUYHU *LDRWUQKEDRJPEÂQFKQJ &KQJJLLWKLÊXPÔWVÂFXOÊQKVGXÊQJWURQJYLÊFQKQJKDFDFÂL WÔQJGOLÊXQKEDQJGOLÊXNKXQJQKQYDFKPXÊF &KQJ WUQK ED\ EÂQ FX OÊQK WKDR WDF G OLÊX OD 6(/(&7 ,16(57 83'$7(YD'(/(7(WURQJRWÊSWUXQJFKX\ÂXFXOÊQK6(/(&7 &KQJFÊSÂQKDLFXOÊQKLXNKLQOD*5$17YD5(92.(VGXÊQJ WURQJYLÊFFÂSSKDWYDKX\ERTX\QFXDQJLVGXÊQJ&6'/ &KQJ JLL WKLÊX Y WKX WXÊF OX WU YD WULJJHU j\ OD QKQJ ÂL WÔQJ &6'/ÔFVGXÊQJQKPWQJKLÊXQQJNKLVGXÊQJ&6'/ 7URQJFKQJSKXÊOXÊFFKXQJWLJLLWKLÊXFÂXWUXFYDGOLÊXFXDFDFEDQJV GXÊQJWURQJFDFYGXÊFKQJEDÊQWLÊQWUDFXYDÂLFKLÂXYLFDFYGXÊDQX 1JRDLUDWURQJFKQJQD\FRQFRFDFKDPWKQJVGXÊQJWURQJ64/6HUYHUFDF EDÊQWKDPNKDRWURQJWKÊFKDQK 0ÊFGXDUÂWFÂJQJQKQJJLDRWUQKNKQJWKWUDQKXÔFFDFVDLVRW5ÂW PRQJQKÊQÔFVÊJRS\FXDFDFEDÊQJLDRWUQKQJD\FDQJKRDQWKLÊQKQ Tráön Nguyãn Phong C C h h æ æ å å n n g g 1 1 : : N N G G Ä Ä N N N N G G Æ Æ Î Î Â Â Ë Ë N N H H N N G G H H É É A A D D Æ Æ Î Î L L I I Ã Ã Û Û U U 1JQQJQKQJKDGOL£XEDRJPFDFFXO£QKFKRSKHSQJLVGX£QJQK QJKD&6'/YDFDF¢LW¤QJWURQJ&6'/QKFDFEDQJFDFNKXQJQKQFKPX£F 7DREDQJGOLX 'OL£XEQWURQJP¤W&6'/¤FW FKFOXWUWURQJFDFEDQJ%QWURQJFDF EDQJGOL£X¤FW FKFGLGD£QJFDFGRQJYDFDFF¤W0¡LP¤WGRQJEL XGL¡Q P¤WEDQJKLGX\QK¢WYDP¡LP¤WF¤WEL XGL¡QFKRP¤WWUQJ &DFWKXFWQKOLQTXDQQEDQJ .KLWD£RYDODPYL£FYLFDFEDQJGOL£XWDFQSKDL \¢QFDFWKX¤FWQK NKDFWUQEDQJQKNL XGOL£XFDFUDQJEX¤FFDFNKRDFDFTXLWF&DFWKX¤F WQKQD\¤FVGX£QJQKPWD£RUDFDFUDQJEX¤FWRDQYH£QWUQFDFF¤WWUQJWUQ EDQJFXQJQKWD£RUDFDFWRDQYH£QWKDPFKL¢XJLDFDFEDQJGOL£XWURQJ&6'/ D.LXGOLX 0¡LP¤WF¤WWUQJFXDP¤WEDQJXSKDLWKX¤FYDRP¤WNL XGOL£XQK¢W QKD¤FQKQJKDWWUF0¡LP¤WNL XGOL£XTXLQKFDFJLDWUGOL£X ¤FFKRSKHS¢LYLF¤WR&DFK£TXDQWU&6'/WKQJFXQJF¢SFDFNL XGOL£X FKX QQJRDLUDFRQFRWK FKRSKHSQJLVGX£QJQKQJKDFDFNL XGOL£XNKDF G£DWUQFDFNL XGOL£XDFR 'L\ODP¤WV¢NL XGOL£XWKQJ¤FVGX£QJWURQJJLDRWDF64/ Binary Bit Char Datetime Decimal Float Image Int Money Nchar Ntext Nvarchar Real Smalldatetime Smallint Smallmoney Text Tinyint Varbinary Varchar E&DFUDQJEXF&21675$,176 7UQFDFEDQJGOL£XFDFUDQJEX¤F¤FVGX£QJQKPFDFPX£FFKVDX • 4XLQKFDFJLDWUGOL£XKD\NKXQGD£QJGOL£X¤FFKRSKHSFK¢SQK£QWUQ FDFF¤WFXDEDQJUDQJEX¤F&+(&. • 4XLQKJLDWUP£FQKFKRFDFF¤WUDQJEX¤F'()$8/7 Giaùo trỗnh thổỷc haỡnh SQL 7UDQJ 7DÊRQQWQKWRDQYHÊQWKÊFWKWURQJPÔWEDQJGOLÊXYDWRDQYHÊQWKDPFKLÂXJLD FDF EDQJ G OLÊX WURQJ &6'/ UDQJ EXÔF 35,0$5< .(< 81,48( YD )25(,*1.(< &KXQJWDVHWPKLXFKLWLÂWKQYFDFUDQJEXÔFQD\SKQWUQKED\YFXOÊQK &5($7(7$%/( 7DREDQJEQJWUX\YQ64/ 7DÊRFDFEDQJODPÔWNKXTXDQWURQJWURÔQJWURQJTXDWUQKWKLÂWNÂYDFDLGÊW FDF&6'/%QWURQJFDF&6'/PĂLPÔWEDQJWKQJÔFVGXÊQJQKPELXGLĂQ WKQJWKLYFDFÂLWÔQJWURQJWKÂJLLWKÊFYDKRÊFELXGLĂQPÂLTXDQKÊJLDFDF ÂLWÔQJRjFRWKWFKFWÂWPÔWEDQJGOLÊXEDÊQWQKÂWFQSKDL[DFQK ÔFFDF\XFXVDX %DQJÔFVGXÊQJQKPPXÊFFKJYDFRYDLWURQKWKÂQDREQWURQJ&6'/" %DQJVHEDRJPQKQJFÔWQDRYDNLXGOLÊXFKRFDFFÔWRODJ" 1KQJFÔWQDRFKRSKHSFKÂSQKÊQJLDWU18// &RVGXÊQJFDFUDQJEXÔFFDFPÊFQKKD\NKQJYDQÂXFRWKVGXÊQJXYD QKXWKÂQDR" 1KQJFÔWQDRVHRQJYDLWURODNKRDFKQKNKRDQJRDLNKRDGX\QKÂW"1KQJ GDÊQJFKPXÊFQDRODFQWKLÂWYDFQX D7DREDQJGOLX jWDÊRPÔWEDQJWURQJ&6'/EDÊQVGXÊQJFXOÊQK&5($7(7$%/(FRFX SKDSQKVDX CREATE TABLE table_name ( {colname_1 col_1_properties [constraints_1 ] [,{colname_2 col_2_properties [constraints_2 ]] . [,{colname_N col_N_properties [constraints_N ]] [table_constraints] ) 7URQJR - table_name: 7QEDQJ FQWDÊR 7QFXD EDQJ SKDL GX\QKÂW WURQJPĂL&6'/YDSKDLWXQWKHRFDFTXLWFY QKGDQK - colname_i: 7QFXDFÔWWKLWURQJEDQJ&DFFÔWWURQJPĂL Tráön Nguyãn Phong EDQJSKDLFRWQNKDFQKDXYDSKDLWXQWKHRFDF TXLWF YQK GDQK 0¡L P¤W EDQJSKDL FR W QK¢WP¤WF¤W - col_i_properties: &DFWKX¤FWQKFXDF¤WWKLTXLQKNL XGOL£X FXDF¤WYDFKQKF¤W FRFKRSKHSFK¢SQK£Q JLDWU18//KD\NKQJ - constraints_i: &DF UDQJ EX¤F Q¢X FR WUQ F¤W WK L QK FDF UDQJEX¤FYNKRDFDFP£FQKFDFTXLQKY NKXQGD£QJGOL£X - table_constraint: &DFUDQJEX¤FWUQEDQJGOL£X 9GX &XO£QKGL\WK£FKL£QKYL£FWD£REDQJ1+$19,(1EDRJPFDFF¤W 0$19+27(11*$<6,1+',$&+,',(17+2$, CREATE TABLE nhanvien ( manv char(10) not null, hoten char(30) not null, ngaysinh datetime null, diachi char(50) null, dienthoai char(6) null ) E6GXQJFDFUDQJEXFWURQJEDQJGOLX D DD D 5DQJEXF&+(&. 5DQJEX¤F&+(&.¤FVGX£QJ FKQKFDFJLDWUKD\NKXQGD£QJGOL£X FRWK ¤F FK¢S QK£Q ¢L YL P¤W F¤W 7UQ P¤W F¤W FR WK FR QKLX UDQJ EX¤F &+(&.j NKDLEDRP¤WUDQJEX¤F&+(&.¢LYLP¤WF¤WQDRRWDVGX£QJFX SKDSQKVDX [CONSTRAINT constraint_name] CHECK (expression) 7URQJR H[SUHVVLRQ ODP¤WEL XWKFORJLFTXLQKJLDWUKD\NKXQGD£QJFXDG OL£X¤FFKRSKHS.KLRFKQKQJJLDWUGOL£XQDRODPFKR H[SUHVVLRQ QK£QJLD WUXQJPL¤FFK¢SQK£Q 9GX j TXLQKL£QWKRD£LFXDQKQYLQSKDLFRGD£QJFKQJKD£Q FXO£QKYGX£¤FYL¢WQKVDX CREATE TABLE nhanvien ( Giaùo trỗnh thổỷc haỡnh SQL 7UDQJ manv char(10) not null, hoten char(30) not null, ngaysinh datetime null, diachi char(50) null, dienthoai char(6) null constraint check_dienthoai check (dienthoai like '[0-9][0-9][0-9] [0-9][0-9] [0-9]') ) D DD D 5DQJEXF'()$8/7 5DQJEXÔF'()$8/7ÔFVGXÊQJTXLQKJLDWUPÊFQKFKRPÔWFÔW *LDWUQD\VHWÊÔQJÔFJDQFKRFÔWQD\NKLQJLVGXÊQJEVXQJPÔWEDQJKL PDNKQJFKQKJLDWUFKRFÔW7UQPĂLFÔWFKFRWKFRQKLXQKÂWPÔWUDQJ EXÔF'()$8/7WFODFKFRWKFRWÂLDPÔWJLDWUPÊFQK j NKDL EDR PÔW JLD WU PÊF QK FKR PÔW FÔW WD FK QK PÔW UDQJ EXÔF '()$8/7FKRFÔWEQJFDFKVGXÊQJFXSKDSVDX [CONSTRAINT constraint_name] DEFAULT {const_expression nonarguments_function NULL} 9 GX &X OÊQK GL \ FK QK JLD WU PÊF QK OD NKQJ ELÂW FKR FÔW ',$&+,WURQJEDQJ1+$19,(1YGXÊ CREATE TABLE nhanvien ( manv char(10) not null, hoten char(30) not null, ngaysinh datetime null, diachi char(50) default 'khọng bióỳt', dienthoai char(6) null ) D DD D 5DQJEXF35,0$5<.(< muYGXÊQD\FKXQJWLNKQJÊWWQFKRUDQJEXÔF'()$8/7.KLRKÊTXDQWU&6'/VHWÊÔQJÊWWQ FKRUDQJEXÔFQD\7X\QKLQGĂGDQJFKRYLÊFTXDQWUEDÊQQQÊWWQFKRFDFUDQJEXÔF Tráön Nguyãn Phong 5DQJEX¤F35,0$5<.(<¤FVGX£QJ QKQJKDNKRDFKQKFXDEDQJ 0¤WUDQJEX¤F35,0$5<.(<DPEDRUQJNKQJFRFDFJLDWUWUXQJO£S¤F DYDRWUQFDFF¤W+D\QRLFDFKNKDFJLDWUFXDNKRDFKQKVHJLXSFKRWD[DF QK¤FGX\QK¢WP¤WGRQJEDQJKLWURQJEDQJGOL£X0¡LP¤WEDQJFKFRWK FRGX\QK¢WP¤WNKRDFKQKYDEDQWKQNKRDFKQKNKQJFK¢SQK£QJLDWU18// 5DQJEX¤F35,0$5<.(<ODFVFKRYL£FDPEDRWQKWRDQYH£QWK£FWK FXQJ QKWRDQYH£QWKDPFKL¢X j NKDLEDRP¤WUDQJEX¤F35,0$5<.(<ED£QVGX£QJFXSKDSVDX [CONSTRAINT constraint_name ] PRIMARY KEY [CLUSTERED|NONCLUSTERED] [( colname [,colname2 [ .,colname16]])] 1¢XNKRDFKQKFXDP¤WEDQJFKODP¤WF¤WNKLRED£QNKQJFQWKL¢WSKDLFK QKGDQKVDFKFDFF¤WVGX£QJUDQJEX¤FPFF¤W7URQJWUQJK¤SNKRDFKQK ODP¤WW£SK¤SWKDLF¤WWUOQED£QSKDLFKQKGDQKVDFKFDFF¤WVGX£QJUDQJ EX¤FPFEDQJ 9GX WD£REDQJ1+$19,(1YLNKRDFKQKOD0$19 CREATE TABLE nhanvien ( manv char(10) primary key, hoten char(30) not null, ngaysinh datetime null, diachi char(50) null, dienthoai char(6) null ) FXO£QKWUQFRWK YL¢WQKVDX CREATE TABLE nhanvien ( manv char(10) not null, hoten char(30) not null, ngaysinh datetime null, diachi char(50) null, dienthoai char(6) null constraint pk_nv primary key(manv) ) Giaùo trỗnh thổỷc haỡnh SQL 7UDQJ D 5DQJEXF81,48( 7KD\YVGXÊQJNKRDFKQKEDÊQFRWKVGXÊQJUDQJEXÔF81,48(DP EDRWQKWRDQYHÊQWKÊFWK6GXÊQJUDQJEXÔF81,48(WUQPÔWKD\QKLXFÔWEW EXÔFFDFJLDWUGOLÊXWUQPÔWKD\QKLXFÔWQD\NKQJÔFWUXQJOÊSQKDXj NKDLEDRPÔWUDQJEXÔF81,48(EDÊQVGXÊQJFXSKDSOÊQKVDX\ [CONSTRAINT constraint_name] UNIQUE [CLUSTERED | NONCLUSTERED] [colname1 [,colname2 [ .,colname16]])] D 5DQJEXF)25(,*1.(< &DFEDQJEQWURQJPÔW&6'/WKQJFRPÂLTXDQKÊYLQKDX&DFPÂLTXDQ KÊQD\ÔF[DFQKGÊDWUQWQKEQJQKDXJLDPÔWKD\QKLXWUQJFXDEDQJ QD\YLPÔWKD\QKLXWUQJFXDEDQJNKDF1ÂXPÔWKD\QKLXFÔWQDRRFXDPÔW EDQJFRJLDWUÔF[DFQKWPÔWKD\QKLXWUQJNKRDFXDEDQJNKDFWKFDF FÔWRÔFJRÔLODFRUDQJEXÔFNKRDQJRDÊLIRUHLJQNH\&DFUDQJEXÔF)25(,*1 .(<ÔFVGXÊQJNÂWKÔSYLFDFUDQJEXÔF35,0$5<.(<YD81,48(QKP DPEDRWQKWRDQYHÊQWKDPFKLÂXJLDFDFEDQJÔFFKQK jNKDLEDRNKRDQJRDÊLEDÊQVGXÊQJFXSKDSOÊQKQKVDX [CONSTRAINT constraint_name ] [FOREIGN KEY (colname [,colname2 [ .,colname16]])] REFERENCES reference_table [(ref_colname [,ref_colname2 [ .,ref_colname 16]])] 9 GX 7DÊR KDL EDQJ 1+$19,(10$19 +27(1 1*$<6,1+ ',$&+, ',(17+2$,0$'9YD'219,0$'97(1'9WKHRKQKGL\ CREATE TABLE donvi ( 1+$19,(1 0$19 +27(1 1*$<6,1+ ',$&+, ',(17+2$, 0$'9 '219, 0$'9 7(1'9 +QK Tráön Nguyãn Phong madv char(2) primary key, tendv char(20) not null ) CREATE TABLE nhanvien ( manv char(10) primary key, hoten char(20) not null, ngaysinh datetime null, diachi char(50) default 'khong biet', dienthoai char(6) check(dienthoai like '[0-9][0-9][0-9] [0-9][0-9][0-9]'), madv char(2) foreign key(madv) references donvi(madv) ) 6DLEDQJ 6DXNKLDWD£REDQJED£QFRWK WL¢QKDQKVD LF¢XWUXFKD\WKX¤FWQKFXD EDQJQKE VXQJF¤WE VXQJNKRDWKD\ LFDFUDQJEX¤Fj FRWK VXD L EDQJED£QVGX£QJFXO£QK$/7(5FRFXSKDSQKVDX ALTER TABLE table_name [ADD {col_name column_properties [column_constraints] [[,]table_constraint ] } [,{next_col_name|next_table_constraint}] .] [DROP [CONSTRAINT] constraint_name1 [, constraint_name2] .] 9GX 7D£RP¤WUDQJEX¤FFKREDQJ'219,WUQF¤W0$'9TXLQKPDQY SKDLFRGD£QJKDLFKV¢YGX£ ALTER TABLE donvi ADD CONSTRAINT check_madv CHECK (madv LIKE ‘[0-9][0-9]’) Giaùo trỗnh thổỷc haỡnh SQL 7UDQJ &KPXFLQGH[ &DFFKPXÊFÔFVGXÊQJQKPKĂWUÔYLÊFWUX\FÊSÂQFDFGRQJGOLÊXÔF QKDQKFKRQJGÊDWUQFDFJLDWUFXDPÔWKD\QKLXFÔW&KPXÊFÔFFKLDUDODPKDL ORDÊLFKPXÊF WXÊ QKRPFOXVWHUHG LQGH[YD FKPXÊF NKQJ WXÊ QKRP QRQFOXVWHUHG LQGH[ 0ÔWFKPXÊFWXÊQKRPODPÔWFKPXÊFPDWURQJRWKWÊORJLFFXDFDFNKRDWQJ WÊQKWKWÊYÊWO\FXDFDFGRQJWQJQJWQWDÊLWURQJEDQJ0ÔWEDQJFKFR WKFRWÂLDPÔWFKPXÊFWXÊQKRP 0ÔWFKPXÊFNKQJWXÊKRPODPÔWFKPXÊFPDWURQJRWKWÊORJLFFXDFDFNKRD NKQJQKWKWÊYÊWO\FXDFDFGRQJWURQJEDQJ&DFFKPXÊFWXÊQKRPKĂWUÔYLÊF WUX\FÊSÂQFDFGRQJGOLÊXQKDQKKQQKLXVRYLFDFFKPXÊFNKQJWXÊQKRP .KLWDNKDLEDRPÔWNKRDFKQKKD\NKRD81,48(WUQPÔWKD\QKLXFÔWQDRR FXDEDQJKÊTXDQWU&6'/VHWÊÔQJWDÊRFKPXÊFWUQFDFFÔWR%DÊQFRWKWDÊR WKPFDFFKPXÊFNKDFEQJFDFKVGXÊQJFXOÊQKFRFXSKDSQKVDX CREATE [CLUSTEREDNONCLUSTERED] INDEX index_name ON table_name(column_name [, column_name] .) 9GX &XOÊQKGL\VHWDÊRPÔWFKPXÊFNKQJWXÊQKRPWUQFÔW0$'9FXD EDQJ1+$19,(1 CREATE NONCLUSTERED INDEX idx_nhanvien_madv ON nhanvien(madv) .KXQJQKQ9LHZ 0ÔWNKXQJQKQFRWKFRLQKODPÔWeEDQJDRfFRQÔLGXQJÔF[DFQKW PÔWWUX\YÂQ0ÔWWUX\YÂQTXHU\ODPÔWWÊSFDFFKGĂQLQVWUXFWLRQQKPWUX\ [XÂWYDKLQWKGOLÊXWFDFEDQJWURQJ&6'/&DFWUX\YÂQÔFWKÊFKLÊQEQJ FDFKVGXÊQJFXOÊQK6(/(&7ÔFFÊSÂQWURQJFKQJ 0ÔWNKXQJQKQWURQJJLÂQJQKPÔWEDQJYLPÔWWÊRFDFWQFÔWYDFDFGRQJ GOLÊX7X\QKLQNKXQJQKQNKQJWQWDÊLQKODPÔWFÂXWUXFOXWUGOLÊXWURQJ &6'/'OLÊXEQWURQJNKXQJQKQWKÊFFKÂWODGOLÊXÔF[DFQKWPÔWKD\ QKLXEDQJFVYDGRRSKXÊWKÔFYDRFDFEDQJFV &DFNKXQJQKQWKQJÔFVGXÊQJEQWURQJ&6'/QKPFDFPXÊFFKVDX \ 6GXÊQJNKXQJQKQWÊSWUXQJWUQGOLÊXÔF[DFQK Tráön Nguyãn Phong • 6GX£QJNKXQJQKQ QJLDQKRDWKDRWDFGOL£X • 6GX£QJNKXQJQKQ WX\EL¢QGOL£X • 6GX£QJNKXQJQKQ [X¢WNK XH[SRUWGOL£X • 6GX£QJNKXQJQKQ EDRP£WGOL£X j WD£RNKXQJQKQED£QVGX£QJFXO£QKFRFXSKDSQKVDX CREATE VIEW view_name[(column_name [, column_name] .)] AS select_statement 7URQJR VHOHFWBVWDWHPHQW ODP¤WFXO£QK6(/(&7GXQJ WUX\[X¢WGOL£XW P¤WKD\QKLXEDQJ .KLWD£RNKXQJQKQFQOX\P¤WV¢L PVDX • 7QNKXQJQKQSKDLWXQWKHRFDFTXLWFYQKGDQKYDSKDLGX\QK¢W¢LYL P¡LQJLVGX£QJ • .KQJWK UDQJEX¤FFDFP£FQKFDFTXLWFFKRNKXQJQKQ • .KQJWK [\G£QJFKPX£FFKRNKXQJQKQ • 7URQJFXO£QK&5($7(9,(:NKQJFQWKL¢WSKDLFKQKWQF¤W7QFXD FDFF¤WFXQJQKNL XGOL£XFXDFKXQJVHWQJQJYLFDFF¤WWURQJGDQKVDFK FKR¤QFXDFXO£QK6(/(&7 • %D£QSKDL[DFQKWQF¤WWURQJFXO£QK&5($7(9,(:WURQJFDFWUQJK¤S VDX − 0¡LF¤WFXDNKXQJQKQ¤FSKDWVLQKWP¤WEL XWKFV¢KR¤FP¤WKDPFDL VQKD\P¤WKQJ − +DLKD\QKLXF¤WFXDNKXQJQKQFRWUXQJWQ − %D£QPX¢QWKD\ LWQF¤WWURQJNKXQJQKQNKDFYLWQF¤WFXDEDQJFV 9GX &XO£QKGL\VHEO¡LGRWQFXDF¤WWKNKQJ[DFQK¤F CREATE VIEW thongtin_nv AS SELECT manv,hoten,datediff(year,ngaysinh,getdate()),tendv FROM nhanvien,donvi WHERE nhanvien.madv=donvi.madv j FXO£QKWUQFRWK WK£FKL£Q¤FED£QSKDL£WWQFKRFDFF¤WFXDNKXQJQKQ QKVDX CREATE VIEW thongtin_nv(manv,hoten,tuoi,donvi) . sau: Họ và tên Hệ số lương ---------------- -------------- ------------- Trần Nguyên Phong Hệ số lương là : 1.92 Lê Hoài Nam Hệ số lương là : 1.86 Nguyễn Hữu. dụng UNION với các giao tác SQL khác Các nguyên tắc sau phải được tuân theo khi sử dụng phép hợp với các câu lệnh giao tác SQL khác: Truy vấn đầu tiên