ãã®æ å ±ã¯åå¿è åãã§ãã
å©ããŠãããŸããã ãããããããã¯ä»ã®èª°ããã®ã£ãããåããã®ã«åœ¹ç«ã€ã§ãããã
ããŒã¿ããŒã¹èšèšã¬ã€ãã
1.ã¯ããã«ã
ç¬èªã®ããŒã¿ããŒã¹ãäœæããå Žåã¯ãããŒã¿ããŒã¹ã®èšèšã«ãŒã«ãéµå®ããããšããå§ãããŸããããã«ãããããŒã¿ã®é·æçãªæŽåæ§ãšã¡ã³ããã³ã¹ã®å®¹æããä¿èšŒãããŸãã ãã®ã¬ã€ãã§ã¯ãããŒã¿ããŒã¹ãšã¯äœããããã³ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ãèšèšããããã®ã«ãŒã«ã«åŸãããŒã¿ããŒã¹ãèšèšããæ¹æ³ã«ã€ããŠèª¬æããŸãã
ããŒã¿ããŒã¹ã¯ã倧éã®é¢é£æ å ±ãä¿åããã³åä¿¡ã§ããããã°ã©ã ã§ãã ããŒã¿ããŒã¹ã¯ã æ å ±ãå«ãããŒãã«ã§æ§æãããŸã ã ããŒã¿ããŒã¹ãäœæãããšããäœæããå¿ èŠã®ããããŒãã«ãšãããŒãã«å ã®æ å ±éã«ååšããé¢ä¿ã«ã€ããŠèããå¿ èŠããããŸãã ã€ãŸããããŒã¿ããŒã¹ã®èšèšã«ã€ããŠèããå¿ èŠããããŸãã åè¿°ã®ããã«ã é©åãªããŒã¿ããŒã¹èšèšã«ãããããŒã¿ã®æŽåæ§ãšã¡ã³ããã³ã¹ã®å®¹æããä¿èšŒãããŸãã
æ§é åç §äŒèšèªïŒSQLïŒã
ããŒã¿ããŒã¹ãäœæããŠãæ å ±ãä¿åããå¿ èŠã«å¿ããŠãã®æ å ±ãååŸããŸãã ããã¯ãããŒã¿ããŒã¹ã«æ å ±ãæ¿å ¥ãæ¿å ¥ïŒ INSERT ïŒã§ããªããã°ãªãããããŒã¿ããŒã¹ããæ å ±ãéžæã§ããïŒ SELECT ïŒããšãã§ããããšãæå³ããŸãã
ããŒã¿ããŒã¹ã¯ãšãªèšèªã¯ãããã®ç®çã®ããã«èæ¡ããã æ§é åã¯ãšãªèšèªãŸãã¯SQLãšåŒã°ããŠããŸããã ããŒã¿æ¿å ¥æäœïŒINSERTïŒãšãã®éžæïŒSELECTïŒã¯ããã®èšèªèªäœã®äžéšã§ãã 以äžã¯ãããŒã¿ãµã³ããªã³ã°ã®ã¯ãšãªãšãã®çµæã®äŸã§ãã
SQLã¯ãã¬ãŒã·ã§ã³ãã倧ããªãããã¯ã§ããããã®æ€èšã¯ãã®ã¬ã€ãã®ç¯å²å€ã§ãã ãã®èšäºã¯ãããŒã¿ããŒã¹èšèšããã»ã¹ã®ãã¬ãŒã³ããŒã·ã§ã³ã«å³å¯ã«çŠç¹ãåœãŠãŠããŸã ã åŸã§ãå¥ã®ã¬ã€ãã§ãSQLã®åºæ¬ã«ã€ããŠèª¬æããŸãã
ãªã¬ãŒã·ã§ãã«ã¢ãã«ã
ãã®ãã¥ãŒããªã¢ã«ã§ã¯ããªã¬ãŒã·ã§ãã«ããŒã¿ã¢ãã«ãäœæããæ¹æ³ã瀺ããŸãã ãªã¬ãŒã·ã§ãã«ã¢ãã«ã¯ãããŒã¿ãããŒãã«ã«æŽçããæ¹æ³ãšããããã®ããŒãã«éã®é¢ä¿ãå€æããæ¹æ³ã説æããã¢ãã«ã§ãã
ãªã¬ãŒã·ã§ãã«ã¢ãã«ã®ã«ãŒã«ã¯ãæ å ±ãããŒãã«ã«æŽçããæ¹æ³ãšãããŒãã«ãçžäºã«é¢é£ä»ããæ¹æ³ãèŠå®ããŠããŸãã æçµçã«ãçµæã¯ããŒââã¿ããŒã¹å³ãããæ£ç¢ºã«ã¯ãå³ïŒMySQL Workbenchããã®äŸïŒã®ãããªãšã³ãã£ãã£é¢ä¿å³ã®åœ¢åŒã§è¡šç€ºã§ããŸãã
äŸã
ããã¥ã¢ã«ã®äŸãšããŠãå€ãã®ã¢ããªã±ãŒã·ã§ã³ã䜿çšããŸããã
RDBMS
ãµã³ãã«ããŒãã«ã®äœæã«äœ¿çšããRDBMSã¯MySQLã§ãã MySQLã¯æã人æ°ã®ããRDBMSã§ãããç¡æã§ãã
ããŒã¿ããŒã¹ç®¡çã®ããã®ãŠãŒãã£ãªãã£ã
MySQLãã€ã³ã¹ããŒã«ããåŸãMySQLãšå¯Ÿè©±ããããã®ã³ãã³ãã©ã€ã³ã€ã³ã¿ãŒãã§ã€ã¹ã®ã¿ãååŸããŸãã å人çã«ã¯ãããŒã¿ããŒã¹ã管çããããã®ã°ã©ãã£ã«ã«ã€ã³ã¿ãŒãã§ã€ã¹ã奜ã¿ãŸãã ç§ã¯ããSQLyogã䜿çšããŸãã ããã¯ç¡æã®GUIãŠãŒãã£ãªãã£ã§ãã ãã®ããã¥ã¢ã«ã®è¡šã®ç»åã¯ããããåãããŠããŸãã
èŠèŠã¢ããªã³ã°ã
åªããç¡æã®MySQL Workbenchã¢ããªã±ãŒã·ã§ã³ããããŸãã ããŒã¿ããŒã¹ãã°ã©ãã£ã«ã«ã«èšèšã§ããŸãã ããã¥ã¢ã«å ã®å³ã®ç»åã¯ããã®ããã°ã©ã ã§äœæãããŠããŸãã
RDBMSã«äŸåããªãèšèšã
ãã®ããã¥ã¢ã«ã§ã¯MySQLã®äŸã瀺ããŠããŸãããããŒã¿ããŒã¹èšèšã¯RDBMSããç¬ç«ããŠããããšãç¥ã£ãŠããããšãéèŠã§ãã ããã¯ãæ å ±ãMySQLã ãã§ãªãäžè¬çãªãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã«é©çšã§ããããšãæå³ããŸãã ãã®ã¬ã€ãã®ç¥èã¯ãMysqlãPostgresqlãMicrosoft AccessãMicrosoft SqlãOracleãªã©ã®ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã«é©çšã§ããŸãã
次ã®éšåã§ã¯ãããŒã¿ããŒã¹ã®é²åã«ã€ããŠç°¡åã«èª¬æããŸãã ããŒã¿ããŒã¹ãšãªã¬ãŒã·ã§ãã«ããŒã¿ã¢ãã«ãã©ãããæ¥ãã®ããåŠã³ãŸãã
2.å±¥æŽã
70幎代ããã³80幎代ãã³ã³ãã¥ãŒã¿ãŒç§åŠè ããŸã 倧ããªæ£æ¹åœ¢ã®ãã¬ãŒã ã®è¶è²ã®ã¿ãã·ãŒããšã¡ã¬ããççšããŠãããšããããŒã¿ã¯æ§é çã«ãã¡ã€ã«ã«ä¿åãããŠããŸããã
ããã¯70幎代ã®ITãããã§ãã·ã§ãã«ã®å§¿ã§ããã ïŒãã«ã²ã€ãã¯å·Šäžã«ãããŸãïŒã
ããã¹ããã¡ã€ã«ã¯ãä»æ¥ã§ãå°éã®ç°¡åãªæ å ±ãä¿åããããã«äœ¿çšãããŠããŸãã ã³ã³ãåºåãå€ïŒCSVïŒ-ã³ã³ãåºåãå€ã¯éåžžã«äººæ°ããããä»æ¥ã§ã¯ããŸããŸãªãœãããŠã§ã¢ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§åºããµããŒããããŠããŸãã Microsoft Excelã¯ãCSVãã¡ã€ã«ãåŠçã§ããããã°ã©ã ã®äžäŸã§ãã ãã®ãããªãã¡ã€ã«ã«ä¿åãããããŒã¿ã¯ãã³ã³ãã¥ãŒã¿ãŒããã°ã©ã ã§èªã¿åãããšãã§ããŸãã
äžèšã¯ããã®ãããªãã¡ã€ã«ãã©ã®ããã«èŠãããã®äŸã§ãã ãã®ãã¡ã€ã«ãèªã¿åãããã°ã©ã ã«ã¯ãããŒã¿ãã³ã³ãã§åºåãããŠããããšãéç¥ããå¿ èŠããããŸãã ããã°ã©ã ããããŒã¿ããŒã¹èšèšãã¥ãŒããªã¢ã«ãã®ã¬ãã¹ã³ãããã«ããŽãªãéžæããŠè¡šç€ºããå Žåã ãããŒã¿ããŒã¹èšèšãã¥ãŒããªã¢ã«ããšããåèªãèŠã€ãããŸã§è¡ããšã«èªã¿ãã³ã³ãã«ç¶ãåèªãèªãå¿ èŠããããŸããã«ããŽãªãœãããŠã§ã¢ãæšè«ããããã«ã
ããŒã¿ããŒã¹ããŒãã«ã
ãã¡ã€ã«ã1è¡ãã€èªã¿åãã®ã¯ããŸãå¹ççã§ã¯ãããŸããã ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã§ã¯ãããŒã¿ã¯ããŒãã«ã«æ ŒçŽãããŸãã 次ã®è¡šã«ã¯ããã¡ã€ã«ãšåãããŒã¿ãå«ãŸããŠããŸãã åè¡ãŸãã¯ããšã³ããªãã«ã¯1ã€ã®ã¬ãã¹ã³ãå«ãŸããŸãã ååã«ã¯ãã¬ãã¹ã³ã®ããããã£ãå«ãŸããŸãã ãã®å Žåãããã¯ã¿ã€ãã«ïŒã¿ã€ãã«ïŒãšãã®ã«ããŽãªïŒã«ããŽãªïŒã§ãã
察å¿ããã¿ã€ãã«ãšã«ããŽãªããã°ããèŠã€ããããã«ãã³ã³ãã¥ãŒã¿ãŒããã°ã©ã ã¯ãã®ããŒãã«ã®tutorial_idåã§ç¹å®ã®tutorial_idèå¥åãæ€çŽ¢ã§ããŸãã ããã¯ãããã°ã©ã ãããã¹ããã¡ã€ã«ã§è¡ãæ¹æ³ãšåæ§ã«ããã¡ã€ã«ã1è¡ãã€æ€çŽ¢ãããããã¯ããã«é«éã§ãã
ææ°ã®ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã¯ãç¹å®ã®è¡ãåãããã³è€æ°ã®ããŒãã«ããäžåºŠã«éåžžã«è¿ éã«ããŒã¿ãéžæã§ããããã«èšèšãããŠããŸãã
ãªã¬ãŒã·ã§ãã«ã¢ãã«ã®å±¥æŽã
ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã¢ãã«ã¯ãè±åœã®ç§åŠè ã§ãããšãã¬ãŒã³ããïŒãããã³ããïŒã«ãã£ãŠ70幎代ã«çºæãããŸããã 圌ã¯ããããã¯ãŒã¯ããŒã¿ããŒã¹ã¢ãã«ãšéå±€ã¢ãã«ã®æ¬ ç¹ãå æããããšèããŠããŸããã ãããŠåœŒã¯ããã§éåžžã«æåããŸããã ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã¢ãã«ã¯ä»æ¥åºãåãå ¥ããããŠãããå¹ççãªããŒã¿ç·šæã®ããã®åŒ·åãªã¢ãã«ãšèããããŠããŸãã
ä»æ¥ãããŒã¿ããŒã¹ç®¡çã·ã¹ãã ã®å¹ åºãéžæãå©çšå¯èœã§ãïŒå°ããªãã¹ã¯ãããã¢ããªã±ãŒã·ã§ã³ããé«åºŠã«æé©åãããæ€çŽ¢æ¹æ³ãåããå€æ©èœãµãŒããŒã·ã¹ãã ãŸã§ã æãããç¥ãããŠãããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ç®¡çã·ã¹ãã ïŒRDBMSïŒã®äžéšã次ã«ç€ºããŸãã
-Oracle-äž»ã«ãããã§ãã·ã§ãã«ã§å€§èŠæš¡ãªã¢ããªã±ãŒã·ã§ã³ã«äœ¿çšãããŸãã
-Microsoft SQLãµãŒã㌠-Microsoft RDBMSã Windowsãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã®ã¿äœ¿çšã§ããŸãã
-Mysqlã¯éåžžã«äººæ°ã®ãããªãŒãã³ãœãŒã¹RDBMSã§ãã ãããšåå¿è ã®äž¡æ¹ãåºã䜿çšããŠããŸãã ä»ã«äœãå¿ èŠã§ããïŒïŒ 圌女ã¯ç¡æã§ãã
-IBM-å€ãã®RDBMSããããæãæåãªã®ã¯DB2ã§ãã
-Microsoft Access-ãªãã£ã¹ããã³èªå® ã§äœ¿çšãããRDBMSã å®éãåãªãããŒã¿ããŒã¹ã§ã¯ãããŸããã MS Accessã§ã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããŠããŒã¿ããŒã¹ãäœæã§ããŸãã
次ã®éšåã§ã¯ããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã®ç¹æ§ã«ã€ããŠèª¬æããŸãã
3.ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã®ç¹æ§ã
ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã¯ã倧éã®æ å ±ããã°ããä¿åããã³ååŸã§ããããã«èšèšãããŠããŸãã 以äžã¯ããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ãšãªã¬ãŒã·ã§ãã«ããŒã¿ã¢ãã«ã®ããã€ãã®ç¹æ§ã§ãã
ããŒã®äœ¿çšã
ããŒãã«å ã®ããŒã¿ã®åè¡ã¯ãäž»ããŒãšåŒã°ããäžæã®ãããŒãã«ãã£ãŠèå¥ãããŸãã å€ãã®å Žåãäž»ããŒã¯èªåçã«ã€ã³ã¯ãªã¡ã³ããããïŒèªåã€ã³ã¯ãªã¡ã³ãïŒçªå·ïŒ1ã2ã3ã4ãªã©ïŒã§ãã ããŒã䜿çšããŠãããŸããŸãªããŒãã«ã®ããŒã¿ããªã³ã¯ã§ããŸãã 1ã€ã®ããŒãã«ã®äž»ããŒå€ãå¥ã®ããŒãã«ã®è¡ïŒã¬ã³ãŒãïŒã«è¿œå ããŠããããã®ã¬ã³ãŒãããªã³ã¯ã§ããŸãã
æ§é åç §äŒèšèªïŒSQLïŒã䜿çšãããšãããŒã§ãªã³ã¯ãããŠããããŸããŸãªããŒãã«ã®ããŒã¿ãäžåºŠã«éžæã§ããŸãã ããšãã°ãusersããŒãã«ã®èå¥åïŒidïŒ3ïŒãã€ã¯ïŒãæã€ãŠãŒã¶ãŒã«å±ãããã¹ãŠã®æ³šæããordersããŒãã«ããéžæããã¯ãšãªãäœæã§ããŸãã ããŒã«ã€ããŠã¯ãåŸã®éšåã§èª¬æããŸãã
ãã®ããŒãã«ã®idåã¯äž»ããŒã§ãã åãšã³ããªã«ã¯ãå€ãã®å Žåãçªå·ã§ããäžæã®äž»ããŒããããŸãã usergroupåã¯å€éšããŒã§ãã ååããå€æãããšãæããã«ãŠãŒã¶ãŒã°ã«ãŒããå«ãããŒãã«ãæããŸãã
ããŒã¿ã®åé·æ§ã®æ¬ åŠã
ãªã¬ãŒã·ã§ãã«ããŒã¿ã¢ãã«ã®ã«ãŒã«ãèæ ®ããŠäœæãããããŒã¿ããŒã¹ãããžã§ã¯ãã§ã¯ããŠãŒã¶ãŒåãªã©ã®åæ å ±ã¯1ãæã«ã®ã¿ä¿åãããŸãã ããã«ãããè€æ°ã®å Žæã§ããŒã¿ãæäœããå¿ èŠããªããªããŸãã ããŒã¿ã®éè€ã¯ããŒã¿ã®åé·æ§ãšåŒã°ããé©åãªããŒã¿ããŒã¹èšèšã§ã¯é¿ããå¿ èŠããããŸãã
å ¥åå¶éã
ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã䜿çšãããšãåã«æ ŒçŽã§ããããŒã¿ã®çš®é¡ã決å®ã§ããŸãã æŽæ°ã10é²æ°ãå°ããªããã¹ããã£ã³ã¯ã倧ããªããã¹ããã£ã³ã¯ãæ¥ä»ãªã©ãå«ããã£ãŒã«ããäœæã§ããŸãã
ããŒã¿ããŒã¹ããŒãã«ãäœæãããšããååã«ããŒã¿åãæå®ããŸãã ããšãã°ãvarcharã¯æ倧æåæ°ã255ã®å°ããªããã¹ããã©ã°ã¡ã³ãã®ããŒã¿åã§ãããintã¯æ°åã§ãã
ããŒã¿åã«å ããŠãRDBMSã§ã¯ãå ¥åã§ããããŒã¿ãããã«å¶éã§ããŸãã ããšãã°ãé·ããå¶éãããããã®åã®ãšã³ããªã®å€ã®äžææ§ã匷å¶ããŸãã åŸè ã®å¶éã¯ããŠãŒã¶ãŒã®ãã°ã€ã³åïŒãã°ã€ã³ïŒãŸãã¯é»åã¡ãŒã«ã¢ãã¬ã¹ãå«ããã£ãŒã«ãã«ãã䜿çšãããŸãã
ãããã®å¶éã«ãããããŒã¿ã®æŽåæ§ãå¶åŸ¡ãã次ã®ãããªç¶æ³ãé²ãããšãã§ããŸãã
-çªå·ã衚瀺ããããšäºæ³ããããã£ãŒã«ãã«ã¢ãã¬ã¹ïŒããã¹ãïŒãå ¥åããŸã
-ãã®ã€ã³ããã¯ã¹èªäœã®é·ãã100æåã§æå®ããŠããªãŒãžã§ã³ã€ã³ããã¯ã¹ãå ¥åããŸã
-åãååã®ãŠãŒã¶ãŒãäœæãã
-åãã¡ãŒã«ã¢ãã¬ã¹ãæã€ãŠãŒã¶ãŒãäœæãã
-èªçæ¥ãã£ãŒã«ãïŒæ¥ä»ïŒã«ééïŒæ°å€ïŒãå ¥åããŸã
ããŒã¿ã®æŽåæ§ãç¶æããŸãã
ãã£ãŒã«ãã®ããããã£ã調æŽããããŒãã«ãçžäºã«ãªã³ã¯ããå¶éãèšå®ããããšã«ãããããŒã¿ã®ä¿¡é Œæ§ãé«ããããšãã§ããŸãã
æš©å©ã®è²æž¡ã
ã»ãšãã©ã®RDBMSã«ã¯ãç¹å®ã®ãŠãŒã¶ãŒã«ç¹å®ã®æš©éãå²ãåœãŠãããšãã§ããã¢ã¯ã»ã¹èš±å¯èšå®ããããŸãã ãŠãŒã¶ãŒã«èš±å¯ãŸãã¯æåŠã§ããã¢ã¯ã·ã§ã³ïŒSELECTïŒéžæïŒãINSERTïŒæ¿å ¥ïŒãDELETEïŒåé€ïŒãALTERïŒå€æŽïŒãCREATEïŒäœæïŒãªã© ãããã¯ãæ§é åç §äŒèšèªïŒSQLïŒã䜿çšããŠå®è¡ã§ããæäœã§ãã
æ§é åç §äŒèšèªïŒSQLïŒã
ããŒã¿ã®ä¿åãéžæãå€æŽãªã©ãããŒã¿ããŒã¹ã«å¯ŸããŠç¹å®ã®æäœãå®è¡ããããã«ãæ§é åç §äŒèšèªïŒSQLïŒã䜿çšãããŸãã SQLã¯æ¯èŒçç解ããããã SQL JOINã¹ããŒãã¡ã³ãã䜿çšããŠè€æ°ã®ããŒãã«ããé¢é£ããŒã¿ããã§ãããããªã©ãã¹ã¿ãã¯éžæã åè¿°ã®ãšããããã®ã¬ã€ãã§ã¯SQLã«ã€ããŠã¯èª¬æããŸããã ããŒã¿ããŒã¹èšèšã«çŠç¹ãåœãŠãŸãã
ããŒã¿ããŒã¹ã®èšèšæ¹æ³ã¯ãããŒã¿ããŒã¹ããããŒã¿ãååŸããããã«å®äºããå¿ èŠãããã¯ãšãªã«çŽæ¥åœ±é¿ããŸãã ããã¯ãããŒã¹ãã©ãããã¹ãããèããå¿ èŠããããã1ã€ã®çç±ã§ãã é©åã«èšèšãããããŒã¿ããŒã¹ã䜿çšãããšãã¯ãšãªãããã¯ãªãŒã³ã§ã·ã³ãã«ã«ã§ããŸãã
移æ€æ§ã
ãªã¬ãŒã·ã§ãã«ããŒã¿ã¢ãã«ã¯æšæºã§ãã ãªã¬ãŒã·ã§ãã«ããŒã¿ã¢ãã«ã®ã«ãŒã«ã«åŸãããšã«ãããããŒã¿ãæ¯èŒçç°¡åã«å¥ã®RDBMSã«è»¢éã§ããããã«ãªããŸãã
åè¿°ããããã«ãããŒã¿ããŒã¹ã®èšèšã¯ãããŒã¿ãšãã®é¢ä¿ãç¹å®ãããã®åé¡ã解決ããçµæãçŽã«ïŒãŸãã¯ã³ã³ãã¥ãŒã¿ãŒããã°ã©ã ã§ïŒäœæããããšã§ãã ããŒã¿ããŒã¹ã®èšèšã¯ãããŒã¿ããŒã¹ã®äœæã«äœ¿çšããRDBMSãšã¯ç¡é¢ä¿ã§ãã
次ã®éšåã§ã¯ãäž»ããŒã«ã€ããŠè©³ããèŠãŠãããŸãã