RDBMSã®é¢ä¿
ãã®èšäºã¯ç§ãä»åºŠåãã倧åŠã®è©Šéšã«åããã¢ãŠããããã«ãªããŸããå匷ããããšãNotionã«ãŸãšããŠãããšãããnoteã§ãŸãšããŠããã°äžãäžééããŠãæã«èª°ããææããŠããããããããªããšããæ·¡ãæåŸ ã蟌ããŠæžããŠããŸãããªã®ã§åèã«ãªããªãå¯èœæ§ããããŸãããRDBMSã«ã€ããŠç解ãæ·±ãããããšããæ¹ã¯ãã²èªãã§ããã ãããšå¬ããã§ãã
RDBMSã«é¢ããŠã¯ãããŸã§ã«ã€ããŠãåºæ¬çãªããšã¯ãŸãšããŠããã®ã§å²æããŸãããç°¡åã«ãããšRDBMSã¯ããŒãã«å士ã®é¢ä¿ã§æãç«ã£ãŠããŸãã
ãã®èšäºã§ã¯DBèšèšã«ã¯æ¬ ãããªãç¥èãšããŠããŒãã«å士ãã©ãé¢ä¿ããŠãã®ããèŠãŠãããããšæããŸãã
One-to-many relationships (1:M)
äžçªå€ãé¢ä¿ãšããŠ1察å€ïŒOne-to-many relationshipïŒãæããããŸãã
äŸãã°ãååãšååã«ããŽãªã®ããŒãã«ãããã1ã€ã®ã«ããŽãªã«è€æ°ã®ååãå«ãŸããŠãããšããŸããåã«ããŽãªã¯å€ãã®è£œåãå«ãããšãã§ããå補åã¯1ã€ã®ã«ããŽãªã«åé¡ãããŸãã
äžèšã¯ãCategoryããŒãã«ã®idãProductããŒãã«ã®å€éšããŒãšããŠçŽã¥ããŠããŸãããã®ããŒãã«ããäžã€ã®ã«ããŽãªãŒã«å¯ŸããŠè€æ°ã®ååãçŽã¥ããŠããã®ãããããŸãããã®ãã1察å€ã®é¢ä¿ã§ãããšèšããŸãã
Many-to-many relationships (M:M)
å€å¯Ÿå€ã®é¢ä¿ãç¥ãã«ã¯ãåŠæ ¡ã®ããŒã¿ããŒã¹ãèšèšããäŸãæããŠèª¬æããŠãããããšæããŸããåæãšããŠçåŸã¯è€æ°ã®ç§ç®ã履修ã§ããäžã€ã®ç§ç®ã§ã¯è€æ°ã®çåŸãååšããŸãããããªããšä»¥äžã®ãããªãã¿ãŒã³ã®ããŒãã«ãæ³å®ãããŸãã
ãã¿ãŒã³â StudentããŒãã«ã«è€åããŒãšããŠè¿œå ãã
StudentããŒãã«ã«ã¯ClassããŒãã«ã®IDãšçµã¿åãããŠè€åããŒã«ããŠããŸããè€åããŒãšã¯è€æ°ã®åããæ§æãããäž»ããŒã®ããšã§ããã®å ŽåãStudentããŒãã«ã®idã ãã ãšäžäººã®çåŸã«è€æ°ã®ç§ç®ã履修ã§ããããåäžã®åãšããŠèªèãããŸããããã®ããclass_idãšçµã¿åãããŠè€åããŒã«ããŠããŸãããããããã¯äžè¬çã«å¥œãŸããªããã¿ãŒã³ã«ãªããŸããäŸãã°ãã®åãçåŸã®ååã®ã©ããäžã€ã ããå ¥åééãã§ã¿ã€ããçºçããŠãããããã¯åãçåŸãšã¿ãªãããŸããããŸããçåŸã®ååãä¿®æ£ã»åé€ãã床ã«å€§éã®ããŒã¿ãæŽæ°ããå¿ èŠãåºãŠããããå¹ççã§ã¯ãªãããã§ããããããStudentããŒãã«ãªã®ã«äžäººã®çåŸããè€æ°ã®ã¬ã³ãŒããè¿ã£ãŠããã®ã¯éåæãèŠããŸãã
ãã¿ãŒã³â¡StudentããŒãã«ã«è€æ°ã®å€éšããŒãäžã€ã®ãã£ãŒã«ãã«ãŸãšããŠããŸã
äžèšã¯ãã¿ãŒã³â ãæ¹åããŠäžã€ã®ãã£ãŒã«ãã«è€æ°ã®å€éšããŒãåœãŠã¯ããŠããŸããããã§ã¿ã€ããçºçããŠã倧äžå€«ãããªæ°ãããŸãããããã¯RDBMSã®ã«ãŒã«ã«åããŠããŸããäžã€ã®ãã£ãŒã«ãã«ã¯å¿ ãäžã€ã®å€ããæ ŒçŽããããšãã§ããŸããããã®ããåãååã ãããšè€æ°ã®å€éšããŒãäžã€ã®ãã£ãŒã«ãã«ã¯å«ããããŸããããããã©ãããããããã ãšããæã«ç»å Žããã®ãäžéããŒãã«ã«ãªããŸãã
ãã¿ãŒã³â¢äžéããŒãã«ã䜿çšãã
æ°ãã«EnrollmentãšããäžéããŒãã«ãäœæããClass,Studentããããã®ããŒãã«ããidãå€éšããŒãšããŠååŸããŠããŸããããã§äžäººã®çåŸãè€æ°ã®ææ¥ã履修ããŠããããšããäžã€ã®ã¯ã©ã¹ã§è€æ°ã®çåŸãããããšãããããŸãããã¿ã€ããçºçããŠãå€éšããŒã ããçŽä»ããŠããã®ã§ä¿®æ£ããŠãäžéããŒãã«ã«åœ±é¿ããŸããã
ãã®ãããå€å¯Ÿå€ã®é¢ä¿ã¯äžéããŒãã«ãçšããŠç®¡çããã®ãäžè¬çã§ãã
One-to-one relationship (1:1)
1察1ã®é¢ä¿ã¯2ã€ã®ããŒãã«éã§ã1ã€ã®ã¬ã³ãŒãããã1ã€ã®ããŒãã«ã®1ã€ã®ã¬ã³ãŒãã«ã®ã¿é¢é£ä»ãããããã®ã§ãããã®ã¿ã€ãã®ãªã¬ãŒã·ã§ã³ã·ããã¯ãããŒã¿ããŒã¹ã§ã¯æ¯èŒçãŸããªæ°ãããŸããïŒ1察1ãªãããäžã€ã®ããŒãã«ã«ããã°è¯ããªãããšïŒãããããäŸã ãšãŠãŒã¶ãŒæ å ±åšãããªãšæããŸãã
äžèšã¯ãUsers ããŒãã«ãš UserSettings ããŒãã«ããããåãŠãŒã¶ã«å¿
ã 1 ã€ã®èšå®ã ããé¢é£ä»ããããŸããUserããŒãã«ãåºæ¬çãªãŠãŒã¶ãŒæ
å ±ãæã¡ãUser Settingsã§ã¯éç¥ã®æç¡ãã¢ãŒãã®èšå®ãªã©ããªãã·ã§ã³çãªæ
å ±ãå«ãŸããŸãã
Users ããŒãã«ã® UserID ã UserSettings ããŒãã«ã®å€éšããŒãšããŠäœ¿çšãããåãŠãŒã¶ãäžæã®ãããã¡ã€ã«ãæã€ããã«ããŸãããã®ããã«äºã€ã®ããŒãã«ãäžã€ã«ããã®ã§ã¯ãªããåããããšã®ã¡ãªãããšããŠã»ãã¥ãªãã£åŒ·åãæããããã®ããªãšæããŸãã
ææ³
DBèšèšããããèªåã¯ç解ããã®ã«ãšã£ãŠãæéãæããã¿ã€ããªã®ã§ã¹ããšç解ã§ãã人ã矚ãŸãããªãšæãæ¥ã ã§ãã次ã¯æ£èŠåã§ãã
ãã®èšäºãæ°ã«å ¥ã£ãããµããŒããããŠã¿ãŸãããïŒ