¸ê®Æ®w¥i¥H¥]§t¼ÆÓ¸ê®Æªí¡A¤£¦P¸ê®Æªí¤§¶¡ªºÄæ¦ì¥i¥H¦³ÃöÁp©m¡A§ÚÌ¥i¥H®Ú¾Ú³o¨Ç¸ê®ÆÄæ¦ìªºÃöÁp©Ê¨Ó¨Ï¸ê®Æ®wªº¸ê®Æ§ó²Å¦X¹ê»Ú¥@¬Éªºª¬ªp¡A¦¹ºØ¨ã¦³ÃöÁp©Êªº¸ê®Æ®w¡A§YºÙ¬°ÃöÁp©Ê¸ê®Æ®w¡]Relational Databases¡^¡C§Ú̺¥ý¥H asp/example/database/song01.mdb ¤ºªº song ¸ê®Æªí¨Ó»¡©ú¡A¨ä¤º®e¦p¤U¡G
§Ç¸¹ ºq¦±¦WºÙ ¥D°ÛªÌ ¦~¥÷ 1 ¥Î¤ß¨}W ±i¦t 1993 2 Å¥®ü ±i´f©f 1998 4 ²o¤â ±i´f©f 2001 6 ³Ì¼ô±xªº¯¥Í¤H ¿½¨È°a 2000 8 ÅʤH¥¼º¡ S.H.E 2002 9 I.O.I.O. S.H.E 2002 11 ¨C¦¸³£·Q©I³Û§Aªº¦W¦r ¥Ã¨¹ 2002 12 ³Ì¼ô±xªº¯¥Í¤H ¿½¨È°a 2000 13 ì¨Ó§A¤°»ò³£¤£n ±i´f©f 1999 14 µ¡¥~ªº¤Ñ®ð ¿½¨È°a 1999 16 ³¥¦Ê¦X¤]¦³¬K¤Ñ ¥Ã¨¹ 2002 «Ü©úÅã¦a¡A¡u¥D°ÛªÌ¡vªºÄæ¦ì¤¤¡A«Ü¦h¸ê®Æ³£¬O«½Æªº¡A¦pªG§ÚÌÁÙn¼W¥[©M¡u¥D°ÛªÌ¡v¬ÛÃöªº¸ê®Æ¡A¨Ò¦p¡u¥X¹D¦~¥÷¡v¡B¡u¨°ª¡v¡B¡u¶Ý¦n¡vµ¥¡A´N·|¼W¥[§ó¦h«ÂЪº¸ê®Æ¡A¦]¦¹¡A§ÚÌ¥i¥H±N©M¥D°ÛªÌ¬ÛÃöªº¸ê®Æ©ñ¨ì¥t¤@Ó¸ê®Æªí singer¡A¨Ã«ü©w¨Cººq¦±¡]¦b song ¸ê®Æªí¡^©Ò¹ïÀ³ªººq¤â¡]¦b singer ¸ê®Æªí¡^¡A³o¼Ë°µªº¦n³B¬O¡G
- ´î¤Ö¸ê®Æªº«½Æ¡G¨Ò¦p¡u±i´f©f¡vªº¸ê®Æ¤£·|¥X²{«Ü¦h¦¸¡C
- «O«ù¸ê®Æªº¤@P©Ê¡G¡u±i´f©f¡v¥u¦³¤@µ§¸ê®Æ¡A¦]¦¹¤£»Ýn¿é¤J¡u±i´f©f¡v«Ü¦h¦¸¡A¤]¤ñ¸û¤£·|¥X²{§â¡u±i´f©f¡v»~¿é¤J¦¨¡u±i¿·©f¡vªº±¡ªp¡C
- «O«ù¸ê®Æªº§¹¾ã©Ê¡G¨Ò¦p§ÚÌ¥i¥H³W©w¡A¨S¦³¹ïÀ³ºq¤âªººq¦±¸ê®Æ¡A¤£¤¹³\µn¿ý¨ì song ¸ê®Æ®w¡C
¬°¤è«K»¡©ú°_¨£¡A§Ų́ϥΤ@Ó¸ê®Æ¸û¤ÖªºÀÉ®× asp/example/database/song02.mdb ¨Ó¶i¦æ¥H¤U»¡©ú¡A¨ä¤¤ song ¸ê®Æªíªº¤º®e¦p¤U¡G
§Ç¸¹ ¦WºÙ ºq¤â§Ç¸¹ ¦~¥÷ 1 ¥Î¤ß¨}W 1 1993 2 Å¥®ü 4 1998 8 ÅʤH¥¼º¡ 9 2002 9 I.O.I.O. 9 2002 17 ¯«¸Ü 0 1983 18 ªá¤ß 0 1993 singer ¸ê®Æªíªº¤º®e¦p¤U¡G
§Ç¸¹ ©m¦W Ãþ§O ¥X¹D¦~¥÷ 1 ±i¦t ¨kºq¤â 1973 4 ±i´f©f ¤kºq¤â 1975 6 ¿½¨È°a ¤kºq¤â 1971 9 S.H.E ¤k¹ÎÅé 1960 11 ¥Ã¨¹ ¨kºq¤â 1969 ¥Ñ¤Wz¦Cªí¥i¥Hª¾¹D¡A¨C¤@ººq¦³¤@ÓÄæ¦ì¬O¡uºq¤â§Ç¸¹¡v¡A«ü¨ì singer ¸ê®Æªíªº¡u§Ç¸¹¡vÄæ¦ì¡A´N¥i¥H§ä¨ì¹ïÀ³ªººq¤â¸ê®Æ¡C§ÚÌ¥i¥H¨Ï¥Î SQL ¬d¸ß¨Ó¦C¥Xºq¤â©Mºq¦±ªº©Ò¦³¥i¯à²Õ¦X¡A©Ò¥Îªº SQL «ü¥O¬°¡G
SELECT song.¦WºÙ, singer.©m¦W FROM song, singer; ©Ò±o¨ìªºµ²ªG¬O¡G
¦WºÙ ©m¦W ¥Î¤ß¨}W ±i¦t Å¥®ü ±i¦t ÅʤH¥¼º¡ ±i¦t I.O.I.O. ±i¦t ¯«¸Ü ±i¦t ªá¤ß ±i¦t ¥Î¤ß¨}W ±i´f©f Å¥®ü ±i´f©f ÅʤH¥¼º¡ ±i´f©f I.O.I.O. ±i´f©f ¯«¸Ü ±i´f©f ªá¤ß ±i´f©f ¥Î¤ß¨}W ¿½¨È°a Å¥®ü ¿½¨È°a ÅʤH¥¼º¡ ¿½¨È°a I.O.I.O. ¿½¨È°a ¯«¸Ü ¿½¨È°a ªá¤ß ¿½¨È°a ¥Î¤ß¨}W S.H.E Å¥®ü S.H.E ÅʤH¥¼º¡ S.H.E I.O.I.O. S.H.E ¯«¸Ü S.H.E ªá¤ß S.H.E ¥Î¤ß¨}W ¥Ã¨¹ Å¥®ü ¥Ã¨¹ ÅʤH¥¼º¡ ¥Ã¨¹ I.O.I.O. ¥Ã¨¹ ¯«¸Ü ¥Ã¨¹ ªá¤ß ¥Ã¨¹ ³oÓ¦Cªí¦@¦³ 30 µ§¸ê®Æ¡A¥Nªí¥Ñ²Ä¤@Ó¸ê®Æªí¡]6 µ§¸ê®Æ¡^©M²Ä¤GÓ¸ê®Æªí¡]5 µ§¸ê®Æ¡^ªº©Ò¦³¥i¯à²Õ¦X¡A¦ý¬O§Ų́èS¦³¥Î¨ì¨âÓ¸ê®Æªí¤§¶¡ªºÃöÁp¡A©Ò¥H±o¨ìªºµ²ªG·íµM¤£¥¿½T¡C§ÚÌ¥i¥H§â¦³ÃöÁp©ÊªºÄæ¦ì¡]¦b¦¹¨Ò¬O song ¸ê®Æªíªº¡uºq¤â§Ç¸¹¡v¥H¤Î singer ¸ê®Æªíªº¡u§Ç¸¹¡vÄæ¦ì¡^¥[¤J±ø¥ó¦¡¡A±o¨ì¤U¦Cªº SQL «ü¥O¡G
SELECT song.¦WºÙ, singer.©m¦W FROM singer, song WHERE (song.ºq¤â§Ç¸¹=singer.§Ç¸¹); ¹ïÀ³ªº¡u³]pÀ˵ø¡vµe±¬O¡G ©Ò±o¨ìªºµ²ªG¬O¡G
¦WºÙ ©m¦W ¥Î¤ß¨}W ±i¦t Å¥®ü ±i´f©f ÅʤH¥¼º¡ S.H.E I.O.I.O. S.H.E ¤Wzªº°µªk¬O¥H where ¤l¥y¨Ó«ü©w¸ê®Æ©Ò¥²¶·¨ã³Æªº¯S©Ê¡A¥t¤@ºØ°µªk«h¬Oª½±µ¦b¡u³]pÀ˵ø¡v¤¤«ü©w¸ê®Æªí¤§¶¡ªºÃöÁp¡A§ÚÌ¥i¥ý±N song ©M singer ¸ê®Æªí¥[¤J¡u³]pÀ˵ø¡vªº¬d¸ß¡AµM«á¿ï¨ú song ¸ê®Æªíªº¡uºq¤â§Ç¸¹¡vÄæ¦ì«á¡A©ì©ñ¨ì singer ¸ê®Æªíªº¡u§Ç¸¹¡vÄæ¦ì¡A´N¥i¥H«Ø¥ß³o¨âÓ¸ê®ÆªíªºÃöÁp©Ê¡]·|²£¥ÍÃöÁp½u¬q¥H³s±µ¦³ÃöÁp©ÊªºÄæ¦ì¡^¡AµM«á¦A¥[¤J»Ýn¬d¸ßªºÄæ¦ì¦WºÙ¡AÅã¥Üµe±¦p¤U¡G
¹ïÀ³ªº SQL «ü¥O¦p¤U¡GSELECT song.§Ç¸¹, song.¦WºÙ, singer.©m¦W FROM song INNER JOIN singer ON song.ºq¤â§Ç¸¹ = singer.§Ç¸¹; ©Ò±o¨ìªºµ²ªG¬O¡G
§Ç¸¹ ¦WºÙ ©m¦W 1 ¥Î¤ß¨}W ±i¦t 2 Å¥®ü ±i´f©f 8 ÅʤH¥¼º¡ S.H.E 9 I.O.I.O. S.H.E ¦b¤Wz½d¨Ò¤¤¡ASQL «ü¥O¨Ï¥Î¤F INNER JOIN¡C¨Æ¹ê¤W¡A¹ï©ó¸ê®Æªíªº³s±µ¡]Join¡^¡A¥i¥H¤À¦¨¤TÃþ¡G
¤å¦r»¡©ú¨Æ¹ê¤W¤£®e©öÁA¸Ñ¡AÅý§Ų́Ӭݬݽd¨Ò¡C¦pªG§ÚÌÂùÀ»³s±µÃöÁp©ÊÄæ¦ìªº½u¬q¡A´N·|¸õ¥X¡u³s±µÄÝ©Ê¡vªºµøµ¡¡A¦p¤U¡G ¦¹µøµ¡ªº¹w³]È´N¬O¡u¶È¥]§t¨âÓ¸ê®Æªí³s±µÄæ¦ìªº¸ê®Æ¬Û¦Pªº°O¿ý¡v¡A³o´N¬O Inner Join¡C¦pªG§ÚÌÂI¿ï²Ä 2ӿﶵ¡]¡u¥]¬A©Ò¦³¨Ó¦Û'song'ªº°O¿ý©M¥u¥]¬A¨º¨Ç³s±µÄæ¦ì¬Ûµ¥ªº'singer'Äæ¦ì¡v¡^¡A³o´N¬O Left Join¡A«ö¡u½T©w¡v¤§«á¡A¬d¸ßµe±¦p¤U¡G ¨ä¤¤ÃöÁp½u¬q³Q¥[¤W¤F¤@ӥѥª¦V¥kªº½bÀY¡A¥Nªí Left Join¡A¬Û¹ïÀ³ªº SQL ©R¥O¦p¤U¡G ¹ïÀ³ªº SQL «ü¥O¦p¤U¡G
- Inner Join¡G¥u·|¦C¥X¨Ó¨âÓ¸ê®Æªí³s±µÄæ¦ìªº¸ê®Æ¬Û¦Pªº°O¿ý¡C
- Left Join¡G¦C¥X©Ò¦³¨Ó¦Û¥ª¸ê®Æªíªº°O¿ý¡A¥H¤Î³s±µÄæ¦ì¬Ûµ¥ªº¥k¸ê®Æªíªº°O¿ý
- Right Join¡G¦C¥X©Ò¦³¨Ó¦Û¥k¸ê®Æªíªº°O¿ý¡A¥H¤Î³s±µÄæ¦ì¬Ûµ¥ªº¥ª¸ê®Æªíªº°O¿ý
SELECT song.§Ç¸¹, song.¦WºÙ, singer.©m¦W FROM song LEFT JOIN singer ON song.ºq¤â§Ç¸¹ = singer.§Ç¸¹; ©Ò±o¨ìªºµ²ªG¬O¡G
§Ç¸¹ ¦WºÙ ©m¦W 1 ¥Î¤ß¨}W ±i¦t 2 Å¥®ü ±i´f©f 8 ÅʤH¥¼º¡ S.H.E 9 I.O.I.O. S.H.E 17 ¯«¸Ü null 18 ªá¤ß null ¦¹µ²ªG¥Nªí¡u¦C¥X©Ò¦³ªººq¡A¥H¤Î³o¨Çºq©Ò¥i¯à¹ïÀ³ªººq¤â¡v¡C
¦pªG§ÚÌÂI¿ï²Ä 3 ӿﶵ¡]¡u¥]¬A©Ò¦³¨Ó¦Û'singer'ªº°O¿ý©M¥u¥]¬A¨º¨Ç³s±µÄæ¦ì¬Ûµ¥ªº'song'Äæ¦ì¡v¡^¡A³o´N¬O Right Join¡A¹ïÀ³ªº SQL ©R¥O¦p¤U¡G
SELECT song.§Ç¸¹, song.¦WºÙ, singer.©m¦W FROM song RIGHT JOIN singer ON song.ºq¤â§Ç¸¹ = singer.§Ç¸¹; ©Ò±o¨ìªºµ²ªG¬O¡G
§Ç¸¹ ¦WºÙ ©m¦W 1 ¥Î¤ß¨}W ±i¦t 2 Å¥®ü ±i´f©f null null ¿½¨È°a 9 I.O.I.O. S.H.E 8 ÅʤH¥¼º¡ S.H.E null null ¥Ã¨¹ ¦¹µ²ªG¥Nªí¡u¦C¥X©Ò¦³ªººq¤â¡A¥H¤Î³o¨Çºq¤â©Ò¥i¯à¹ïÀ³ªººq¡v¡C
¥H¤Wªº°µªk¡A¬O¦b«Ø¥ß¬d¸ß®É¡A¤~«Ø¥ß°_¸ê®Æªí¤§¶¡ªºÃöÁp¡A¥t¤@Ӥ覡¡A«h¬O¨Æ¥ý´N«Ø¥ß¦n¸ê®ÆªíªºÃöÁp¡A³o¬O¥Ã¤[©ÊªºÃöÁp¡A©Ò¥H¦b¶i¦æ¬d¸ß®É¡A¤]·|±N¦¹ÃöÁp¥]§t¶i¨Ó¡C¥H¸ê®Æ®w song02.mdb ¬°¨Ò¡A§ÚÌ¥i¥H¶}±Ò¡u¸ê®Æ®w¤u¨ã/¸ê®Æ®wÃöÁp¹Ï¡v¡A¬Ý¨ìªºµe±¦p¤U¡G
§ÚÌ¥i¥H¿ï¨ú song ¸ê®Æªíªº¡uºq¤â§Ç¸¹¡vÄæ¦ì«á¡A©ì©ñ¨ì singer ¸ê®Æªíªº¡u§Ç¸¹¡vÄæ¦ì¡A´N¥i¥H«Ø¥ß³o¨âÓ¸ê®Æªíªº¥Ã¤[ÃöÁp¡A¦¹®É·|¸õ¥X¨Ó¡u½s¿èÃöÁp¡vªºµe±¡A¦p¤U¡G ¦³Ãö³oÓµe±ªº¿ï¶µ¡u±j¢°Ñ¦Ò§¹¾ã©Ê¡v¡A§ÚÌ·|¦b¤U¤@¸`»¡©ú¡C¥Ø«e§A¥un«ö¤U¡u«Ø¥ß¡v¡A§Y¥i«Ø¥ß®Ú°ò©ó Inner Join ªº¥Ã¤[ÃöÁp¡A§A¤]¥i¥H«ö¤U¡u³s±µÃþ«¬¡v¡A¨Ó³]©w¨ä¥LÃþ§Oªº Join¡A¦p Left Join ©Î¬O Right Join¡C¦¹·s«Ø¥ßªºÃöÁp¡A·|¦b¡u¸ê®Æ®wÃöÁp¹Ï¡v¥H½u¬qªº¤è¦¡Åã¥Ü¥X¨Ó¡A¦¹½u¬q©Ò³sµ²ªºÄæ¦ì§Y¬O¤¬¦³ÃöÁpªºÄæ¦ì¡Aµe±¦p¤U¡G Yn½s¿èÃöÁp¡A¥i¥HÂùÀ»¦¹½u¬q¡A§Y¥i¶}±Ò¡u½s¿èÃöÁp¡vªºµøµ¡¡C¤@¥¹«Ø¥ß¥Ã¤[ÃöÁp«á¡A¦b¡u³]pÀ˵ø¡v¼Ò¦¡¤U½s¿è¬d¸ß®É¡A¥un¥[¤J¬ÛÃöªº¸ê®Æªí¡A§Y¥i¤ÏÀ³¦¹¥Ã¤[ÃöÁp¡A¦Ó¤£»Ýn¦A¦Û¦æ¤â°Ê¥[¤J¡C
JScript µ{¦¡³]p»PÀ³¥Î¡G¥Î©ó¦øªA¾¹ºÝªº ASP Àô¹Ò