1. Trang chủ
  2. » Công Nghệ Thông Tin

Các Lệnh SQL Cơ Bản

46 592 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 46
Dung lượng 430,24 KB

Nội dung

Các Lệnh SQL Cơ Bản

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 1JQQJQKQJKDGOL£XEDRJPFDFFXO£QKFKRSKHSQJLVGX£QJQK QJKD&6'/YDFDF¢LW¤QJWURQJ&6'/QKFDFEDQJFDFNKXQJQKQFKPX£F 7DREDQJGOLX 'OL£XEQWURQJP¤W&6'/¤FW FKFOXWUWURQJFDFEDQJ%QWURQJFDF EDQJGOL£X¤FW FKFGLGD£QJFDFGRQJYDFDFF¤W0¡LP¤WGRQJEL XGL¡Q P¤WEDQJKLGX\QK¢WYDP¡LP¤WF¤WEL XGL¡QFKRP¤WWUQJ &DFWKXFWQKOLQTXDQQEDQJ .KLWD£RYDODPYL£FYLFDFEDQJGOL£XWDFQSKDL \¢QFDFWKX¤FWQK NKDFWUQEDQJQKNL XGOL£XFDFUDQJEX¤FFDFNKRDFDFTXLWF&DFWKX¤F WQKQD\¤FVGX£QJQKPWD£RUDFDFUDQJEX¤FWRDQYH£QWUQFDFF¤WWUQJWUQ EDQJFXQJQKWD£RUDFDFWRDQYH£QWKDPFKL¢XJLDFDFEDQJGOL£XWURQJ&6'/ D.LXGOLX 0¡LP¤WF¤WWUQJFXDP¤WEDQJXSKDLWKX¤FYDRP¤WNL XGOL£XQK¢W QKD¤FQKQJKDWWUF0¡LP¤WNL XGOL£XTXLQKFDFJLDWUGOL£X ¤FFKRSKHS¢LYLF¤WR&DFK£TXDQWU&6'/WKQJFXQJF¢SFDFNL XGOL£X FKX QQJRDLUDFRQFRWK FKRSKHSQJLVGX£QJQKQJKDFDFNL XGOL£XNKDF G£DWUQFDFNL XGOL£XDFR 'L\ODP¤WV¢NL XGOL£XWKQJ¤FVGX£QJWURQJJLDRWDF64/ Binary Bit Char Datetime Decimal Float Image Int Money Nchar Ntext Nvarchar Real Smalldatetime Smallint Smallmoney Text Tinyint Varbinary Varchar E&DFUDQJEXF&21675$,176 7UQFDFEDQJGOL£XFDFUDQJEX¤F¤FVGX£QJQKPFDFPX£FFKVDX • 4XLQKFDFJLDWUGOL£XKD\NKXQGD£QJGOL£X¤FFKRSKHSFK¢SQK£QWUQ FDFF¤WFXDEDQJUDQJEX¤F&+(&. • 4XLQKJLDWUP£FQKFKRFDFF¤WUDQJEX¤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 EDQJSKDLFRWQNKDFQKDXYDSKDLWXQWKHRFDF TXLWF YQK GDQK 0¡L P¤W EDQJSKDL FR W QK¢WP¤WF¤W - col_i_properties: &DFWKX¤FWQKFXDF¤WWKLTXLQKNL XGOL£X FXDF¤WYDFKQKF¤W FRFKRSKHSFK¢SQK£Q JLDWU18//KD\NKQJ - constraints_i: &DF UDQJ EX¤F Q¢X FR WUQ F¤W WK L QK FDF UDQJEX¤FYNKRDFDFP£FQKFDFTXLQKY NKXQGD£QJGOL£X - table_constraint: &DFUDQJEX¤FWUQEDQJGOL£X 9GX &XO£QKGL\WK£FKL£QKYL£FWD£REDQJ1+$19,(1EDRJPFDFF¤W 0$19+27(11*$<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 ) E6GXQJFDFUDQJEXFWURQJEDQJGOLX D DD D 5DQJEXF&+(&. 5DQJEX¤F&+(&.¤FVGX£QJ FKQKFDFJLDWUKD\NKXQGD£QJGOL£X FRWK  ¤F FK¢S QK£Q ¢L YL P¤W F¤W 7UQ P¤W F¤W FR WK  FR QKLX UDQJ EX¤F &+(&.j NKDLEDRP¤WUDQJEX¤F&+(&.¢LYLP¤WF¤WQDRRWDVGX£QJFX SKDSQKVDX [CONSTRAINT constraint_name] CHECK (expression) 7URQJR H[SUHVVLRQ ODP¤WEL XWKFORJLFTXLQKJLDWUKD\NKXQGD£QJFXDG OL£X¤FFKRSKHS.KLRFKQKQJJLDWUGOL£XQDRODPFKR H[SUHVVLRQ QK£QJLD WUXQJPL¤FFK¢SQK£Q 9GX j TXLQKL£QWKRD£LFXDQKQYLQSKDLFRGD£QJFKQJKD£Q FXO£QKYGX£¤FYL¢WQKVDX 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 5DQJEX¤F35,0$5<.(<¤FVGX£QJ QKQJKDNKRDFKQKFXDEDQJ 0¤WUDQJEX¤F35,0$5<.(<DPEDRUQJNKQJFRFDFJLDWUWUXQJO£S¤F DYDRWUQFDFF¤W+D\QRLFDFKNKDFJLDWUFXDNKRDFKQKVHJLXSFKRWD[DF QK¤FGX\QK¢WP¤WGRQJEDQJKLWURQJEDQJGOL£X0¡LP¤WEDQJFKFRWK  FRGX\QK¢WP¤WNKRDFKQKYDEDQWKQNKRDFKQKNKQJFK¢SQK£QJLDWU18// 5DQJEX¤F35,0$5<.(<ODFVFKRYL£FDPEDRWQKWRDQYH£QWK£FWK FXQJ QKWRDQYH£QWKDPFKL¢X j NKDLEDRP¤WUDQJEX¤F35,0$5<.(<ED£QVGX£QJFXSKDSVDX [CONSTRAINT constraint_name ] PRIMARY KEY [CLUSTERED|NONCLUSTERED] [( colname [,colname2 [ .,colname16]])] 1¢XNKRDFKQKFXDP¤WEDQJFKODP¤WF¤WNKLRED£QNKQJFQWKL¢WSKDLFK QKGDQKVDFKFDFF¤WVGX£QJUDQJEX¤FPFF¤W7URQJWUQJK¤SNKRDFKQK ODP¤WW£SK¤SWKDLF¤WWUOQED£QSKDLFKQKGDQKVDFKFDFF¤WVGX£QJUDQJ EX¤FPFEDQJ 9GX WD£REDQJ1+$19,(1YLNKRDFKQKOD0$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 ) FXO£QKWUQFRWK YL¢WQKVDX 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) ) 6DLEDQJ 6DXNKLDWD£REDQJED£QFRWK WL¢QKDQKVD LF¢XWUXFKD\WKX¤FWQKFXD EDQJQKE VXQJF¤WE VXQJNKRDWKD\ LFDFUDQJEX¤Fj FRWK VXD L EDQJED£QVGX£QJFXO£QK$/7(5FRFXSKDSQKVDX 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] .] 9GX 7D£RP¤WUDQJEX¤FFKREDQJ'219,WUQF¤W0$'9TXLQKPDQY SKDLFRGD£QJKDLFKV¢YGX£ 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 • 6GX£QJNKXQJQKQ QJLDQKRDWKDRWDFGOL£X • 6GX£QJNKXQJQKQ WX\EL¢QGOL£X • 6GX£QJNKXQJQKQ [X¢WNK XH[SRUWGOL£X • 6GX£QJNKXQJQKQ EDRP£WGOL£X j WD£RNKXQJQKQED£QVGX£QJFXO£QKFRFXSKDSQKVDX CREATE VIEW view_name[(column_name [, column_name] .)] AS select_statement 7URQJR VHOHFWBVWDWHPHQW ODP¤WFXO£QK6(/(&7GXQJ WUX\[X¢WGOL£XW P¤WKD\QKLXEDQJ .KLWD£RNKXQJQKQFQOX\P¤WV¢L PVDX • 7QNKXQJQKQSKDLWXQWKHRFDFTXLWFYQKGDQKYDSKDLGX\QK¢W¢LYL P¡LQJLVGX£QJ • .KQJWK UDQJEX¤FFDFP£FQKFDFTXLWFFKRNKXQJQKQ • .KQJWK [\G£QJFKPX£FFKRNKXQJQKQ • 7URQJFXO£QK&5($7(9,(:NKQJFQWKL¢WSKDLFKQKWQF¤W7QFXD FDFF¤WFXQJQKNL XGOL£XFXDFKXQJVHWQJQJYLFDFF¤WWURQJGDQKVDFK FKR¤QFXDFXO£QK6(/(&7 • %D£QSKDL[DFQKWQF¤WWURQJFXO£QK&5($7(9,(:WURQJFDFWUQJK¤S VDX − 0¡LF¤WFXDNKXQJQKQ¤FSKDWVLQKWP¤WEL XWKFV¢KR¤FP¤WKDPFDL VQKD\P¤WKQJ − +DLKD\QKLXF¤WFXDNKXQJQKQFRWUXQJWQ − %D£QPX¢QWKD\ LWQF¤WWURQJNKXQJQKQNKDFYLWQF¤WFXDEDQJFV 9GX &XO£QKGL\VHEO¡LGRWQFXDF¤WWKNKQJ[DFQK¤F CREATE VIEW thongtin_nv AS SELECT manv,hoten,datediff(year,ngaysinh,getdate()),tendv FROM nhanvien,donvi WHERE nhanvien.madv=donvi.madv j FXO£QKWUQFRWK WK£FKL£Q¤FED£QSKDL£WWQFKRFDFF¤WFXDNKXQJQKQ QKVDX CREATE VIEW thongtin_nv(manv,hoten,tuoi,donvi) . thức (các tên cột, các biểu thức số học, các hàm gộp, .) Các cột tương ứng trong tất cả các bảng, hoặc tập con bất kỳ các cột được sử dụng trong bản thân. câu lệnh SELECT Giaùo trỗnh thổỷc haỡnh SQL 7UDQJ &K ọn tất cả các cột trong bảng Khi muốn truy xuất tất cả các cột trong bảng, ta sử dụng câu lệnh

Ngày đăng: 19/12/2013, 23:29

HÌNH ẢNH LIÊN QUAN

Bảng dưới đây cho biết các cách kết hợp hợp lệ và không hợp lệ của phép nối trong và phép nối ngoài: - Các Lệnh SQL Cơ Bản
Bảng d ưới đây cho biết các cách kết hợp hợp lệ và không hợp lệ của phép nối trong và phép nối ngoài: (Trang 23)
Bảng R Bảng S - Các Lệnh SQL Cơ Bản
ng R Bảng S (Trang 24)

TỪ KHÓA LIÊN QUAN

w