¼ø¶È»ñÎÁ/14
¥Ç¡¼¥¿¤Î¼è¤ê°·¤¤¤Ë¤Ä¤¤¤Æ †
¤¢¤ëÄøÅÙÂ絬ÌϤÀ¤Ã¤¿¤êÊ£»¨¤À¤Ã¤¿¤ê¤¹¤ë¥Ç¡¼¥¿¤ò½èÍý¤¹¤ë¤³¤È¤Ï¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤è¤¯¤¢¤ë¤³¤È¤À¡¥ ¤è¤¯¤¢¤ë¤³¤È¤Ç¤¢¤ë¤Î¤Ç¡¤¤³¤¦¤·¤¿¥Ç¡¼¥¿¤ò¡Ö¤É¤Î¤è¤¦¤ËÊݸ¤¹¤ë¤«¡×¡ÖÊݸ¤·¤¿¥Ç¡¼¥¿¤ò ¤É¤Î¤è¤¦¤Ë¼è¤ê½Ð¤¹¤«¡×¤È¤¤¤¦»ëÅÀ¤Ç¤¤Á¤ó¤Èª¤¨¤Æ°ìÄê¤Îµ¬³Ê¤Ë¤Î¤Ã¤È¤Ã¤Æ¤³¤ì¤é¤ò¶¦Ä̲½¤¹¤ë¤³¤È¤Ç¡¤Åµ·¿Åª¤Êºî¶È¤Ë¤Ä¤¤¤Æ¤Ï¥×¥í¥°¥é¥Þ¤¬¤¤¤Á¤¤¤ÁºÙ¤«¤¤¤³¤È¤ò¹Í¤¨¤Ê¤¤¤ÇºÑ¤Þ¤»¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë¤Ê¤ë*1¡¥ ¤³¤¦¤·¤¿¹Í¤¨Êý¤¬°ìÂΤηÁ¤ò¤È¤Ã¤¿¤â¤Î¤¬°Ê²¼¤Ë½Ò¤Ù¤ë¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤Ê¤É¤ÈÁí¾Î¤µ¤ì¤ë¤â¤Î¡¤¤È»×¤¨¤ÐÎɤ¤¡¥
¥Ç¡¼¥¿¥Ù¡¼¥¹(¥½¥Õ¥È¥¦¥§¥¢)¤È¤Ï †
Â绨ÇĤ˸À¤¨¤Ð¡¤¼ý½¸¤µ¤ì¤¿¥Ç¡¼¥¿¤Î½¸¹çÂΤ½¤Î¤â¤Î¤ò»Ø¤¹. ¤Þ¤¿¤Ï¡¤¥Ç¡¼¥¿¤òÊݸ¤¹¤ë¤³¤È¡¤¤Þ¤¿¡¤°ìÄê¤Î¥ë¡¼¥ë¤Ë¤½¤Ã¤ÆÃßÀѤ·¤¿¥Ç¡¼¥¿¤ÎÃ椫¤éɬÍפʥǡ¼¥¿¤òÃê½Ð¤¹¤ë¤³¤È¡¤Åù¤Î¥Ç¡¼¥¿¼ý½¸¤«¤ÄÃê½Ð¤Îµ¡Ç½¤ò»ý¤Ã¤¿¥×¥í¥°¥é¥à¤ä¥é¥¤¥Ö¥é¥ê¤ò¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¡¤¥Ç¡¼¥¿¥Ù¡¼¥¹¥é¥¤¥Ö¥é¥ê¤Ê¤É¤È¸Æ¤Ó¡¤¤½¤Îά¾Î¤È¤·¤Æ¥Ç¡¼¥¿¥Ù¡¼¥¹¤È¸Æ¤Ö¡¥
¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤Î¶¯¤ß¤Ï¤Þ¤º¤Ï¤½¤ÎÈÆÍÑÀ¡¤¤Ä¤Þ¤ê¡¤Áàºî¤Ê¤É¤¬¶¦Ä̤Ǥ¢¤ë¤³¤È¤Ë¤¢¤ë¡¥ ¤Þ¤¿¡¤¥Ç¡¼¥¿¤ò¼è¤ê°·¤¦¤³¤È¤ËÆò½¤·¤Æ¤¤¤ë¤³¤È¤Ë¤è¤ê¡¤Áàºî¤Ë¤è¤ë¥Ç¡¼¥¿Ç˲õ¤ä¥Ç¡¼¥¿Â»¼º¤ËÈ÷¤¨¤¿µ¡¹½¤ò¤â¤¿¤»¤Æ¤¤¤¿¤ê¡¤¥á¥â¥ê¤ä¥¹¥È¥ì¡¼¥¸¤ÎÍøÍѸúΨ¤¬¹â¤¯¤Ê¤Ã¤Æ¤¤¤¿¤ê¡¤¸¡º÷¤Ê¤É¤ÎÁàºî¤¬¹â®¤Ç¤¢¤Ã¤¿¤ê¤È¡¤¤½¤Î¹âµ¡Ç½À¤âÍøÅÀ¤Ç¤¢¤ë¡¥
¤¿¤À¡¤¤³¤¦¤·¤¿¹âµ¡Ç½À¤Ï¥½¥Õ¥È¥¦¥§¥¢¤ÎÈîÂç²½¡¤ÈÑ»¨¤µ¤È¶¯¤¤Áê´Ø¤¬¤¢¤ê¡¤¥é¥¤¥È¥æ¡¼¥¶¡¼¤«¤é¤ß¤ë¤È¤«¤¨¤Ã¤Æ»È¤¤¤Ë¤¯¤¤¡¤¤ï¤«¤ê¤Ë¤¯¤¤¤È¤¤¤¦·çÅÀ¤Ë¤â·Ò¤¬¤ë¡¥
¤è¤Ã¤Æ¡¤¡Ö¤½¤Î¥Ç¡¼¥¿¹½Â¤¤Ë¤Î¤ß¡×Æò½¤·¤¿¸¤¤¥×¥í¥°¥é¥à¤ÎÊý¤¬
ÈÆÍѥǡ¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤è¤ê¤âÍ¥½¨¤Ç¤¢¤ë¤³¤È¤Ï½¼Ê¬¤Ë¤¢¤ê¤¦¤ë¡¥
ÂоݤȤ¹¤ë¥Ç¡¼¥¿¤Î¼è°·¤Ë¤½¤â¤½¤â¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤ò»È¤¦¤Ù¤¤«¤É¤¦¤«¡¤
¤Þ¤º¤ÏºÇ½é¤Ë¸¡Æ¤¤·¤¿¤Û¤¦¤¬¤¤¤¤¤À¤í¤¦¡¥
¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤Î¼ïÎà †
Èó¾ï¤ËÂ绨ÇĤËʬ¤±¤ë¤Î¤Ê¤é¤Ð¡¤´Ê°×¤Ê¤â¤Î¤«¤éÈó¾ï¤ËÂ絬ÌϤʤâ¤Î¤Þ¤Ç°Ê²¼¤Î¤è¤¦¤Ê3¤Ä¤ËʬÎà¤Ç¤¤ë¤À¤í¤¦¡¥
- ɽ·×»»¥½¥Õ¥È¡¤Ã±¤Ê¤ë¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë+Unix¥³¥Þ¥ó¥É·² Åù¡¹: Èó¾ï¤Ë¹µÁ¤Ëª¤¨¤ë¤Ê¤é¤Ð¤³¤ì¤é¤Ï¤â¤Ã¤È¤â´Ê°×¤Ê¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤È¤¤¤¨¤ë¤À¤í¤¦¡¥
- RDBMS(¥ê¥ì¡¼¥·¥ç¥Ê¥ë¥Ç¡¼¥¿¥Ù¡¼¥¹´ÉÍý¥·¥¹¥Æ¥à): ¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤Î¼çή¤È¸À¤¨¤½¤¦¤Ê¤Î¤¬¤³¤ì¤Ç¤¢¤ë¡¥¥Ç¡¼¥¿¤ÎÁàºî¤Ë¤Ï¼ç¤Ë SQL ¤È¤¤¤¦¸À¸ì¤¬»È¤ï¤ì¤ë¡¥ ¥½¥Õ¥È¥¦¥§¥¢¤È¤·¤Æ¤Ï´Ê°×¤Ê¤â¤Î¤Ï¥é¥¤¥Ö¥é¥ê¡¤¥³¥Þ¥ó¥É¤È¤·¤Æ¼ÂÁõ¤µ¤ì¡¤ËܳÊŪ¤Ê¤â¤Î¤Ï¥µ¡¼¥Ð¤È¤·¤Æ¼ÂÁõ¤µ¤ì¤ë¡¥
- ¹½Â¤·¿¥¹¥È¥ì¡¼¥¸(NoSQL): ĶÂ絬ÌϤʥǡ¼¥¿¤ä¡¤¥ê¥¢¥ë¥¿¥¤¥àÀ¤ò½ÅÍ׻뤹¤ë¤è¤¦¤Ê¡¤ RDB(¥ê¥ì¡¼¥·¥ç¥Ê¥ë¥Ç¡¼¥¿¥Ù¡¼¥¹)¤Ç¤Ï°·¤¤¤Ë¤¯¤¤¥Ç¡¼¥¿¤ò¼è¤ê°·¤¦¡¥ Áàºî¤¬ SQL ¤Ç¤Þ¤«¤Ê¤¨¤Ê¤¤¤È¤¤¤¦¤³¤È¤Ç¤â¤¢¤ë¤Î¤Ç¡¤NoSQL (Not Only SQL) ¤È¤â¸Æ¤Ð¤ì¤ë¡¥
¥Ç¡¼¥¿¤Îµ¬ÌϤȥǡ¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤Î´Ø·¸ †
¥Ç¡¼¥¿¤¬Ã±½ã¡¤¤â¤·¤¯¤Ïµ¬ÌϤ¬¾®¤µ¤¤¾ì¹ç †
Á´¥Ç¡¼¥¿¤¬¥³¥ó¥½¡¼¥ë²èÌÌ 1Ëç¤ËÆþ¤ê¤¤ë¥±¡¼¥¹¤Ê¤É¡¤¥Ç¡¼¥¿µ¬ÌϤ¬¾®¤µ¤¤¾ì¹ç¤Ï¡¤¥Ç¡¼¥¿¥Ù¡¼¥¹¤òƳÆþ¤¹¤ë¼ê´Ö¤ä¥Ç¡¼¥¿¤ò½èÍý¤¹¤ë¥½¥Õ¥ÈËÜÂΤȥǡ¼¥¿¤Î´Ö¤Ë¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤¬¶´¤Þ¤ëʬ¤À¤±¡¤¤«¤¨¤Ã¤Æ¥³¥¹¥È¹â¤Ë¤Ê¤ê¤«¤Í¤Ê¤¤¡¥ ¤½¤¦¤·¤¿¾ì¹ç¤Ï̵Íý¤Ë¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤òƳÆþ¤·¤Ê¤¯¤Æ¤âÎɤ¤¤À¤í¤¦*2¡¥ ¤³¤¦¤·¤¿¾ì¹ç¤Ïñ¤Ê¤ë¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤Ë¥Ç¡¼¥¿¤òǼ¤á¤Æ¤ª¤¯¤È¤«¡¤¤¤¤ï¤æ¤ëɽ·×»»¥½¥Õ¥È¥¦¥§¥¢¤Ê¤É¤òÍøÍѤ·¤¿Êý¤¬ÌµÍý¤¬¤Ê¤µ¤½¤¦¤À¡¥
¤Þ¤¿¡¤Î㤨¤Ðñ½ã¤Ê´Ñ¬¥Ç¡¼¥¿¤¬¿ô»ú¤Çʤó¤Ç¤¤¤ë¤À¤±¡¤¤È¤¤¤¦¤è¤¦¤Ë¥Ç¡¼¥¿¤¬Ã±½ã¤Ê¾ì¹ç¤Ï¤½¤ì¤ËÆò½¤·¤¿½èÍý·Ï¤òÍÑ°Õ¤·¤¿¤Û¤¦¤¬¸«Ä̤·¤â¤è¤¯¡¤½èÍý®Å٤䵲±ÍÆÎ̤ΰµ½ÌÀ¤Ê¤É¤ÎÌ̤Ç¿¤¯¤ÎÍøÅÀ¤¬¤¢¤ë¤À¤í¤¦¡¥ ¿ôÃͲòÀÏ¡¤¿ôÃÍ·×»»¤Ê¤É¤Î¾ì¹ç¤Ï¤³¤¦¤·¤¿¥±¡¼¥¹¤¬Â¿¤½¤¦¤À¡¥
¥Ç¡¼¥¿¤¬¤¢¤ëÄøÅÙÊ£»¨¡¤¤â¤·¤¯¤Ïµ¬ÌϤ¬¾¯¤·Â礤¤¾ì¹ç †
¸½¼ÂŪ¤ÊÁÛÄê¤È¤·¤Æ¤Ï½»½êÏ¿¤ä¥½¥Õ¥È¥¦¥§¥¢¤ÎÍÍ¡¹¤ÊÀßÄêÊݸ¤Ê¤É¤¬¤³¤Î¤¢¤¿¤ê¤À¤í¤¦¡¥ ¤³¤ì¤°¤é¤¤¤Îµ¬ÌϤ«¤é¡¤¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÍøÍѤò¸¡Æ¤¤¹¤ë²ÁÃͤ¬¤Ç¤Æ¤¯¤ë¡¥
¤¿¤À¤·¡¤Ê£»¨¤µ¤äµ¬ÌϤ¬¤½¤ì¤Û¤É¤Ç¤â¤Ê¤¤¤³¤ÎÃʳ¬¤Ç¤Ï¡¤
- SQLite ¤Ê¤É¤Î¡¤RDBMS ¤Î¤Ê¤«¤Ç¤â¥µ¡¼¥Ð¥·¥¹¥Æ¥à¤Ç¤Ï¤Ê¤¤¤è¤¦¤Ê·ÚÎ̥ǡ¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¡¥
- ñ¤Ê¤ëÀ°Íý¤·¤¿¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë + ¾®¤µ¤Ê¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤ÎÁȤ߹ç¤ï¤»
¤°¤é¤¤¤¬(¿ÍŪÅêÆþ¥³¥¹¥È¤ÎÌ̤«¤é¤â)ŬÀڤȹͤ¨¤é¤ì¤ë¡¥
¥Ç¡¼¥¿¤¬Ê£»¨¡¤¤â¤·¤¯¤ÏÂ絬ÌϤʾì¹ç †
¤â¤¦¾¯¤·¥Ç¡¼¥¿¤¬Ê£»¨¡¤¤â¤·¤¯¤ÏÂ絬ÌϤʥ±¡¼¥¹¤Ï¤³¤Á¤é¤Ë¤Ê¤ë¡¥ ¶ñÂÎŪ¤Ë¤Ï¡¤²ñ¼Ò¤Î³Æ¼ï¶È̳Íѥǡ¼¥¿¤ä¥ª¥ó¥é¥¤¥ó¥·¥ç¥Ã¥Ô¥ó¥°¥µ¥¤¥È¤Î¥Ç¡¼¥¿½èÍý¤Ê¤É ¤¬ÁÛÄêÂоݤÀ¤í¤¦¤«¡¥ ¤³¤¦¤·¤¿µ¬ÌϤǤϼç¤Ë RDBMS ¤¬»È¤ï¤ì¤Æ¤¤¤ë¡¥ ¤¿¤À¤·¡¤¶áǯ¤Ç¤Ï¥³¥ó¥Ô¥å¡¼¥¿¤ÎÀǽ¸þ¾å¤Ë¤è¤ê¡¤Ã±¤Ê¤ë¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë+¥·¥§¥ë¥¹¥¯¥ê¥×¥È ¤Ç¤³¤¦¤·¤¿ÍÑÅӤ⽼ʬ¤Þ¤«¤Ê¤¨¤ë¤È¤¹¤ëÆ°¤¤â¤¢¤ë¡¥
¥Ç¡¼¥¿¤¬Ä¶Ê£»¨¡¤¤â¤·¤¯¤ÏĶÂ絬ÌϤʾì¹ç †
¥Ç¡¼¥¿¤¬Èó¾ï¤ËÊ£»¨¤À¤Ã¤¿¤ê¤½¤Î¹½Â¤¤¬²òÀÏÁ°¤ÏÉÔÌÀ¤À¤Ã¤¿¤ê¡¤¤â¤·¤¯¤Ïµ¬ÌϤ¬ ¥µ¡¼¥Ð 1Âæ¤Ë¼ý¤Þ¤é¤Ê¤¤¤°¤é¤¤Â絬ÌϤÀ¤Ã¤¿¤ê¤¹¤ë¾ì¹ç¡¤RDB ¤ÏÉÔ¸þ¤¤Ç¤¢¤ë¡¥ ¤³¤¦¤·¤¿¾ì¹ç¤Ï¹½Â¤·¿¥¹¥È¥ì¡¼¥¸(NoSQL)¥µ¡¼¥Ð¤¬»È¤ï¤ì¤ë¡¥
SQLite †
Ëܼø¶È¤ÇÍѤ¤¤ë SQLite ¤È¤Ï¡¤RDBMS ¤Î¤Ê¤«¤Ç¤âºÇ¤â·ÚÎ̤ǹ¤¯»È¤ï¤ì¤Æ¤¤¤ë*3¥½¥Õ¥È¥¦¥§¥¢¤Ç(À¤³¦¤Ç°ìÈÖ¹¤¯»È¤ï¤ì¤Æ¤¤¤ë SQL ¥¨¥ó¥¸¥ó¤À¤È¼çÄ¥¤·¤Æ¤¤¤ë)¡¤³Æ¼ï¸À¸ìÍѥ饤¥Ö¥é¥ê¤ä¥³¥Þ¥ó¥É¤È¤·¤Æ¼ÂÁõ¤µ¤ì¤ë¡¥ ¥µ¡¼¥Ð¤Ç¤Ï¤Ê¤¤¤¿¤áÊ£»¨¤Ê¥¤¥ó¥¹¥È¡¼¥ëºî¶È¤¬ÉÔÍפǡ¤¤¹¤°»È¤¨¤ë¤È¤¤¤¦ÍøÅÀ¤¬¤¢¤ë¡¥ ¤Þ¤¿¡¤¥Ç¡¼¥¿¥Ù¡¼¥¹°ì¤Ä¤Ë¤Ä¤¥Õ¥¡¥¤¥ë¤ò°ì¤Äºî¤ëÊý¼°¤Î¤¿¤á¡¤¥Ð¥Ã¥¯¥¢¥Ã¥×¤Ê¤É¤¬¼è¤ê°×¤¤¤Î¤âÊØÍø¤ÊÅÀ¤Ç¤¢¤ë¡¥
¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÁàºî¤Ï SQL ¤Ç¹Ô¤¦¤¿¤á¡¤Â¾¤Î RDBMS ¤È¤¢¤Þ¤êÊѤï¤é¤Ê¤¤Áàºî¤¬¹Ô¤¨¤ë¡¥ ¤¿¤À¤·¡¤¥Ç¡¼¥¿¤Î¡Ö·¿¡×ÀßÄê¤òÍ׵ᤷ¤Ê¤¤¤È¤¤¤¦Í»Ä̤µ¤ò»ý¤Ä¤Î¤Ç¡¤´Êñ¤Ë»È¤¨¤ë¡¥
¼ç¤Ë»È¤ï¤ì¤ë¥Ð¡¼¥¸¥ç¥ó¤Ï 2·ÏÅý¤È 3·ÏÅý¤Ç¤¢¤ë¤¬¡¤¤³¤³¤Ç¤Ï 3·ÏÅý(ver.3)¤òÍѤ¤¤ë¡¥
ºåÂç¤Î¶µ°é·×»»µ¡¥·¥¹¥Æ¥à¾å¤Ç¤Ï¡¢cygwin, linux(vmware) ¤ÎξÊý¤Ë sqlite3 ¥³¥Þ¥ó¥É¤¬¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤é¤¤¤Ä¤Ç¤â sqlite3 ¤ò»È¤¦¤³¤È¤¬½ÐÍè¤ë¡¥
»ñÎÁ †
-
SQLite:
SQLite ¤ÎËÜ²È web ¤Ç¤¢¤ë¡¥ SQLite ¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤¤ë¤¬¡¤cygwin ¤ä Linux ¤Ç¤Ï¥·¥¹¥Æ¥à¤¬¤â¤Ä¥¢¥×¥ê¥±¡¼¥·¥ç¥ó´ÉÍý¥·¥¹¥Æ¥à¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¤Û¤¦¤¬¤¤¤¤¤À¤í¤¦¡¥ - SQLite ÆþÌç Âè2ÈÇ: Ãø À¾Âô ľÌÚ, æƱ˼Ò(2009).
¾å¤ÎËÜ²È web ¤Ç¤â¾Ò²ð¤µ¤ì¤Æ¤¤¤ë½ñÀҤǤ¢¤ë¡¥ÂêÌܤÎÄ̤ꡤÆþÌç¤Ë¤Ï¤Þ¤µ¤Ë¤Ô¤Ã¤¿¤ê¤ÎËܤȻפï¤ì¤ë¡¥ ¤¿¤À¤·¡¤ÆþÌç¼Ô¤Ë¤ÏÆñ²ò¤«¤È»×¤ï¤ì¤ëÆâÍƤϺܤäƤ¤¤Ê¤¤(¤È¤¯¤Ë¥ê¥ì¡¼¥·¥ç¥Ê¥ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤È¤·¤Æ¤Î°·¤¤Êý¤Ë¤Ä¤¤¤Æ)¤Î¤Ç¡¤Ãæµé¼Ô°Ê¾å¤Ï¾¤Î½ñÀҤʤɤâ»ñÎÁ¤È¤·¤ÆÍÑ°Õ¤·¤Æ¤ª¤¯¤ÈÎɤ¤¤À¤í¤¦¡¥ - ¡ÉSQLite ÆþÌç¡É ¤È¤¤¤¦¥¡¼¥ï¡¼¥É¤Ç¸¡º÷¤·¤Æ½Ð¤Æ¤¯¤ë¤è¤¦¤Ê web.
ÃúÇ«¤Ë½ñ¤«¤ì¤¿Ê¬¤«¤ê¤ä¤¹¤¤¤â¤Î¤â¤¢¤ê¡¤ÂçÊѰ٤ˤʤë¤Î¤Ç¸«¤Æ¤ª¤¯¤ÈÎɤ¤¤À¤í¤¦¡¥
SQLite ¤ÎÁàºî †
¾¤ÎÃø̾¤Ê RDBMS ¤Ï¥½¥Õ¥È¥¦¥§¥¢¤È¤·¤Æ¤Ï¥µ¡¼¥Ð·Á¼°¤ò¤È¤ë¤³¤È¤¬Â¿¤¤.
¤³¤ì¤Ï¡¢¥Í¥Ã¥È¥ï¡¼¥¯±Û¤·¤Ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò°·¤¦¤¿¤á¤Ë¤Ï¤³¤ÎÊý¤¬¹¥ÅÔ¹ç¤À¤«¤é¤Ç¡¢
¤¢¤ëÄøÅÙÂ礤ʵ¬ÌϤΥǡ¼¥¿¥Ù¡¼¥¹¤Ç¤Ï(ÍøÍѼԤ¬Ê£¿ô¤Ë¤Ê¤ë¤³¤È¤â¤¢¤ê)ɬÍפʷÁ¼°¤È¤¤¤¨¤ë¡£
¤·¤«¤·¡¢¥µ¡¼¥Ð¤ò¥¤¥ó¥¹¥È¡¼¥ë¡¢²ÔƯ¤µ¤»¤ë¤¿¤á¤Ë¤Ï¥·¥¹¥Æ¥à¤Î´ÉÍý¼Ô¸¢¸Â¤¬É¬ÍפÀ¤Ã¤¿¤ê¡¢Æüì¤Ê¥¢¥«¥¦¥ó¥È¤òÍÑ°Õ¤·¤¿¤ê¤»¤Í¤Ð¤Ê¤é¤º¡¢ÍøÍѤ¹¤ë¤¿¤á¤ÎÏ«ÎϤϾ®¤µ¤¯¤Ê¤¤.
¤³¤ì¤ËÂФ·¡¢SQLite ¤Ï¥µ¡¼¥Ð·Á¼°¤Ç¤Ï¤Ê¤¯¡¢Ã±¤Ê¤ë¥³¥Þ¥ó¥É¡¢¤â¤·¤¯¤Ï¥é¥¤¥Ö¥é¥ê¤«¤é¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÁàºî¤¹¤ë¤È¤¤¤¦Ã±½ã¤Ê»ÅÁȤߤǤ¢¤ë.
Ëܼø¶È¤Ç¤Ï¡¢¤â¤Ã¤È¤â´Êñ¤Ê¥³¥Þ¥ó¥É¤«¤é¤ÎÁàºî¤ò»ý¤Ã¤Æ³Ø¤Ö¤â¤Î¤È¤¹¤ë.
SQLite ¤ÇÍѤ¤¤ë¸À¸ì †
SQLite ¤ò»È¤Ã¤Æ¤ÎÁàºî¤Ë¤Ï¡¢°Ê²¼¤ÎÆó¼ïÎब¤¢¤ê¡¢¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤Æ°Û¤Ê¤ë¸À¸ì(¥³¥Þ¥ó¥É)¤òÍѤ¤¤ë¡¥
- SQLite ¤½¤Î¤â¤Î¤ÎÁàºî: ³Æ¼ïÀßÄê¤ÎÊѹ¹¡¢É½¼¨¤Ê¤É¡¥
SQLite ¥³¥Þ¥ó¥É ¤È¸Æ¤Ð¤ì¤ë¥³¥Þ¥ó¥É¤òÍѤ¤¤ë¡¥
SQLite ¥³¥Þ¥ó¥É¤Ï .(¥Ô¥ê¥ª¥É)¤Ç»Ï¤Þ¤ëñ¸ì¤Ç¤¢¤ë¤³¤È¤¬ÆÃħ¤Ç¤¢¤ë¡¥
- ¥Ç¡¼¥¿¥Ù¡¼¥¹½èÍý: ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ø¤ÎÁàºî¡¥¥Æ¡¼¥Ö¥ë¤ÎºîÀ®¡¢¥Ç¡¼¥¿¤ÎÅÐÏ¿¡¢¥Ç¡¼¥¿¤ÎÃê½Ð¤Ê¤É¡¢ËÜÍè¤Î¤ä¤ê¤¿¤¤¤³¤È¡¥ ¤³¤ì¤Ë¤Ï SQL ¥³¥Þ¥ó¥É ¤òÍѤ¤¤ë¡¥ SQL ¥³¥Þ¥ó¥É¤Ï¤¢¤ë¤Æ¤¤¤Éµ¬³Ê²½¤µ¤ì¤Æ¤ª¤ê*4¡¢É¸½àŪ¤Êµ¡Ç½¤ò»È¤¦¤Î¤Ç¤¢¤ì¤Ð¾¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¥½¥Õ¥È¥¦¥§¥¢¤ÈƱÍͤ˰·¤¨¤ë¡¥
SQLite ¤Ë¤ª¤±¤ë¥Ç¡¼¥¿¤Î¼è°·¤¤ †
Ä̾ï¤Ï¡¢RDBMS ¤Ç¤Ï°ì¤Ä¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÃæ¤Ë¡¤¥Æ¡¼¥Ö¥ë(ɽ)¤òÊ£¿ôºî¤ê¡¤
¤½¤Î¥Æ¡¼¥Ö¥ë¤ÎÃæ¤Ë°ì¹Ô¤º¤Ä·è¤Þ¤Ã¤¿·Á¼°¤Ç¥Ç¡¼¥¿¤òÆþ¤ì¤ë(¤µ¤é¤Ë¡¢¤³¤¦¤·¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÊ£¿ôºî¤ë)¡¥
¥Æ¡¼¥Ö¥ë¤ÏÃíÌܤ¹¤ë¥Ç¡¼¥¿¤ÎʬÎऴ¤È(Î㤨¤Ð¸ÜµÒ¥ê¥¹¥È¤òʤ٤ƺî¤ë¸ÜµÒ¥Æ¡¼¥Ö¥ë¡¤¾¦Éʥꥹ¥È¤òʤ٤뾦Éʥơ¼¥Ö¥ë¡¤¤½¤·¤Æ郎²¿¤òÇã¤Ã¤¿¤«¤È¤¤¤¦¹ØÇã¥ê¥¹¥È¤òʤ٤¿¹ØÇã¥Æ¡¼¥Ö¥ë¤Ê¤É)¤Ëºî¤ë¤³¤È¤¬ÁÛÄꤵ¤ì¤Æ¤ª¤ê¡¤¤½¤ì¤é¤ò´Ø·¸ÉÕ¤±¤ë*5¤³¤È¤ÇÁ´ÂΤξðÊ󤬤ޤȤޤ뤳¤È¤Ë¤Ê¤ë¡¥ ¤³¤Î¤è¤¦¤Ë¡¤¥ê¥¹¥È¥¢¥Ã¥×¤Ç¤¤ë¾ðÊó¤ò¥Æ¡¼¥Ö¥ë¤È¤·¤Æʤ١¤¤½¤ì¤é¤Î´Ø·¸¤ò¤Þ¤¿¥Æ¡¼¥Ö¥ë¤Ë¤¹¤ë¡¤¤È¤¤¤¦¤è¤¦¤Ë¡Î´Ø·¸À¡Ï¤ÇÁ´ÂΤξðÊó¤òɽ¤¹¤Î¤¬Â绨ÇĤ˸À¤¨¤Ð¥ê¥ì¡¼¥·¥ç¥Ê¥ëDB ¤Ç¤¢¤ë¡¥
¤Ê¤ª¡¢SQLite ¤Ç¤Ï°ì¤Ä¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò°ì¤Ä¤Î¥Õ¥¡¥¤¥ë¤ËÆþ¤ì¤ë¤Î¤Çʬ¤«¤ê°×¤¤¤·¡¢¥Ð¥Ã¥¯¥¢¥Ã¥×¤â¼è¤ê¤ä¤¹¤¤¡¥
¤³¤Î¼ø¶È¤Ç¤Ï¡¢Çä¾å¤ò´ÉÍý¤¹¤ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÁÛÄꤷ¤Æ¤ß¤ë¡¥
¶ñÂÎŪ¤Ë¤Ï¡¢°ì¤Ä¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÃæ¤Ë ¾¦ÉʾðÊó¤Î¥Æ¡¼¥Ö¥ë¡¢¸ÜµÒ¾ðÊó¤Î¥Æ¡¼¥Ö¥ë¡¢Çä¾åµÏ¿¤Î¥Æ¡¼¥Ö¥ë¤òºî¤Ã¤Æ¤ß¤ë¡¥
¤½¤Î¤Ä¤â¤ê¤Ç°Ê²¼¤òÆɤ߿ʤá¤Æ¤ß¤è¤¦¡¥
SQLite3 ¤Îµ¯Æ°¡¢½ªÎ» †
¥³¥Þ¥ó¥É¤«¤é SQLite ¤òµ¯Æ°¤¹¤ë = ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ø¤ÎÀܳ or ¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎºîÀ® †
SQLite ¤Î¥³¥Þ¥ó¥É¤Ï¡¢°ú¿ô¤Ëʸ»úÎó¤òÍ¿¤¨¤ë¤È¤½¤Î̾Á°¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹(¥Õ¥¡¥¤¥ë)¤ËÀܳ¤·¤è¤¦¤È¤¹¤ë¡£ ¤â¤·¤½¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬¤Ê¤±¤ì¤Ð¿·µ¬¤Ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬ºî¤é¤ì¤ë¡£ ¤¿¤È¤¨¤Ð db1 ¤È¤¤¤¦Ì¾Á°¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤òºî¤ë¤È¤¹¤ë¤È¡¢
sqlite3␣db1
¤ÈÆþÎϤ¹¤ì¤Ð¤è¤¤. sqlite (ver.3) ¤¬µ¯Æ°¤·¤Æ¥³¥Þ¥ó¥É¼õÉե⡼¥É¤Ë¤Ê¤ë(¥×¥í¥ó¥×¥È¤¬ sqlite> ¤ËÊѤï¤ë¤Î¤Çµ¤¤Å¤¯¤À¤í¤¦).
(¼Â½¬) ¾å¤Î¤è¤¦¤Ë¤·¤Æ SQLite ¤òµ¯Æ°¤·¤è¤¦¡¥ µ¯Æ°¤·¤¿¤é¤½¤Î¤Þ¤Þ¤Ë¤·¤Æ¡¢¼¡¤Î¼Â½¬¤Þ¤ÇÀè¤ØÆɤ߿ʤá¤è¤¦¡¥
SQLite ¤Î½ªÎ» †
µ¯Æ°¤·¤¿¡¡SQLite ¤ò½ªÎ»¤¹¤ë¤Ë¤Ï¡¢
.exit
¤â¤·¤¯¤Ï
.quit
¤Ç¤è¤¤¡£ ¤½¤ì¤¾¤ì°ìʸ»úÌܤ¬¥Ô¥ê¥ª¥É¤Ç¤¢¤ë¤³¤È¤ËÃí°Õ¤·¤è¤¦¡£
SQLite3 ¤ÎÀßÄê †
SQLite ¤òµ¯Æ°¤·¤Æ¤«¤é¡¢¤Þ¤º¤Ï
.show
¤È¤·¤Æ¤ß¤è¤¦¡¥ ¸½ºß¤ÎÀßÄê¾õ¶·¤¬°Ê²¼¤Î¤è¤¦¤Ëɽ¼¨¤µ¤ì¤ë(¤â¤Á¤í¤ó¡¢ÆâÍƤÏÀßÄê¤Ë¤è¤ê°Û¤Ê¤ë)¡¥
echo: off eqp: off explain: off headers: off mode: list nullvalue: "" output: stdout separator: "|" stats: off width:
¸«¤Æ¿ä¬¤Ç¤¤ë¤è¤¦¤Ë¡¢¤¤¤í¤¤¤íÀßÄê¤Ï¤¢¤ë¤¬¡¢¤Þ¤º¤Ï°Ê²¼¤ÎÀßÄê¤À¤±¤Ç¤â¤·¤Æ¤ª¤¯¤È²¿¤«¤È¤ï¤«¤ê°×¤¯¤Ê¤ë¤Î¤Ç, ¼ê¤Ç¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤È¤¤Ï¤³¤¦¤·¤Æ¤ª¤³¤¦¡¥
.explain␣on
¤³¤ì¤Ï¡¢²èÌ̽ÐÎϤò¤ï¤«¤ê¤ä¤¹¤¯¤¹¤ëÀßÄê¤Ç¤¢¤ê¡¢ÂÐÏÃŪ¤ËÁàºî¤·¤Æ¤¤¤ë¤È¤¤Ï¤Ê¤Ë¤«¤È½õ¤«¤ë¤À¤í¤¦¡¥
(¼Â½¬) .show ¥³¥Þ¥ó¥É¤ò»î¤·¤Ë¼Â¹Ô¤·¤¿¤Î¤Á¡¢.explain␣on ÀßÄê¤ò¤·¤Æ¤ª¤³¤¦¡¥
SQLite3 ¤Ç¤Î¥Æ¡¼¥Ö¥ë¡ÖñÆÈ¡×Áàºî †
¥Æ¡¼¥Ö¥ë¤òºî¤ë †
¥ê¥ì¡¼¥·¥ç¥Ê¥ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÃæ¿È¤ÎËܼÁ¤Ï¥Ç¡¼¥¿¤òÎóµó¤·¤¿²ô¤Ç¤¢¤ë¥Æ¡¼¥Ö¥ë¤Ç¤¢¤ë¡£ ¤¿¤À¤·¡¢°ì¤Ä¤Î¥Æ¡¼¥Ö¥ë¤ÎÃæ¤ËÎóµó¤µ¤ì¤ë¥Ç¡¼¥¿¤Ï¤¹¤Ù¤ÆƱ¤¸¹½Â¤¤ò¤·¤Æ¤¤¤ë¤â¤Î¤È¤¹¤ëɬÍפ¬¤¢¤ë¡£ ¤½¤Î¹½Â¤¤Ï¡¢¥Æ¡¼¥Ö¥ëºîÀ®»þ¤ËÄêµÁ¤·¤Æ¤ä¤ëɬÍפ¬¤¢¤ë¡£
SQLite ¤Ç¤Î¥Æ¡¼¥Ö¥ë¤ÎºîÀ®»þ¤Ë¤ª¤±¤ë¥Ç¡¼¥¿¤ÎÄêµÁ¤Ï´Êñ¤À¡¥ ¤·¤«¤â¥Ç¡¼¥¿¤Î·¿¤ÎÄêµÁ¤ò¾Êά¤¹¤ë¤³¤È¤â¤Ç¤¤ë¤Î¤Ç¡¢¼ÂÍÑŪ¤Ê¤ä¤êÊý¤È¤·¤Æ¤Ï(´·¤ì¤Æ¤¤¤Ê¤¤¤¦¤Á¤Ï)¼¡¤Î¤è¤¦¤Ë¤·¤Æ¤ª¤¯¤ÈÎɤ¤¤À¤í¤¦¡¥
CREATE␣TABLE␣¥Æ¡¼¥Ö¥ë̾␣(id␣INTEGER␣PRIMARY␣KEY␣AUTOINCREMENT, ÊÑ¿ô̾2, ÊÑ¿ô̾3, ...);
SQLite3 ¤Ï ; (¥»¥ß¥³¥í¥ó)¤òÆþÎϤ¹¤ë¤Þ¤Ç¤ÏÌ¿Îá¤Î²ò¼á¤òÂԤĤΤǡ¢Ä¹¤¤¥³¥Þ¥ó¥É¤ò
Á´Éô 1 ¹Ô¤ÇÆþÎϤ¹¤ëɬÍפϤʤ¤¡¥¿Í´Ö¤Ë¤È¤Ã¤Æʬ¤«¤ê°×¤¤¤È¤³¤í¤Ç²þ¹Ô¤·¤ÆÆþÎϤò³¤±¤ë¤Î¤ÏÎɤ¤¼ê¤Ç¤¢¤ë¡¥
´·½¬¤È¤·¤Æ SQL Ì¿Îá¤ÏÂçʸ»ú¤Çɽµ¤µ¤ì¤ë¤¬¡¢SQLite3 ¤Ï¾®Ê¸»ú¤Ç¤âÌäÂê¤Ê¤¯¼õ¤±ÉÕ¤±¤ë¡¥
ÂÐÏÃŪ¤ËÆþÎϤ¹¤ë¤È¤¤ÏÌÌÅݤÀ¤í¤¦¤«¤é¡¢µ¤¤Ë¤»¤º¤Ë¾®Ê¸»ú¤Î¤Þ¤Þ¤ÇÆþÎϤ·¤Æ¤·¤Þ¤¦¤Î¤¬´Êñ¤À¤í¤¦¡¥
¤³¤³¤Ç¤Ï ÊÑ¿ô̾1 ¤ò id ¤È·è¤á¤Æ¤·¤Þ¤Ã¤Æ¤¤¤ë¤¬¡¢¼Â¤Ï¼«Í³¤Ë·è¤á¤ÆÎɤ¤¡¥
¤¿¤À¤·¡¢´·¤ì¤Æ¤¤¤Ê¤¤¤¦¤Á¤Ï¤³¤¦¤·¤Æ¤ª¤¯¤È¤Ê¤Ë¤«¤È¸å¤Ç½õ¤«¤ë¤À¤í¤¦¡¥
id ¤Î¸å¤Î INTEGER PRIMARY KEY AUTOINCREMENT ¤Î°ÕÌ£¤Ï¡¢
id ¤È¤¤¤¦ÊÑ¿ô¤ò¡ÖÀ°¿ô¡×¤Ç¡Ö¤³¤ì¤ò¼ç¥¡¼¤È¤·¤Æ¡×¡Ö¥Ç¡¼¥¿ºï½ü¸å¤ÎºÆÍøÍѤʤ·¡×¤Ë¤¹¤ë¤È¤¤¤¦°ÕÌ£¤Ç¤¢¤ë¡¥
¼ç¥¡¼¤È¤¤¤¦¤Î¤Ï¡¢Â绨ÇĤ˸À¤¨¤Ð¡¢¤½¤Îɽ¤ÎÃæ¤Ç¤³¤ÎÊÑ¿ô¤ËÂФ¹¤ë¥Ç¡¼¥¿¤ÏÍ£°ì¤Ç¤¢¤ë¤³¤È¤¬Êݾڤµ¤ì¤ëÊÑ¿ô¤Ç¤¢¤ë¡¢¤È¤¤¤¦°ÕÌ£¤Ç¤¢¤ë¡¥
(¼Â½¬) ¼¡¤Î¤è¤¦¤Ë¤·¤Æ¡¢¤Þ¤º¤Ï¾¦ÉʾðÊó¤Î¥Æ¡¼¥Ö¥ë¤È¤·¤Æ fruits ¥Æ¡¼¥Ö¥ë¤òºî¤Ã¤Æ¤ª¤³¤¦¡¥
CREATE␣TABLE␣fruits␣(id␣INTEGER␣PRIMARY␣KEY␣AUTOINCREMENT, name, price);
¾å¤ÎÃí°Õ¤Ç½ñ¤¤¤¿¤è¤¦¤Ë¡¢°ì¹Ô¤Ç°ìµ¤¤ËÆþÎϤ¹¤ëɬÍפϤʤ¤¡¥ºÇ¸å¤Î ; (¥»¥ß¥³¥í¥ó) ¤òÂǤĤޤǤÏÌ¿Îá¤Ï¼Â¹Ô¤µ¤ì¤Ê¤¤¡¥
¥Æ¡¼¥Ö¥ë¤òºï½ü¤¹¤ë †
ºî¤Ã¤¿¥Æ¡¼¥Ö¥ë¤òºï½ü¤¹¤ë¤Î¤Ï´Êñ¤Ç¡¢
DROP␣TABLE␣¥Æ¡¼¥Ö¥ë̾;
¤À¤±¤ÇÎɤ¤¡¥
¤³¤Î´Êñ¤ÊÁàºî¤Ç¤¢¤Ã¤µ¤êÂçÎ̤Υǡ¼¥¿¤ò¼º¤¦¤³¤È¤¬¤¢¤ë¤Î¤Ç¡¢Í×Ãí°Õ¡ª¡ª
¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤É¤ó¤Ê¥Æ¡¼¥Ö¥ë¤¬Í¤ë¤«¸«¤Æ¤ß¤ë †
°ì¤Ä¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤ÏÊ£¿ô¤Î¥Æ¡¼¥Ö¥ë¤ò³ÊǼ¤Ç¤¤ë¡¥ ¤½¤³¤Ç¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹Ãæ¤Ë¤É¤ó¤Ê¥Æ¡¼¥Ö¥ë¤¬¤¢¤ë¤«Ä´¤Ù¤ëÊýË¡¤ò½ñ¤¤¤Æ¤ª¤³¤¦¡¥ ¤³¤ì¤Ï .tables Ì¿Îá(SQLite Ì¿Îá)¤ò»È¤Ã¤Æ
.tables
¤È¤¹¤ë¤À¤±¤Ç¤è¤¤¡¥
(¼Â½¬) ¾å¤Î .tables ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢³Î¤«¤Ë fruits ¥Æ¡¼¥Ö¥ë¤¬ºî¤é¤ì¤Æ¤¤¤ë¤³¤È¤ò³Îǧ¤·¤è¤¦¡¥
¥Æ¡¼¥Ö¥ë¤Ë¥Ç¡¼¥¿¤òÄɲä¹¤ë †
¤µ¤Æ¡¢¥Æ¡¼¥Ö¥ë¤¬´û¤Ë¸ºß¤¹¤ë¤Ê¤é¤Ð¤½¤³¤Ë¥Ç¡¼¥¿¤òÄɲäǤ¤ë¡¥ ¥Ç¡¼¥¿¤ÎÄÉ²Ã¤Ï INSERT Ì¿Îá¤ò»È¤Ã¤Æ°Ê²¼¤Î¤è¤¦¤Ë¹Ô¤¦¡¥
INSERT␣INTO␣¥Æ¡¼¥Ö¥ë̾␣VALUES(NULL, ÊÑ¿ô2¤ÎÆâÍÆ, ÊÑ¿ô3¤ÎÆâÍÆ, ...);
¤³¤¦¤¹¤ë¤È¡¢ÊÑ¿ô id ¤ÏÏ¢È֤Ǽ«Æ°Åª¤Ë¿ô»ú¤¬ÆþÎϤµ¤ì¤ë.
(¼Â½¬) ¼¡¤Î¤è¤¦¤Ë¤·¤Æ¡¢ fruits ¥Æ¡¼¥Ö¥ë¤Ë¾¦Éʥǡ¼¥¿¤òÅÐÏ¿¤·¤è¤¦¡¥
INSERT␣INTO␣fruits␣VALUES(NULL, "banana", 100);
INSERT␣INTO␣fruits␣VALUES(NULL, "strawberry", 200);
INSERT␣INTO␣fruits␣VALUES(NULL, "apple", 150);
INSERT␣INTO␣fruits␣VALUES(NULL, "water melon", 1500);
¤â¤Á¤í¤ó¡¢Â¾¤Î¥Æ¡¼¥Ö¥ë¤ä¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¥Ç¡¼¥¿¤ò¥³¥Ô¡¼¤·¤Æ¤¯¤ëÊýË¡¤ä¡¢Â¾¤ÎÉáÄ̤Υե¡¥¤¥ë¤«¤é¥Ç¡¼¥¿¤ò¥³¥Ô¡¼¤·¤Æ¤¯¤ëÊýË¡¤Ê¤É¤âͤ롥
ɬÍפˤʤ俤éÄ´¤Ù¤è¤¦¡¥
¥Æ¡¼¥Ö¥ë¤Î¥Ç¡¼¥¿¤òɽ¼¨¤¹¤ë, ¼è¤ê½Ð¤¹ †
¥Æ¡¼¥Ö¥ë¤ËÆþ¤Ã¤Æ¤¤¤ë¥Ç¡¼¥¿¤ò¤Þ¤º¤Ï¸«¤Æ¤ß¤¿¤¤¤È¤¤¤¦¾ì¹ç¤Ï SELECT Ì¿Îá¤ò»È¤Ã¤Æ°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë¡¥
SELECT␣*␣FROM␣¥Æ¡¼¥Ö¥ë̾;
¾å¤ÎÀßÄê¤Ç .explain on ¤È¤·¤Æ¤¤¤ë¤È¤³¤Îɽ¼¨¤¬¾¯¤·¤À¤±Ê¬¤«¤ê°×¤¤¤è¤¦¤Ë¤Ê¤ë¡¥
(¼Â½¬) ¾å¤Î SELECT ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢fruits ¥Æ¡¼¥Ö¥ë¤Ë¥Ç¡¼¥¿¤¬ÅÐÏ¿¤µ¤ì¤Æ
¤¤¤ë¤³¤È¤ò³Îǧ¤·¤è¤¦¡¥
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
id name pric ---- ------------- ---- 1 banana 100 2 strawberry 200 3 apple 150 4 water melon 1500
¤µ¤é¤Ë¡¢¾ò·ï¤ò»ØÄꤷ¤Æ¥Ç¡¼¥¿¤ò¸«¤Æ¤ß¤¿¤¤¤È¤¤¤¦¾ì¹ç¤Ï¡¢
SELECT Ì¿Îá¤Ë WHERE ¶ç¤òÄɲ䷤ưʲ¼¤Î¤è¤¦¤Ë¤¹¤ë¡¥
SELECT␣*␣FROM␣¥Æ¡¼¥Ö¥ë̾␣WHERE␣¾ò·ï;
WHERE ¤Î¤¢¤È¤Ë³¤¯¡Ö¾ò·ï¡×¤Ï¤¤¤í¤¤¤í¤È½ÀÆð¤Ë»ØÄê¤Ç¤¤ë¡¥ ¤³¤³¤ÇÀâÌÀ¤¹¤ë¤Ë¤Ï¿¤¹¤®¤ë¤Î¤Ç¡¢°Ê²¼¤ÎÆóÎã¤ò¤ß¤Æ¤Þ¤º¤Ï´¶³Ð¤ò¤Ä¤«¤â¤¦¡¥
(¼Â½¬) ¼¡¤Î SELECT ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢fruits ¥Æ¡¼¥Ö¥ëÃæ¤Çñ²Á¤¬ 1000±ß°Ê¾å¤ÎÉʤò¥ê¥¹¥È¥¢¥Ã¥×¤·¤Æ¤ß¤è¤¦¡¥
SELECT␣*␣FROM␣fruits␣WHERE␣price>1000;
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
id name pric ---- ------------- ---- 4 water melon 1500
¤µ¤é¤Ëº£Å٤ϡ¢fruits ¥Æ¡¼¥Ö¥ëÃæ¤Ç̾Á°¤¬ "¤Û¤Ë¤ã¤é¤énana" ¤È¤¤¤¦¤â¤Î¤ò¥ê¥¹¥È¥¢¥Ã¥×¤·¤Æ¤ß¤è¤¦¡¥
SELECT␣*␣FROM␣fruits␣WHERE␣LIKE('%nana',name);
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
id name pric ---- ------------- ---- 1 banana 100
LIKE Ãæ¤Î % ¤Ï¡ÖǤ°Õ¤Îʸ»úÎó¡×¤È¤¤¤¦°ÕÌ£¤ò»ý¤Ä¡¥¾Ü¤·¤¯¤ÏÄ´¤Ù¤è¤¦¡¥
¤µ¤é¤Ë¡¢¹àÌܤ¹¤Ù¤Æ¤Ç¤Ï¤Ê¤¯¡¢°ìÉô¤Î¹àÌܤÀ¤±¸«¤¿¤¤¤È¤¤¤¦¾ì¹ç¤Ï SELECT Ì¿Îá¤Î¤¢¤È¤Ë * ¤Ç¤Ï¤Ê¤¯¡¢¹àÌÜ̾¤òÎóµó¤¹¤ë¡¥
SELECT␣¸«¤¿¤¤¹àÌÜ̾1, ¸«¤¿¤¤¹àÌÜ̾2, ... ␣FROM␣¥Æ¡¼¥Ö¥ë̾␣WHERE␣¾ò·ï;
(¼Â½¬) ¼¡¤Î SELECT ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢fruits ¥Æ¡¼¥Ö¥ëÃæ¤Îñ²Á¡Ö¤Î¤ß¡×¥ê¥¹¥È¥¢¥Ã¥×¤·¤Æ¤ß¤è¤¦¡¥
SELECT␣price␣FROM␣fruits;
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
pric ---- 100 200 150 1500
¥Æ¡¼¥Ö¥ë¤Î¥Ç¡¼¥¿¤ò½¤Àµ¤¹¤ë †
¥Æ¡¼¥Ö¥ë¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë¥Ç¡¼¥¿¤ò½¤Àµ¤¹¤ë¤Ë¤Ï¡¢REPLACE Ì¿Îá¤È UPDATE Ì¿Î᤬»È¤¨¤ë¡¥ ÅÔ¹ç¤Ë¹ç¤ï¤»¤Æ¹¥¤¤ÊÊý¤ò»È¤ª¤¦¡¥
¤Þ¤º REPLACE ¤Ï¡¢¼¡¤Î¤è¤¦¤Ë»È¤¦¡¥
REPLACE␣INTO␣¥Æ¡¼¥Ö¥ë̾␣VALUES(idÈÖ¹æ, ÊÑ¿ô2¤ÎÆâÍÆ, ÊÑ¿ô3¤ÎÆâÍÆ, ...);
REPLACE Ì¿Îá¤ò»È¤Ã¤¿»þ¡¢¤½¤Î idÈÖ¹æ ¤ò¤â¤Ä¥Ç¡¼¥¿¤¬¤Ê¤¤¾ì¹ç¡¢¤½¤Î¥Ç¡¼¥¿¤Ï¤½¤Î idÈÖ¹æ¤Ç¿·µ¬¤Ë¡ÖÅÐÏ¿¡×¤µ¤ì¤ë¡¥ ¤½¤Î°Õ¿Þ¤¬¤Ê¤¤¾ì¹ç¤Ï´Ö°ã¤¤¤Î¤â¤È¤Ë¤Ê¤ë¤Î¤Çα°Õ¤·¤è¤¦¡¥
¼¡¤Ë¡¢UPDATE ¤Î»È¤¤Êý¤À¤¬¡¢¼¡¤Î¤è¤¦¤Ë¤¹¤ë¡¥
UPDATE␣¥Æ¡¼¥Ö¥ë̾␣SET␣ÊÑ¿ô̾n=ÊÑ¿ôn¤ÎÆâÍÆ␣WHERE␣¾ò·ï;
WHERE °Ê¹ß¤ò¾Êά¤¹¤ë¤È¡¢¥Ç¡¼¥¿Á´Éô¤¬ÂоݤȤʤ롥
(¼Â½¬) ¼¡¤Î¤è¤¦¤Ë UPDATE ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢fruits ¥Æ¡¼¥Ö¥ë¤Î¥Ç¡¼¥¿¤ÎÃæ¤Î¡¢water melon ¤Î²Á³Ê¤ò 2000 ¤Ë½¤Àµ¤·¤è¤¦¡¥
UPDATE␣fruits␣SET␣price=2000␣WHERE␣id=4;
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢SELECT ¥³¥Þ¥ó¥É¤Ç¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
id name pric ---- ------------- ---- 1 banana 100 2 strawberry 200 3 apple 150 4 water melon 2000
(¼Â½¬:±þÍÑ) ¤µ¤é¤Ë¼¡¤Î¤è¤¦¤Ë UPDATE ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢
ñ²Á¤¬ 300±ß̤Ëþ¤Î¾¦ÉʤòÇܤËÃ;夲¤·¤è¤¦¡¥
UPDATE␣fruits␣SET␣price=2*price␣WHERE␣price<300;
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢SELECT ¥³¥Þ¥ó¥É¤Ç¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
id name pric ---- ------------- ---- 1 banana 200 2 strawberry 400 3 apple 300 4 water melon 2000
¥Æ¡¼¥Ö¥ë¤Î¥Ç¡¼¥¿¤òºï½ü¤¹¤ë †
¥Æ¡¼¥Ö¥ëÃæ¤Î¥Ç¡¼¥¿¤òºï½ü¤¹¤ë¤Ë¤Ï¡¢UPDATE ¥³¥Þ¥ó¥É¤Ë»÷¤¿ DELETE ¥³¥Þ¥ó¥É¤¬»È¤¨¤ë¡¥
DELETE␣FROM␣¥Æ¡¼¥Ö¥ë̾␣WHERE␣¾ò·ï;
¤³¤ì¤â WHERE °Ê¹ß¤ò¾Êά¤¹¤ë¤È¡¢¥Ç¡¼¥¿Á´Éô¤¬ÂоݤȤʤ롥 ¤Ä¤Þ¤ê¡¢¥Ç¡¼¥¿¤¬Á´Éô¾Ã¤¨¤Æ¤·¤Þ¤¦! ¤Î¤Ç¡¢´Ö°ã¤¨¤Æ¤½¤¦Áàºî¤·¤Ê¤¤¤è¤¦µ¤¤ò¤Ä¤±¤è¤¦¡¥
(¼Â½¬) ¼¡¤Î¤è¤¦¤Ë DELETE ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢fruits ¥Æ¡¼¥Ö¥ë¤Î¥Ç¡¼¥¿¤ÎÃæ¤Î¡¢
strawberry ¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤òºï½ü¤·¤è¤¦¡¥
DELETE␣FROM␣fruits␣WHERE␣id=2;
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢SELECT ¥³¥Þ¥ó¥É¤Ç¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
id name pric ---- ------------- ---- 1 banana 200 3 apple 300 4 water melon 2000
°ìÅٻȤï¤ì¤¿ id ÈÖ¹æ 2 ¤¬·çÈ֤ˤʤäƤ¤¤ë¤³¤È¤ËÃí°Õ¤·¤è¤¦¡¥
(¼Â½¬) ¼¡¤Î¤è¤¦¤Ë INSERT ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¥Ç¡¼¥¿¤òÄɲä·¡¢
·çÈÖ id ¤¬¤É¤Î¤è¤¦¤Ë°·¤ï¤ì¤ë¤«ÇÄ°®¤·¤è¤¦¡¥
INSERT␣INTO␣fruits␣VALUES(NULL, "orange", 400);
¤¦¤Þ¤¯¤¤¤Ã¤Æ¤¤¤ì¤Ð¡¢SELECT ¥³¥Þ¥ó¥É¤Ç¼¡¤Î¤è¤¦¤Ëɽµ¤µ¤ì¤ë¤Ï¤º¤À¡¥
id name pric ---- ------------- ---- 1 banana 200 3 apple 300 4 water melon 2000 5 orange 400
¼«Æ°Ï¢ÈÖµ¡Ç½¤òÍѤ¤¤ë¤È id ÈÖ¹æ 2 ¤¬·çÈ֤ΤޤޤˤʤäƤ¤¤ë¤³¤È¤ËÃí°Õ¤·¤è¤¦¡¥
SQLite3 ¤Ç¤Î¥Æ¡¼¥Ö¥ë¤Î¡ÖÁê¸ßºîÍѤò¹Íθ¤·¤¿¡×Áàºî †
¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ç¤Î¥Æ¡¼¥Ö¥ëÁê¸ßºîÍѤδðËܤϡ¢²¿¤«¤Î¹àÌܤò¶¦ÄÌ¥¡¼¤È¤·¤Æ¥Æ¡¼¥Ö¥ë¤ò¹çÂΤµ¤»¤ë¤³¤È¤Ç¤¢¤ë¡¥ Æñ¤·¤¯¤Ï¤Ê¤¤¤¬¤ä¤Ã¤Æ¤ß¤Ê¤¤¤È¼Â´¶¤·¤Ë¤¯¤¤¤Î¤Ç¡¢¼Â½¬¤òÄ̤¸¤Æ³Ø¤Ö¤È¤·¤è¤¦¡¥
½àÈ÷ †
¼Â½¬¤òÄ̤¸¤Æ³Ø¤Ö¤¿¤á¤Ë¡¢¾¯¤·½àÈ÷¤ò¤·¤è¤¦¡¥ ¶ñÂÎŪ¤Ë¤Ï¡¢¤â¤¦Æó¤Ä¡¢Â¾¤Î¥Æ¡¼¥Ö¥ë¤òƱ¤¸¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÃæ¤ËºîÀ®¤·¤è¤¦¡¥
(¼Â½¬) ¼¡¤Î¤è¤¦¤Ë CREATE ¥³¥Þ¥ó¥É¤È INSERT ¥³¥Þ¥ó¥É¤òÍѤ¤¤Æ¡¢º£¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÃæ¤Ë¤â¤¦2¤Ä¤Î¥Æ¡¼¥Ö¥ë¤òºî¤Ã¤Æ¤ª¤³¤¦¡¥
¤Þ¤º°ì¤ÄÌܤϡ¢¸ÜµÒ¥ê¥¹¥È¤òʤ٤¿ customers ¥Æ¡¼¥Ö¥ë¤Ç¤¢¤ë¡¥
¸ÜµÒ¤È¤·¤Æ 3¿Í¤Û¤É¥Ç¡¼¥¿¤òÆþ¤ì¤Æ¤ª¤³¤¦¡¥
CREATE␣TABLE␣customers␣(id␣INTEGER␣PRIMARY␣KEY␣AUTOINCREMENT, name);
INSERT␣INTO␣customers␣VALUES(NULL,"john");
INSERT␣INTO␣customers␣VALUES(NULL,"tom");
INSERT␣INTO␣customers␣VALUES(NULL,"mike");
SELECT Ì¿Îá¤ÇÃæ¿È¤ò¤ß¤ë¤È¼¡¤Î¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Ï¤º¤À¡¥
id name ---- ------------- 1 john 2 tom 3 mike
Æó¤ÄÌܤϡ¢Çä¾å¥ê¥¹¥È¤òʤ٤¿ sales ¥Æ¡¼¥Ö¥ë¤Ç¤¢¤ë¡¥
Çä¾å¥ê¥¹¥È¤Ï¡¢
id, ¸ÜµÒid, ¾¦ÉÊid, Çä¤ì¤¿¸Ä¿ô
¤È¤·¤Æ¤ª¤³¤¦¡¥
CREATE␣TABLE␣sales␣(id␣INTEGER␣PRIMARY␣KEY␣AUTOINCREMENT, customer_id, fruit_id, quantity);
¤µ¤Æ¡¢5 ²ó¤ÎÇä¾å¤²¾ðÊó¤òÆþ¤ì¤Æ¤ª¤³¤¦¡¥
INSERT␣INTO␣sales␣VALUES(NULL,2,5,3);
INSERT␣INTO␣sales␣VALUES(NULL,1,1,1);
INSERT␣INTO␣sales␣VALUES(NULL,2,3,2);
INSERT␣INTO␣sales␣VALUES(NULL,2,1,4);
INSERT␣INTO␣sales␣VALUES(NULL,3,4,10);
SELECT Ì¿Îá¤Ç sales ¥Æ¡¼¥Ö¥ë¤ÎÃæ¿È¤ò¤ß¤ë¤È¼¡¤Î¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Ï¤º¤À¡¥
id customer_id frui quan ---- ------------- ---- ---- 1 2 5 3 2 1 1 1 3 2 3 2 4 2 1 4 5 3 4 10
¤³¤Î sales ¥Æ¡¼¥Ö¥ë¤Ï¾¤Î¥Æ¡¼¥Ö¥ë¤Î¾ðÊ󤬤¢¤Ã¤Æ½é¤á¤Æ°ÕÌ£¤¬¤¢¤ë¤³¤È¤ËÃí°Õ¤·¤è¤¦¡¥
¶¦Ä̾ðÊó¤ò¤â¤È¤Ë¥Æ¡¼¥Ö¥ë¤ò¹çÂΤµ¤»¤ë †
¤³¤ì¤Ç¤³¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤Ï·× 3¤Ä¤Î¥Æ¡¼¥Ö¥ë¤¬Í¤ë¤Ï¤º¤Ç¤¢¤ë¡¥ °ì±þ¡¢.tables ¥³¥Þ¥ó¥É¤Ç
.tables
¤È¤¹¤ë¤È¡¢
customers fruits sales
¤È½ÐÎϤµ¤ì¤ë¤³¤È¤ò³Îǧ¤·¤è¤¦¡¥
¤³¤Î 3¤Ä¤Î¥Æ¡¼¥Ö¥ë¤Î¤¦¤Á¾¤Î¥Æ¡¼¥Ö¥ë¤Î¾ðÊó¤ò°úÍѤ¹¤ë·Á¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Î¤Ï sales ¥Æ¡¼¥Ö¥ë¤Ç¤¢¤ë¤Î¤Ç¡¢ sales ¥Æ¡¼¥Ö¥ë¤Ë¾¤Î¥Æ¡¼¥Ö¥ë¤Î¾ðÊó¤ò¹çÂÎ(join)¤µ¤»¤Æ¤ß¤è¤¦¡¥ ¶ñÂÎŪ¤Ë¤Ï¡¢SELECT ¤È°ì½ï¤ËJOIN Ì¿Îá¤ò»È¤Ã¤Æ¡¢¹çÂΤµ¤»¤¿¥Æ¡¼¥Ö¥ë¤«¤é¾ðÊó¤ò¼è¤ê½Ð¤¹·Á¤ò¤È¤ë¡¥ ʸˡ¤È¤·¤Æ¤Ï¼¡¤Î¤è¤¦¤Ê´¶¤¸¤À¡¥
SELECT␣*␣FROM␣¥Æ¡¼¥Ö¥ë̾1
␣JOIN␣¥Æ¡¼¥Ö¥ë̾2␣ON␣¥Æ¡¼¥Ö¥ë̾1.¹àÌÜ̾=¥Æ¡¼¥Ö¥ë̾2.¹àÌÜ̾;
ºÇ¸å¤Î = ¤Ç·Ò¤¬¤ì¤Æ¤¤¤ëÆó¤Ä¤Î¹àÌܤ¬¡¢¤³¤Î¥Æ¡¼¥Ö¥ë´Ö¤Ç¶¦Ä̤ξðÊó¤Ç¤¢¤ë¡¥ ¤Þ¤¢¡¢¼¡¤Î¼Â½¬¤ò¤ä¤Ã¤Æ¤ß¤¿¤Û¤¦¤¬¤ï¤«¤ê¤ä¤¹¤¤¤À¤í¤¦¡¥
(¼Â½¬) ¼¡¤Î¤è¤¦¤Ë, sales ¥Æ¡¼¥Ö¥ë¤ÎÇä¾å¾ðÊó¤Ç¡¢¸ÜµÒ¤Î̾Á°¤¬¸«¤¨¤ë¤è¤¦¤Ë¤·¤Æ¤ß¤è¤¦¡¥
SELECT␣*␣FROM␣sales
␣JOIN␣customers␣ON␣sales.customer_id=customers.id;
¤¹¤ë¤È¡¢¼¡¤Î¤è¤¦¤Ê´¶¤¸¤Ç¥Ç¡¼¥¿¤¬ÆÀ¤é¤ì¤ë¤Ï¤º¤Ç¤¢¤ë¡¥
id customer_id fruit_id quantity id name ---- ------------- ------------- ------------- ---- ------------- 1 2 5 3 2 tom 2 1 1 1 1 john 3 2 3 2 2 tom 4 2 1 4 2 tom 5 3 4 10 3 mike
Á´ÂΤΡ¢Âè2¹àÌÜ(sales ¥Æ¡¼¥Ö¥ë¤Î customer_id) ¤ÈÂè5¹àÌÜ(customers ¥Æ¡¼¥Ö¥ë¤Î id)¤¬°ìÃפ·¤Æ¤¤¤ë¤³¤È¤ò³Îǧ¤·¤Æ¤ª¤³¤¦¡¥
¤³¤ì¤Ç¤Ï¸«¤Ë¤¯¤¤¡¢¤È¤¤¤¦¤è¤¦¤Ç¤¢¤ì¤Ð½ÐÎϤò¸«¤ä¤¹¤¤¤â¤Î¤À¤±¤Ë¤¹¤ì¤Ð¤è¤¤¡¥
Î㤨¤Ð¼¡¤Î¤è¤¦¤Ê´¶¤¸¤À¡¥
SELECT␣sales.id, name, fruit_id, quantity
␣FROM␣sales
␣JOIN␣customers␣ON␣sales.customer_id=customers.id;
¼¡¤Î¤è¤¦¤Ê½ÐÎϤ¬ÆÀ¤é¤ì¤ë¤Ï¤º¤À¡¥
id name fruit_id quantity ---- ------------- ------------- ------------- 1 tom 5 3 2 john 1 1 3 tom 3 2 4 tom 1 4 5 mike 4 10
¥Æ¡¼¥Ö¥ë¤ò¹çÂΤµ¤»¤ë¤È¡¢Æ±¤¸¹àÌÜ̾¤¬»È¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¤¢¤ë¡¥ ¤³¤ì¤òÛ£Ëæ¤Ëµ½Ò¤·¤ÆÌ¿Î᤹¤ë¤È¥¨¥é¡¼¤Ë¤Ê¤ë¤Î¤Ç¡¢¤½¤¦¤¤¤¦»þ¤Ï ¥Æ¡¼¥Ö¥ë̾.¹àÌÜ̾ ¤È¤·¤Æ»ØÄꤷ¤Æ¡¢¶èÊ̤ò¤¹¤ë¡¥ ¾å¤ÎÎã¤Ç¤â SELECT ¤ÎÂÐ¾Ý¤Ç sales.id ¤È¤·¤Æ¶èÊ̤·¤Æ¤¤¤ë¤Î¤ËÃí°Õ¤·¤è¤¦¡¥
JOIN ¤Ï¤¤¤¯¤Ä¤Ç¤â¤¤¤±¤ë! †
JOIN ¤Ï¤¤¤¯¤Ä¤Ç¤â¥Æ¡¼¥Ö¥ë¤ò¹çÂΤµ¤»¤é¤ì¤ë¡¥ ñ¤Ë¸å¤í¤Ë³¤±¤Æµ½Ò¤¹¤ì¤Ð¤¤¤¤¤À¤±¤Ç¤¢¤ë¡¥ ¼¡¤Î¼Â½¬¤Ç³Î¤«¤á¤è¤¦¡¥
(¼Â½¬) sales ¥Æ¡¼¥Ö¥ë¤ÎÇä¾å¾ðÊó¤Ç¡¢¸ÜµÒ¤Î̾Á°¤À¤±¤Ç¤Ê¤¯¡¢¾¦ÉʤÎ̾Á°¤äñ²Á¤â¸«¤¨¤ë¤è¤¦¤Ë¤·¤è¤¦¡¥
¶ñÂÎŪ¤Ë¤ÏÀè¤ÎÎã¤Ë¤µ¤é¤Ë¤â¤¦°ì²ó join ¤ò¤¹¤ì¤ÐÎɤ¤¡¥
SELECT␣*␣FROM␣sales
␣JOIN␣customers␣ON␣sales.customer_id=customers.id
␣JOIN␣fruits␣ON␣sales.fruit_id=fruits.id;
¤¹¤ë¤È¡¢(²£¤ËŤ¤¤¬)¼¡¤Î¤è¤¦¤Ê½ÐÎϤòÆÀ¤ë¤Ï¤º¤À¡¥
id customer_id fruit_id quantity id name id name price ---- ------------- ------------- ------------- ---- ------------- -- ------------- ---------- 1 2 5 3 2 tom 5 orange 400 2 1 1 1 1 john 1 banana 200 3 2 3 2 2 tom 3 apple 300 4 2 1 4 2 tom 1 banana 200 5 3 4 10 3 mike 4 water melon 2000
¤ï¤«¤ê¤ä¤¹¤¯¤¹¤ë¤Ê¤é¤Ð¡¢¼¡¤Î¤è¤¦¤Ê´¶¤¸¤«¡¥
SELECT␣sales.id, customers.name, fruits.name, price, quantity
␣FROM␣sales
␣JOIN␣customers␣ON␣sales.customer_id=customers.id
␣JOIN␣fruits␣ON␣sales.fruit_id=fruits.id;
¤¹¤ë¤È¡¢¼¡¤Î¤è¤¦¤Êʬ¤«¤ê°×¤¤½ÐÎϤòÆÀ¤ë¤À¤í¤¦¡¥
id name name price quan ---- ------------- ------------- ------------- ---- 1 tom orange 400 3 2 john banana 200 1 3 tom apple 300 2 4 tom banana 200 4 5 mike water melon 2000 10
¤³¤ì¤ò¤ß¤ì¤Ð¡¢Î㤨¤ÐÂè4²óÌܤμè°ú¤¤Ç¤Ï tom ¤¬200±ß¤Î¥Ð¥Ê¥Ê¤ò4ËÜÇã¤Ã¤Æ¤¤¤Ã¤¿¤³¤È¤¬¤¹¤°¤ï¤«¤ë¡¥
¤³¤ó¤ÊÌÌÅݤʤ³¤È¤ò¤·¤Ê¤¤¤Ç¡¢¾å¤Îɽ¤½¤Î¤â¤Î¤òÍÑ°Õ¤·¤Æ¡¢¥Ç¡¼¥¿¤ò¤·¤Æ¤¤¤±¤Ð¤¤¤¤¤ó¤¸¤ã¤Ê¤¤¤«¤È»×¤¦¿Í¤â¤¤¤ë¤À¤í¤¦¡¥
¤·¤«¤·¤½¤ì¤ò¤ä¤ë¤È¡¢ÅÓÃæ¤Ç²¿¤«¤òÊѹ¹¤¹¤ë¤È²áµî¤Î¥Ç¡¼¥¿¤È¤Î°ì´ÓÀ¤ò¼º¤Ã¤Æ¤·¤Þ¤Ã¤¿¤ê¡¢
¤¢¤ëÍó¤Ç¤Ï tom ¤È½ñ¤Â¾¤ÎÍó¤Ç¤Ï ton ¤ÈµºÜ¥ß¥¹¤¹¤ë¤ÈÊÌ¿Í°·¤¤¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤Ã¤¿¤ê¤¹¤ë¤Î¤À¡¥
¾¦ÉʾðÊó¤Ï¾¦Éʥơ¼¥Ö¥ëñÆȤǡ¢¸ÜµÒ¾ðÊó¤Ï¸ÜµÒ¥Æ¡¼¥Ö¥ëñÆȤǴÉÍý¤Ç¤¡¢¤«¤Ä¡¢¤½¤ì¤é¤Î¾ðÊó¤ò
¾¤Î¥Æ¡¼¥Ö¥ë¤«¤é»²¾È¤Ç¤¤ë¡¢¤È¤¤¤¦¤Î¤¬ RDB ¤Î¥Ý¥¤¥ó¥È¤Ê¤Î¤Ç¤¢¤ë¡¥
¤³¤ì¤Ï¥Ç¡¼¥¿¤Î´ÉÍý¤Î¡Ö°ÂÁ´À¡×¤ò°ÕÌ£¤¹¤ë¡¥
¥Ç¡¼¥¿¤¬Â¿¤¯¡¢Ê£»¨¤Ë¤Ê¤ì¤Ð¤Ê¤ë¤Û¤É¤³¤Î¤³¤È¤Î½ÅÍ×À¤ÏÁý¤¹¤À¤í¤¦¡¥
¤µ¤Æ¡¢¤µ¤é¤Ë¥Ç¡¼¥¿¤ò¸«¤ë¤À¤±¤Ç¤Ï¤Ê¤¯¤Æ¡¢¤¹¤³¤·²Ã¹©¤·¤Æ¤ß¤è¤¦¡¥
SELECT␣sales.id, customers.name, fruits.name, price, quantity, price*quantity
␣FROM␣sales
␣JOIN␣customers␣ON␣sales.customer_id=customers.id
␣JOIN␣fruits␣ON␣sales.fruit_id=fruits.id;
¤¹¤ë¤È¼¡¤Î¤è¤¦¤Ë¡¢Ã±²Áx¸Ä¿ô=¾®·× ¤â¥ê¥¹¥È¥¢¥Ã¥×¤Ç¤¤ë¡¥
id name name price quan price*quantit ---- ------------- ------------- ------------- ---- ------------- 1 tom orange 400 3 1200 2 john banana 200 1 200 3 tom apple 300 2 600 4 tom banana 200 4 800 5 mike water melon 2000 10 20000
(±þÍÑ) ¤µ¤Æ¡¢¤µ¤é¤Ë¡¢Ã¯¤Ë¤¤¤¯¤éÀÁµá¤¹¤ë¤Ù¤¤«¤â¹ç·×¤ò¸«¤Æ¤ß¤è¤¦¡¥
¸ÜµÒ¾ðÊó¤ò¤â¤È¤Ë¤Þ¤È¤á¤ë¤ï¤±¤À¤¬¡¢¤³¤ì¤Ë¤Ï GROUP BY ¤È¤¤¤¦Ì¿Îá¤ò»È¤¦(¾Ü¤·¤¯¤Ï³Æ¿Í¤ÇÄ´¤Ù¤è¤¦)¡¥
¤Ê¤ª¡¢¹ç·×¤Ë¤Ïñ¤Ê¤ë SUM ¤È¤¤¤¦Ì¿Î᤬»È¤¨¤ë¡¥
SELECT␣customers.name, SUM(price*quantity)
␣FROM␣sales
␣JOIN␣customers␣ON␣sales.customer_id=customers.id
␣JOIN␣fruits␣ON␣sales.fruit_id=fruits.id
␣GROUP␣BY␣customers.id;
¤¹¤ë¤È¡¢¼¡¤Î¤è¤¦¤Ê½ÐÎϤòÆÀ¤ë¤³¤È¤¬¤Ç¤¤ë¡¥
name sum(price*qua ---- ------------- john 200 tom 2600 mike 20000
¤³¤ì¤Ç¡¢¤À¤ì¤Ë¹ç·×¤Ç¤¤¤¯¤é»Ùʧ¤Ã¤Æ¤â¤é¤¨¤Ð¤è¤¤¤«¡¢°ìÌÜÎÆÁ³¤Ç¤¢¤ë¡¥
ºÇ¸å¤Ë †
º£²ó¤Ï SQLite ¤ò¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤éľÀÜÁàºî¤·¤Æ RDBMS ¤ÎÆþÌçŪ¤ÊÉôʬ¤òÍý²ò¤Ç¤¤ë¤è¤¦¤ÊÆâÍƤȤ·¤¿¡¥ RDB ¤ò¼ÂÍѤ˶¡¤¹¤ë¾ì¹ç¤Ï¡¤¥é¥¤¥Ö¥é¥ê·Ðͳ¤«¥µ¡¼¥Ð·Ðͳ¤È¤Ê¤ë¤¿¤á¡¤¤µ¤é¤ËÍý²ò¤·¤Ê¤¤¤È¤¤¤±¤Ê¤¤¤³¤È¤¬Áý¤¨¤ë¤¬¡¤´ðËܤÏƱ¤¸¤Ç¤¢¤ë¡¥ ¤½¤¦¤¤¤Ã¤¿ºÝ¤Ë¤è¤¯¤ï¤«¤é¤Ê¤¯¤Ê¤Ã¤¿¤é¡¤º£²ó¤Î¤è¤¦¤ËľÀÜ¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤é³ºÅö¤¹¤ëÁàºî¤ò¤·¤Æ¤ß¤Æ¡¤¼ÂºÝ¤Ë²¿¤¬µ¯¤¤ë¤«³Îǧ¤·¤Æ¤ß¤ë¤Î¤âÎɤ¤¤À¤í¤¦¡¥
Report: ¥ì¥Ý¡¼¥È †
°Ê²¼¤Î²ÝÂê¤Ë¤Ä¤¤¤Æǽ¤¦¸Â¤ê¸ÌÀ¤ÊÄ´ºº¤È¹Í»¡¤ò¹Ô¤¤¡¤
AppliedMath7-Report-14
¤È¤¤¤¦Âê̾¤ò¤Ä¤±¤Æ e-mail ¤Ë¤Æ¶µ´±°¸¤Ë¥ì¥Ý¡¼¥È¤È¤·¤ÆÄó½Ð¤»¤è. ¤Ê¤ª¡¤¥ì¥Ý¡¼¥È¤ò e-mail ¤ÎÂå¤ï¤ê¤Ë TeX ¤ÇºîÀ®¤·¤¿½ñÌ̤ˤÆÄó½Ð¤·¤Æ¤â¤è¤¤.
Exercises: ²ÝÂê †
- ¾å¤Î¼Â½¬¤ò³¤±¤Æ¡¢¤µ¤é¤Ë¡¢¤É¤Î¾¦Éʤ¬¹ç·×¤Ç¤¤¤¯¤ÄÇä¤ì¤¿¤«¡¢¤ò½ÐÎϤµ¤»¤Æ¤ß¤è¡¥
- SQLite ¤Ç¡¢¥Õ¥¡¥¤¥ë¤«¤é¥Ç¡¼¥¿¤òÆɤ߹þ¤àÊýË¡¤òÄ´¤Ù¤è¡¥
- SQLite ¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò GUI ¤ÇÁàºî¤Ç¤¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬Â¿¿ô¸ºß¤¹¤ë¡¥
¤½¤¦¤¤¤Ã¤¿Êª¤òõ¤·¡¤¤½¤Î¤¦¤Á¤Î°ì¤Ä¤ÇÎɤ¤¤Î¤Ç¼ÂºÝ¤ËÁàºî¤·¤Æ»î¤·¤Æ¤ß¤è¡¥
- ¼«Ê¬¤ÎÀ¸³è¤ÎÃæ¤Ç SQLite ¤òÍøÍѤ¹¤ë¤ÈÊØÍø¤Ë¤Ê¤ê¤½¤¦¤Ê¥·¡¼¥ó¤¬¤Ê¤¤¤«¡¢¹Í¤¨¤Æ¤ß¤è¡¥
about Icons, ClipArts †
For details, see this.
*1 ¤½¤â¤½¤âÏÀ¤Ç¸À¤¨¤Ð OS ¤¬Ä󶡤¹¤ëµ¡Ç½¤Ï¤¢¤ëÄøÅÙ¤³¤¦¤·¤¿¤â¤Î¤Ð¤«¤ê¤À¤¬¡¥
*2 ƳÆþ¤·¤Æ¤â¤â¤Á¤í¤óÌäÂê¤Ï¤Ê¤¤¤±¤ì¤É¤â
*3 Í̾¤É¤³¤í¤À¤È¡¤firefox ¤ä android ¤Ç»È¤ï¤ì¤Æ¤¤¤ë¡¥
*4 Àµ³Î¤Ë¤Ï¡¢¤¿¤Ó¤¿¤Óµ¬³Ê²½¤µ¤ì¤Æ¤¤¤ë¤¬¡¢³Æ¼ï¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¡ÖÊý¸À¡×¤¬¤Þ¤À¤¤¤í¤¤¤í¤¢¤ë¤È¤¤¤¦¾õÂÖ¡¥
*5 Ê̤Υǡ¼¥¿¥Ù¡¼¥¹¤Î¥Æ¡¼¥Ö¥ë¤È´Ø·¸¤Å¤±¤ë¤³¤È¤â½ÐÍè¤ë
źÉÕ¥Õ¥¡¥¤¥ë: database-table-data-diagram.png 903·ï [¾ÜºÙ] how-to-treat-db-via-sqlite.png 886·ï [¾ÜºÙ] SQLite-commands.png 846·ï [¾ÜºÙ]