{"id":6196,"date":"2025-10-12T23:03:23","date_gmt":"2025-10-12T14:03:23","guid":{"rendered":"https:\/\/sky-peace.net\/?p=6196"},"modified":"2025-10-12T23:03:23","modified_gmt":"2025-10-12T14:03:23","slug":"sql-er-relation","status":"publish","type":"post","link":"https:\/\/sky-peace.net\/certified\/sql-er-relation\/","title":{"rendered":"\u3010\u56f3\u89e3\u3068SQL\u3067\u7406\u89e3\u3011ER\u56f3\u3068\u5916\u90e8\u30ad\u30fc\u306e\u57fa\u672c\uff5c\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u3068\u53c2\u7167\u6574\u5408\u6027\u5236\u7d04\u3092\u3084\u3055\u3057\u304f\u89e3\u8aac"},"content":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u3001\u7279\u306b\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306e\u52c9\u5f37\u3092\u59cb\u3081\u308b\u3068\u3001\u5fc5\u305a\u3068\u8a00\u3063\u3066\u3044\u3044\u307b\u3069\u767b\u5834\u3059\u308b\u306e\u304c\u300c<strong>ER\u56f3<\/strong>\u300d\u3084\u300c<strong>\u5916\u90e8\u30ad\u30fc<\/strong>\u300d\u3068\u3044\u3063\u305f\u5c02\u9580\u7528\u8a9e\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u300c\u4e3b\u30ad\u30fc\u3068\u5916\u90e8\u30ad\u30fc\u3063\u3066\u3001\u540d\u524d\u306f\u4f3c\u3066\u3044\u308b\u3051\u3069\u4f55\u304c\u9055\u3046\u306e\uff1f\u300d\u300cER\u56f3\u306b\u63cf\u304b\u308c\u3066\u3044\u308b\u7dda\u3084\u8a18\u53f7\u306b\u306f\u3001\u3069\u3093\u306a\u610f\u5473\u304c\u3042\u308b\u306e\uff1f\u300d\u3068\u3001\u6700\u521d\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u3064\u307e\u305a\u3044\u3066\u3057\u307e\u3046\u65b9\u3082\u5c11\u306a\u304f\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u308c\u3089\u306e\u6982\u5ff5\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u9aa8\u683c\u3092\u306a\u3059\u975e\u5e38\u306b\u91cd\u8981\u306a\u90e8\u5206\u3067\u3059\u304c\u3001\u305d\u308c\u305e\u308c\u306e\u95a2\u4fc2\u6027\u3092\u6b63\u3057\u304f\u7406\u89e3\u3057\u306a\u3044\u307e\u307e\u6697\u8a18\u306b\u983c\u3063\u3066\u3057\u307e\u3046\u3068\u3001\u5fdc\u7528\u554f\u984c\u306b\u5bfe\u5fdc\u3067\u304d\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u3054\u5b89\u5fc3\u304f\u3060\u3055\u3044\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u306e\u6838\u5fc3\u3067\u3042\u308b\u300cER\u56f3\u300d\u304b\u3089\u59cb\u307e\u308a\u3001\u300c\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u300d\u300c\u5916\u90e8\u30ad\u30fc\u300d\u300c\u53c2\u7167\u6574\u5408\u6027\u5236\u7d04\u300d\u3068\u3044\u3046\u4e00\u9023\u306e\u6d41\u308c\u3092\u3001\u8c4a\u5bcc\u306a\u56f3\u89e3\u3068\u5b9f\u969b\u306b\u52d5\u304b\u305b\u308bSQL\u306e\u5177\u4f53\u4f8b\u3092\u4ea4\u3048\u306a\u304c\u3089\u3001\u4e00\u3064\u3072\u3068\u3064\u4e01\u5be7\u306b\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u307f\u7d42\u3048\u308b\u9803\u306b\u306f\u3001\u70b9\u3068\u70b9\u3060\u3063\u305f\u77e5\u8b58\u304c\u7dda\u3067\u3064\u306a\u304c\u308a\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u69cb\u9020\u304c\u76f4\u611f\u7684\u306b\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<h2>ER\u56f3\u3068\u306f\uff1f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u56f3<\/h2>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u69cb\u7bc9\u3059\u308b\u969b\u3001\u3044\u304d\u306a\u308a\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308a\u59cb\u3081\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u5bb6\u3092\u5efa\u3066\u308b\u524d\u306b\u8a2d\u8a08\u56f3\u304c\u5fc5\u8981\u306a\u306e\u3068\u540c\u3058\u3088\u3046\u306b\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u3082\u300c\u3069\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3092\u300d\u300c\u3069\u306e\u3088\u3046\u306b\u95a2\u9023\u4ed8\u3051\u3066\u300d\u4fdd\u5b58\u3059\u308b\u306e\u304b\u3092\u793a\u3059<strong>\u8a2d\u8a08\u56f3<\/strong>\u304c\u5fc5\u8981\u3067\u3059\u3002\u305d\u306e\u8a2d\u8a08\u56f3\u306e\u5f79\u5272\u3092\u679c\u305f\u3059\u306e\u304c<strong>ER\u56f3\uff08Entity Relationship Diagram\uff09<\/strong>\u3067\u3059\u3002<\/p>\n<p>ER\u56f3\u306f\u3001\u76f4\u8a33\u3059\u308b\u3068\u300c\u5b9f\u4f53\u95a2\u9023\u56f3\u300d\u3068\u306a\u308a\u3001\u305d\u306e\u540d\u306e\u901a\u308a\u30b7\u30b9\u30c6\u30e0\u3067\u6271\u3046\u30c7\u30fc\u30bf\uff08<strong>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3<\/strong>\uff09\u3068\u3001\u305d\u306e\u30c7\u30fc\u30bf\u540c\u58eb\u306e\uff08<strong>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7<\/strong>\uff09\u3092\u53ef\u8996\u5316\u3059\u308b\u305f\u3081\u306e\u56f3\u3067\u3059\u3002\u3053\u306e\u56f3\u3092\u63cf\u304f\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5168\u4f53\u50cf\u304c\u660e\u78ba\u306b\u306a\u308a\u3001\u958b\u767a\u8005\u3084\u8a2d\u8a08\u8005\u306e\u9593\u3067\u8a8d\u8b58\u306e\u30ba\u30ec\u304c\u751f\u307e\u308c\u308b\u306e\u3092\u9632\u304e\u307e\u3059\u3002<\/p>\n<h3>ER\u56f3\u306e\u57fa\u672c\u8981\u7d20\u3092\u899a\u3048\u3088\u3046<\/h3>\n<p>ER\u56f3\u306f\u3001\u4e3b\u306b3\u3064\u306e\u57fa\u672c\u8981\u7d20\u3067\u69cb\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u307e\u305a\u306f\u3053\u306e3\u3064\u3092\u899a\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">\u8981\u7d20<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u610f\u5473<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u56f3\u3067\u306e\u8868\u73fe\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3<\/strong> (Entity)<\/td>\n<td style=\"padding: 8px;\">\u30c7\u30fc\u30bf\u306e\u307e\u3068\u307e\u308a\u3002\u591a\u304f\u306e\u5834\u5408\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u300c\u30c6\u30fc\u30d6\u30eb\u300d\u306b\u76f8\u5f53\u3057\u307e\u3059\u3002<\/td>\n<td style=\"padding: 8px;\">\u56db\u89d2\u5f62 (<code>[ ]<\/code>)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u5c5e\u6027<\/strong> (Attribute)<\/td>\n<td style=\"padding: 8px;\">\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u304c\u6301\u3064\u500b\u3005\u306e\u30c7\u30fc\u30bf\u9805\u76ee\u3002\u300c\u30ab\u30e9\u30e0\u300d\u3084\u300c\u30d5\u30a3\u30fc\u30eb\u30c9\u300d\u306b\u76f8\u5f53\u3057\u307e\u3059\u3002<\/td>\n<td style=\"padding: 8px;\">\u6955\u5186\u5f62\u307e\u305f\u306f\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u5185\u306e\u30ea\u30b9\u30c8<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7<\/strong> (Relationship)<\/td>\n<td style=\"padding: 8px;\">\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\uff08\u30c6\u30fc\u30d6\u30eb\uff09\u540c\u58eb\u306e\u95a2\u4fc2\u6027\u306e\u3053\u3068\u3002<\/td>\n<td style=\"padding: 8px;\">\u7dda (<code>\u2500\u2500<\/code>) \u3084\u3072\u3057\u5f62 (<code>&lt;&gt;<\/code>)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u307e\u305a\u306f\u30a4\u30e1\u30fc\u30b8\u3067\u7406\u89e3\uff1a\u9867\u5ba2\u3068\u6ce8\u6587\u306e\u95a2\u4fc2<\/h3>\n<p>\u8a00\u8449\u3060\u3051\u3067\u306f\u5206\u304b\u308a\u306b\u304f\u3044\u306e\u3067\u3001\u5177\u4f53\u7684\u306a\u4f8b\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u30aa\u30f3\u30e9\u30a4\u30f3\u30b9\u30c8\u30a2\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u8003\u3048\u307e\u3059\u3002\u305d\u3053\u306b\u306f\u300c\u9867\u5ba2\u300d\u306e\u60c5\u5831\u3068\u300c\u6ce8\u6587\u300d\u306e\u60c5\u5831\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u3068\u304d\u3001\u300c1\u4eba\u306e\u9867\u5ba2\u304c\u3001\u8907\u6570\u306e\u6ce8\u6587\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u300d\u3068\u3044\u3046\u95a2\u4fc2\u6027\u304c\u6210\u308a\u7acb\u3061\u307e\u3059\u3002\u3053\u308c\u3092ER\u56f3\u306e\u30a4\u30e1\u30fc\u30b8\u3067\u8868\u3059\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code>[ \u9867\u5ba2 ] \u2500\u2500\u2500&lt; \u6ce8\u6587\u3059\u308b &gt;\u2500\u2500\u2500 [ \u6ce8\u6587 ]<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001ER\u56f3\u306f\u30c7\u30fc\u30bf\uff08\u9867\u5ba2\u3001\u6ce8\u6587\uff09\u3068\u305d\u306e\u95a2\u4fc2\u6027\uff08\u6ce8\u6587\u3059\u308b\uff09\u3092\u30b7\u30f3\u30d7\u30eb\u306b\u8868\u73fe\u3059\u308b\u305f\u3081\u306e\u30c4\u30fc\u30eb\u3067\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u306e\u300c\u95a2\u4fc2\u6027\uff08\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\uff09\u300d\u306b\u3064\u3044\u3066\u3001\u3055\u3089\u306b\u8a73\u3057\u304f\u6398\u308a\u4e0b\u3052\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3068\u306f\uff1f\u8868\u3068\u8868\u3092\u3064\u306a\u3050\u7dda\u306e\u610f\u5473<\/h2>\n<p>ER\u56f3\u3067\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\uff08\u30c6\u30fc\u30d6\u30eb\uff09\u3092\u56db\u89d2\u3067\u63cf\u304d\u307e\u3057\u305f\u304c\u3001\u305d\u308c\u3060\u3051\u3067\u306f\u305f\u3060\u306e\u7bb1\u306e\u96c6\u307e\u308a\u3067\u3059\u3002ER\u56f3\u3067\u6700\u3082\u91cd\u8981\u306a\u306e\u306f\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u540c\u58eb\u3092\u3064\u306a\u3050\u300c<strong>\u7dda<\/strong>\u300d\u3001\u3059\u306a\u308f\u3061<strong>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\uff08\u95a2\u9023\uff09<\/strong>\u3067\u3059\u3002\u3053\u306e\u7dda\u304c\u3001\u300c\u3069\u306e\u30c6\u30fc\u30d6\u30eb\u304c\u3001\u3069\u306e\u30c6\u30fc\u30d6\u30eb\u3068\u3001\u3069\u306e\u3088\u3046\u306b\u95a2\u308f\u308a\u5408\u3046\u306e\u304b\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<p>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u306b\u306f\u3001\u5927\u304d\u304f\u5206\u3051\u3066\u4ee5\u4e0b\u306e3\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306a\u3069\u3067\u3082\u983b\u51fa\u3059\u308b\u3001\u975e\u5e38\u306b\u91cd\u8981\u306a\u6982\u5ff5\u3067\u3059\u3002<\/p>\n<ul>\n<li><strong>\u4e00\u5bfe\u4e00\uff081 to 1\uff09<\/strong>: 1\u3064\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u3001\u76f8\u624b\u306e\u30c6\u30fc\u30d6\u30eb\u306e1\u3064\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u3057\u304b\u5bfe\u5fdc\u3057\u306a\u3044\u95a2\u4fc2\u3002\uff08\u4f8b\uff1a\u300c\u793e\u54e1\u300d\u3068\u300c\u793e\u54e1\u8a73\u7d30\u60c5\u5831\u300d\uff09<\/li>\n<li><strong>\u4e00\u5bfe\u591a\uff081 to N\uff09<\/strong>: 1\u3064\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u3001\u76f8\u624b\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u8907\u6570\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u5bfe\u5fdc\u3059\u308b\u95a2\u4fc2\u3002\uff08\u4f8b\uff1a\u300c\u9867\u5ba2\u300d\u3068\u300c\u6ce8\u6587\u300d\uff09<\/li>\n<li><strong>\u591a\u5bfe\u591a\uff08N to N\uff09<\/strong>: \u4e92\u3044\u306b\u8907\u6570\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u5bfe\u5fdc\u3057\u3042\u3046\u95a2\u4fc2\u3002\uff08\u4f8b\uff1a\u300c\u5b66\u751f\u300d\u3068\u300c\u8b1b\u7fa9\u300d\uff09<\/li>\n<\/ul>\n<p>\u3053\u306e\u4e2d\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u306b\u304a\u3044\u3066\u6700\u3082\u57fa\u672c\u304b\u3064\u983b\u7e41\u306b\u767b\u5834\u3059\u308b\u306e\u304c\u300c<strong>\u4e00\u5bfe\u591a<\/strong>\u300d\u306e\u95a2\u4fc2\u3067\u3059\u3002<\/p>\n<h3>\u4e00\u5bfe\u591a\uff081:N\uff09\u306e\u4ee3\u8868\u4f8b<\/h3>\n<p>\u5148\u307b\u3069\u306e\u4f8b\u3092\u601d\u3044\u51fa\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u300c1\u4eba\u306e\u9867\u5ba2\u304c\u3001\u8907\u6570\u306e\u6ce8\u6587\u5c65\u6b74\u3092\u6301\u3064\u300d\u3068\u3044\u3046\u69cb\u9020\u306f\u3001\u307e\u3055\u306b\u300c\u4e00\u5bfe\u591a\u300d\u306e\u5178\u578b\u4f8b\u3067\u3059\u3002<\/p>\n<ul>\n<li><strong><code>\u9867\u5ba2<\/code>\u30c6\u30fc\u30d6\u30eb<\/strong>: 1\u4eba\u306e\u9867\u5ba2\u306e\u60c5\u5831\u3092\u6301\u3064\u300c\u89aa\u300d\u306e\u5f79\u5272\u3092\u679c\u305f\u3057\u307e\u3059\u3002\u3053\u308c\u3092<strong>\u89aa\u30c6\u30fc\u30d6\u30eb<\/strong>\u3068\u547c\u3073\u307e\u3059\u3002<\/li>\n<li><strong><code>\u6ce8\u6587<\/code>\u30c6\u30fc\u30d6\u30eb<\/strong>: \u8907\u6570\u306e\u6ce8\u6587\u60c5\u5831\u304c\u683c\u7d0d\u3055\u308c\u308b\u300c\u5b50\u300d\u306e\u5f79\u5272\u3092\u679c\u305f\u3057\u307e\u3059\u3002\u3053\u308c\u3092<strong>\u5b50\u30c6\u30fc\u30d6\u30eb<\/strong>\u3068\u547c\u3073\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>ER\u56f3\u4e0a\u306e <code>[\u9867\u5ba2] \u2500\u2500\u2500 [\u6ce8\u6587]<\/code> \u3068\u3044\u30461\u672c\u306e\u7dda\u306f\u3001\u3053\u306e\u300c\u89aa\u5b50\u306e\u95a2\u4fc2\u6027\u300d\u3092\u793a\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u3002<\/p>\n<h3>SQL\u3067\u8868\u3059\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3<\/h3>\n<p>\u3067\u306f\u3001\u3053\u306eER\u56f3\u4e0a\u306e\u300c\u7dda\u300d\u306f\u3001\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u306f\u3069\u306e\u3088\u3046\u306b\u8868\u73fe\u3055\u308c\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u308c\u304c<strong>SQL<\/strong>\u306e<code>CREATE TABLE<\/code>\u6587\u3067\u3059\u3002ER\u56f3\u3067\u5b9a\u7fa9\u3057\u305f\u95a2\u4fc2\u6027\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u969b\u306e\u300c<strong>\u5236\u7d04<\/strong>\u300d\u3068\u3057\u3066\u30b3\u30fc\u30c9\u306b\u843d\u3068\u3057\u8fbc\u307e\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\n-- \u89aa\u30c6\u30fc\u30d6\u30eb\nCREATE TABLE customers (\n  customer_id INT PRIMARY KEY,\n  name VARCHAR(50)\n);\n\n-- \u5b50\u30c6\u30fc\u30d6\u30eb\nCREATE TABLE orders (\n  order_id INT PRIMARY KEY,\n  customer_id INT,\n  product_name VARCHAR(100),\n  FOREIGN KEY (customer_id) REFERENCES customers(customer_id)\n);\n<\/code><\/pre>\n<p>\u3053\u306eSQL\u6587\u306e\u6700\u5f8c\u306e\u884c <code>FOREIGN KEY (customer_id) REFERENCES customers(customer_id)<\/code> \u304c\u3001\u307e\u3055\u306b <code>customers<\/code> \u30c6\u30fc\u30d6\u30eb\u3068 <code>orders<\/code> \u30c6\u30fc\u30d6\u30eb\u3092\u7e4b\u3050\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u90e8\u5206\u3067\u3059\u3002\u3053\u306e <code>FOREIGN KEY<\/code> \u3053\u305d\u304c\u3001\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u89e3\u8aac\u3059\u308b\u300c<strong>\u5916\u90e8\u30ad\u30fc<\/strong>\u300d\u306e\u6b63\u4f53\u3067\u3059\u3002<\/p>\n<h2>\u4e3b\u30ad\u30fc\u3068\u5916\u90e8\u30ad\u30fc\u306e\u9055\u3044\u3092\u660e\u78ba\u306b\u7406\u89e3\u3057\u3088\u3046<\/h2>\n<p>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092SQL\u3067\u8868\u73fe\u3059\u308b\u969b\u306b <code>PRIMARY KEY<\/code> \u3068 <code>FOREIGN KEY<\/code> \u3068\u3044\u30462\u3064\u306e\u30ad\u30fc\u30ef\u30fc\u30c9\u304c\u767b\u5834\u3057\u307e\u3057\u305f\u3002\u3053\u306e2\u3064\u306e\u300c\u30ad\u30fc\uff08\u9375\uff09\u300d\u306e\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u3001\u30c6\u30fc\u30d6\u30eb\u306e\u89aa\u5b50\u95a2\u4fc2\u3092\u628a\u63e1\u3059\u308b\u4e0a\u3067\u6975\u3081\u3066\u91cd\u8981\u3067\u3059\u3002<\/p>\n<p>\u4e00\u8a00\u3067\u3044\u3046\u3068\u3001<strong>\u4e3b\u30ad\u30fc\u306f\u300c\u81ea\u5206\u81ea\u8eab\u3092\u7279\u5b9a\u3059\u308b\u305f\u3081\u306e\u9375\u300d<\/strong>\u3001<strong>\u5916\u90e8\u30ad\u30fc\u306f\u300c\u76f8\u624b\uff08\u89aa\uff09\u3092\u6307\u3057\u793a\u3059\u305f\u3081\u306e\u9375\u300d<\/strong>\u3067\u3059\u3002<\/p>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">\u7528\u8a9e<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u610f\u5473<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u4e3b\u30ad\u30fc<\/strong> (Primary Key, PK)<\/td>\n<td style=\"padding: 8px;\">\u30c6\u30fc\u30d6\u30eb\u5185\u3067\u3001\u3042\u308b1\u884c\u306e\u30c7\u30fc\u30bf\u3092<strong>\u4e00\u610f\u306b\uff08\u91cd\u8907\u306a\u304f\uff09\u8b58\u5225\u3059\u308b\u305f\u3081<\/strong>\u306e\u30ab\u30e9\u30e0\u3002<code>NULL<\/code> (\u7a7a) \u306f\u8a31\u3055\u308c\u307e\u305b\u3093\u3002<\/td>\n<td style=\"padding: 8px;\">\u9867\u5ba2\u30c6\u30fc\u30d6\u30eb\u306e <code>customer_id<\/code>\u3001\u6ce8\u6587\u30c6\u30fc\u30d6\u30eb\u306e <code>order_id<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u5916\u90e8\u30ad\u30fc<\/strong> (Foreign Key, FK)<\/td>\n<td style=\"padding: 8px;\"><strong>\u4ed6\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u3092\u53c2\u7167\u3059\u308b<\/strong>\u305f\u3081\u306e\u30ab\u30e9\u30e0\u3002\u30c6\u30fc\u30d6\u30eb\u540c\u58eb\u3092\u95a2\u9023\u4ed8\u3051\u308b\u300c\u6a4b\u6e21\u3057\u5f79\u300d\u3092\u62c5\u3044\u307e\u3059\u3002<\/td>\n<td style=\"padding: 8px;\">\u6ce8\u6587\u30c6\u30fc\u30d6\u30eb\u306e <code>customer_id<\/code> \uff08\u9867\u5ba2\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u3092\u53c2\u7167\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>\u6ce8\u6587<\/code>\u30c6\u30fc\u30d6\u30eb\u306e <code>customer_id<\/code> \u306f\u3001\u305d\u308c\u5358\u4f53\u3067\u306f\u300c\u6ce8\u6587\u300d\u3092\u4e00\u610f\u306b\u7279\u5b9a\u3067\u304d\u307e\u305b\u3093\u304c\u3001\u300c\u3069\u306e\u9867\u5ba2\u306b\u3088\u308b\u6ce8\u6587\u306a\u306e\u304b\u300d\u3092\u793a\u3059\u305f\u3081\u306b\u3001\u89aa\u3067\u3042\u308b <code>\u9867\u5ba2<\/code> \u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc <code>customer_id<\/code> \u3092\u53c2\u7167\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u304c\u5916\u90e8\u30ad\u30fc\u306e\u5f79\u5272\u3067\u3059\u3002<\/p>\n<h3>ER\u56f3\u3067\u306e\u898b\u5206\u3051\u65b9<\/h3>\n<p>ER\u56f3\u306e\u8a18\u6cd5\u306f\u3044\u304f\u3064\u304b\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u591a\u304f\u306e\u5834\u5408\u3001\u4e3b\u30ad\u30fc\u3068\u5916\u90e8\u30ad\u30fc\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u660e\u8a18\u3055\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li><strong>\u4e3b\u30ad\u30fc (PK)<\/strong>: \u30ab\u30e9\u30e0\u540d\u306b\u4e0b\u7dda\u304c\u5f15\u304b\u308c\u3066\u3044\u305f\u308a\u3001<code>(PK)<\/code> \u3068\u3044\u3046\u5370\u304c\u4ed8\u3044\u3066\u3044\u307e\u3059\u3002<\/li>\n<li><strong>\u5916\u90e8\u30ad\u30fc (FK)<\/strong>: \u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u3068\u7dda\u3067\u7d50\u3070\u308c\u3066\u304a\u308a\u3001<code>(FK)<\/code> \u3068\u5370\u304c\u4ed8\u3044\u3066\u3044\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<\/li>\n<\/ul>\n<pre><code>\n[ Customer ]\n----------\n<u>customer_id (PK)<\/u>\nname\n\n   \u2191\n   \u2502 (\u53c2\u7167)\n   \u2502\n[ Order ]\n----------\n<u>order_id (PK)<\/u>\ncustomer_id (FK)\nproduct_name\n<\/code><\/pre>\n<p>\u3053\u306e\u56f3\u3092\u898b\u308b\u3060\u3051\u3067\u3001\u300cOrder\u30c6\u30fc\u30d6\u30eb\u306ecustomer_id\u306f\u3001Customer\u30c6\u30fc\u30d6\u30eb\u306ecustomer_id\u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u5916\u90e8\u30ad\u30fc\u3060\u306a\u300d\u3068\u3044\u3046\u3053\u3068\u304c\u4e00\u76ee\u3067\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<h2>\u5916\u90e8\u30ad\u30fc\u3068\u306f\uff1f\u89aa\u5b50\u95a2\u4fc2\u3092\u3064\u306a\u3050\u201c\u6a4b\u201d\u306e\u5f79\u5272<\/h2>\n<p>\u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u3001\u5916\u90e8\u30ad\u30fc\u306f\u300c\u4ed6\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u3092\u53c2\u7167\u3059\u308b\u30ab\u30e9\u30e0\u300d\u3060\u3068\u8aac\u660e\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u9593\u306b\u89aa\u5b50\u95a2\u4fc2\u3092\u7bc9\u304d\u3001\u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u3092\u4fdd\u3064\u305f\u3081\u306e\u975e\u5e38\u306b\u91cd\u8981\u306a\u4ed5\u7d44\u307f\u3067\u3059\u3002\u5916\u90e8\u30ad\u30fc\u306f\u3001\u89aa\u3068\u5b50\u3092\u3064\u306a\u3050<strong>\u201c\u6a4b\u201d<\/strong>\u306e\u3088\u3046\u306a\u5f79\u5272\u3092\u679c\u305f\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e \u201c\u6a4b\u201d \u304c\u3042\u308b\u304a\u304b\u3052\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f<strong>\u300c\u5b58\u5728\u3057\u306a\u3044\u89aa\u300d\u3092\u6301\u3064\u300c\u5b64\u7acb\u3057\u305f\u5b50\u300d\u30c7\u30fc\u30bf<\/strong>\u304c\u751f\u307e\u308c\u308b\u306e\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u9867\u5ba2\u300d\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3057\u306a\u3044 <code>customer_id<\/code> \u3092\u6301\u3064\u300c\u6ce8\u6587\u300d\u30c7\u30fc\u30bf\u304c\u767b\u9332\u3067\u304d\u3066\u3057\u307e\u3046\u3068\u3001\u305d\u306e\u6ce8\u6587\u304c\u8ab0\u304b\u3089\u306e\u3082\u306e\u304b\u5206\u304b\u3089\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u4fe1\u983c\u6027\u3092\u640d\u306a\u3046\u81f4\u547d\u7684\u306a\u554f\u984c\u3067\u3059\u3002\u5916\u90e8\u30ad\u30fc\u306f\u3001\u3053\u306e\u3088\u3046\u306a\u4e0d\u6b63\u306a\u30c7\u30fc\u30bf\u304c\u767b\u9332\u3055\u308c\u308b\u306e\u3092\u9632\u3050<strong>\u9580\u756a<\/strong>\u306e\u3088\u3046\u306a\u5f79\u5272\u3082\u62c5\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u3002\u3053\u306e\u300c\u30c7\u30fc\u30bf\u306e\u77db\u76fe\u3092\u9632\u3050\u4ed5\u7d44\u307f\u300d\u306e\u3053\u3068\u3092<strong>\u5916\u90e8\u30ad\u30fc\u5236\u7d04<\/strong>\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<h3>\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u57fa\u672c\u69cb\u6587<\/h3>\n<p>\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306f\u3001\u5b50\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b <code>CREATE TABLE<\/code> \u6587\u306e\u4e2d\u3067\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u5177\u4f53\u7684\u306b\u306f\u3001<code>FOREIGN KEY<\/code> \u53e5\u3068 <code>REFERENCES<\/code> \u53e5\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\nFOREIGN KEY (\u81ea\u30c6\u30fc\u30d6\u30eb\u306e\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u540d) REFERENCES \u89aa\u30c6\u30fc\u30d6\u30eb\u540d(\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u30ab\u30e9\u30e0\u540d);\n<\/code><\/pre>\n<p>\u518d\u63b2\u306b\u306a\u308a\u307e\u3059\u304c\u3001<code>orders<\/code> \u30c6\u30fc\u30d6\u30eb\u306eSQL\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code class=\"language-sql\">\nCREATE TABLE orders (\n  order_id INT PRIMARY KEY,\n  customer_id INT, -- \u3053\u306e\u30ab\u30e9\u30e0\u304c\u5916\u90e8\u30ad\u30fc\u306b\u306a\u308b\n  product_name VARCHAR(100),\n  \n  -- \u2193\u3053\u3053\u304c\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u5b9a\u7fa9\u2193\n  FOREIGN KEY (customer_id) REFERENCES customers(customer_id)\n);\n<\/code><\/pre>\n<p>\u3053\u306e\u4e00\u884c\u3092\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3067\u3001<code>orders<\/code> \u30c6\u30fc\u30d6\u30eb\u306e <code>customer_id<\/code> \u306b\u306f\u3001<code>customers<\/code> \u30c6\u30fc\u30d6\u30eb\u306e <code>customer_id<\/code> \u306b\u5b58\u5728\u3059\u308b\u5024\u3057\u304b\u767b\u9332\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30c7\u30fc\u30bf\u306e\u4e00\u8cab\u6027\u304c\u4fdd\u8a3c\u3055\u308c\u308b\u306e\u3067\u3059\u3002<\/p>\n<h2>\u53c2\u7167\u6574\u5408\u6027\u5236\u7d04\u3068\u306f\uff1f\u524a\u9664\u3084\u66f4\u65b0\u6642\u306e\u30eb\u30fc\u30eb\u3092\u6c7a\u3081\u308b\u4ed5\u7d44\u307f<\/h2>\n<p>\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u300c\u5b58\u5728\u3057\u306a\u3044\u89aa\u300d\u3092\u53c2\u7167\u3059\u308b\u30c7\u30fc\u30bf\u306f\u4f5c\u308c\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u3002\u3057\u304b\u3057\u3001\u3053\u3053\u3067\u65b0\u305f\u306a\u7591\u554f\u304c\u751f\u307e\u308c\u307e\u3059\u3002\u300c<strong>\u3059\u3067\u306b\u5b50\u30c7\u30fc\u30bf\u304b\u3089\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u89aa\u30c7\u30fc\u30bf\u3092\u3001\u524a\u9664\u3057\u305f\u308a\u66f4\u65b0\u3057\u305f\u308a\u3057\u305f\u3044\u5834\u5408\u306f\u3069\u3046\u306a\u308b\u306e\u304b\uff1f<\/strong>\u300d\u3068\u3044\u3046\u554f\u984c\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u3042\u308b\u9867\u5ba2\u304c\u9000\u4f1a\u3057\u305f\u3068\u3057\u307e\u3059\u3002\u3053\u306e\u3068\u304d\u3001\u305d\u306e\u9867\u5ba2\u306e\u6ce8\u6587\u5c65\u6b74\uff08\u5b50\u30c7\u30fc\u30bf\uff09\u3092\u3069\u3046\u6271\u3046\u3079\u304d\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<ol>\n<li>\u9867\u5ba2\u60c5\u5831\u3068\u4e00\u7dd2\u306b\u3001\u904e\u53bb\u306e\u6ce8\u6587\u5c65\u6b74\u3082\u3059\u3079\u3066\u524a\u9664\u3059\u308b\u3079\u304d\u304b\uff1f<\/li>\n<li>\u6ce8\u6587\u5c65\u6b74\u306f\u6b8b\u3057\u3064\u3064\u3001\u8ab0\u304b\u3089\u306e\u6ce8\u6587\u3060\u3063\u305f\u304b\u3068\u3044\u3046\u60c5\u5831\u3060\u3051\u3092\u6d88\u3059\u3079\u304d\u304b\uff1f<\/li>\n<li>\u305d\u308c\u3068\u3082\u3001\u6ce8\u6587\u5c65\u6b74\u304c\u6b8b\u3063\u3066\u3044\u308b\u9650\u308a\u3001\u9867\u5ba2\u60c5\u5831\u306e\u524a\u9664\u306f\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3079\u304d\u304b\uff1f<\/li>\n<\/ol>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u304c\u5909\u66f4\uff08<code>UPDATE<\/code>\uff09\u3055\u308c\u305f\u308a\u524a\u9664\uff08<code>DELETE<\/code>\uff09\u3055\u308c\u305f\u308a\u3057\u305f\u969b\u306b\u3001\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u306e\u4e00\u8cab\u6027\u3092\u4fdd\u3064\u305f\u3081\u306e\u30eb\u30fc\u30eb\u3092\u5b9a\u7fa9\u3059\u308b\u4ed5\u7d44\u307f\u304c\u300c<strong>\u53c2\u7167\u6574\u5408\u6027\u5236\u7d04<\/strong>\u300d\u3067\u3059\u3002\u3053\u306e\u30eb\u30fc\u30eb\u306f\u3001\u5916\u90e8\u30ad\u30fc\u3092\u5b9a\u7fa9\u3059\u308b\u969b\u306b <code>ON DELETE<\/code> \u3084 <code>ON UPDATE<\/code> \u3068\u3044\u3046\u53e5\u3092\u4f7f\u3063\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h3>\u53c2\u7167\u52d5\u4f5c\u306e\u7a2e\u985e\u4e00\u89a7<\/h3>\n<p>\u5177\u4f53\u7684\u306b\u3069\u306e\u3088\u3046\u306a\u52d5\u4f5c\u3092\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u304b\u3001\u4ee3\u8868\u7684\u306a\u3082\u306e\u3092\u4ee5\u4e0b\u306e\u8868\u306b\u307e\u3068\u3081\u307e\u3057\u305f\u3002\u7279\u306b <code>CASCADE<\/code> \u3068 <code>RESTRICT<\/code> \u306f\u3001\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306e\u5348\u5f8c\u554f\u984c\u3067\u3082\u983b\u51fa\u3059\u308b\u91cd\u8981\u306a\u9078\u629e\u80a2\u3067\u3059\u3002<\/p>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">\u52d5\u4f5c<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u610f\u5473<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u6319\u52d5\u30a4\u30e1\u30fc\u30b8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\"><strong><code>CASCADE<\/code><\/strong><\/td>\n<td style=\"padding: 8px;\">\u89aa\u304c\u524a\u9664\/\u66f4\u65b0\u3055\u308c\u305f\u3089\u3001<strong>\u5b50\u3082\u9023\u52d5\u3057\u3066<\/strong>\u524a\u9664\/\u66f4\u65b0\u3055\u308c\u308b\u3002\uff08\u6edd\u306e\u3088\u3046\u306b\u9023\u9396\u3059\u308b\uff09<\/td>\n<td style=\"padding: 8px;\">\u9867\u5ba2\u3092\u524a\u9664\u3057\u305f\u3089\u3001\u305d\u306e\u9867\u5ba2\u306e\u6ce8\u6587\u3082\u3059\u3079\u3066\u81ea\u52d5\u3067\u6d88\u3048\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong><code>SET NULL<\/code><\/strong><\/td>\n<td style=\"padding: 8px;\">\u89aa\u304c\u524a\u9664\/\u66f4\u65b0\u3055\u308c\u305f\u3089\u3001\u5b50\u306e\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u3092 <strong><code>NULL<\/code> \u306b<\/strong>\u3059\u308b\u3002<\/td>\n<td style=\"padding: 8px;\">\u9867\u5ba2\u3092\u524a\u9664\u3057\u3066\u3082\u6ce8\u6587\u5c65\u6b74\u306f\u6b8b\u308b\u304c\u3001\u8ab0\u306e\u6ce8\u6587\u304b\u3092\u793a\u3059ID\u304c\u7a7a\u306b\u306a\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong><code>RESTRICT<\/code><\/strong> \/ <strong><code>NO ACTION<\/code><\/strong><\/td>\n<td style=\"padding: 8px;\">\u5b50\u30c7\u30fc\u30bf\u304c\u6b8b\u3063\u3066\u3044\u308b\u9650\u308a\u3001\u89aa\u306e\u524a\u9664\/\u66f4\u65b0\u3092 <strong>\u7981\u6b62<\/strong>\u3059\u308b\u3002<\/td>\n<td style=\"padding: 8px;\">\u6ce8\u6587\u5c65\u6b74\u304c1\u4ef6\u3067\u3082\u6b8b\u3063\u3066\u3044\u308b\u9867\u5ba2\u306f\u3001\u9000\u4f1a\u51e6\u7406\uff08\u524a\u9664\uff09\u304c\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong><code>SET DEFAULT<\/code><\/strong><\/td>\n<td style=\"padding: 8px;\">\u89aa\u304c\u524a\u9664\/\u66f4\u65b0\u3055\u308c\u305f\u3089\u3001\u5b50\u306e\u5916\u90e8\u30ad\u30fc\u3092 <strong>\u3042\u3089\u304b\u3058\u3081\u6c7a\u3081\u3089\u308c\u305f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306b<\/strong>\u3059\u308b\u3002<\/td>\n<td style=\"padding: 8px;\">\u9000\u4f1a\u3057\u305f\u9867\u5ba2\u306e\u6ce8\u6587\u306f\u3001\u3059\u3079\u3066\u300c\u4e0d\u660e\u9867\u5ba2(ID:999)\u300d\u306a\u3069\u306e\u7279\u5b9aID\u306b\u4ed8\u3051\u66ff\u3048\u308b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u308c\u3089\u306e\u52d5\u4f5c\u3092\u9069\u5207\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u306e\u77db\u76fe\u3092\u9632\u304e\u306a\u304c\u3089\u3001\u696d\u52d9\u306e\u30eb\u30fc\u30eb\u306b\u5408\u308f\u305b\u305f\u67d4\u8edf\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u8a2d\u8a08\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u52d5\u4f5c\u3092SQL\u3067\u5b9f\u969b\u306b\u4f53\u9a13\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u3010SQL\u5b9f\u4f8b\u30114\u3064\u306e\u53c2\u7167\u6574\u5408\u6027\u5236\u7d04\u3092\u4f53\u9a13\u3057\u3088\u3046<\/h2>\n<p>\u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u5b66\u3093\u30604\u3064\u306e\u53c2\u7167\u52d5\u4f5c\uff08<code>CASCADE<\/code>, <code>SET NULL<\/code>, <code>RESTRICT<\/code>, <code>SET DEFAULT<\/code>\uff09\u304c\u3001\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u3069\u306e\u3088\u3046\u306b\u632f\u308b\u821e\u3046\u306e\u304b\u3092SQL\u3092\u52d5\u304b\u3057\u306a\u304c\u3089\u4f53\u9a13\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u767e\u805e\u306f\u4e00\u898b\u306b\u5982\u304b\u305a\u3067\u3059\u3002<\/p>\n<h3>\u30b5\u30f3\u30d7\u30eb\u6e96\u5099<\/h3>\n<p>\u307e\u305a\u3001\u89aa\u3068\u306a\u308b <code>customers<\/code> \u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u30013\u4eba\u306e\u9867\u5ba2\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u3053\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u5404\u30d1\u30bf\u30fc\u30f3\u306e\u53c2\u7167\u5143\u3068\u3057\u3066\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\n-- \u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\nCREATE TABLE customers (\n  customer_id INT PRIMARY KEY,\n  name VARCHAR(50)\n);\n\n-- \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u306e\u633f\u5165\nINSERT INTO customers VALUES (1, '\u7530\u4e2d\u592a\u90ce'), (2, '\u4f50\u85e4\u82b1\u5b50'), (3, '\u5c71\u7530\u4e00\u90ce');\n<\/code><\/pre>\n<h3>\u2460 ON DELETE CASCADE\uff08\u89aa\u3092\u6d88\u3057\u305f\u3089\u5b50\u3082\u524a\u9664\uff09<\/h3>\n<p><code>ON DELETE CASCADE<\/code> \u306f\u3001\u89aa\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3059\u308b\u3068\u3001\u305d\u306e\u89aa\u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u5b50\u30ec\u30b3\u30fc\u30c9\u3082\u81ea\u52d5\u7684\u306b\u524a\u9664\uff08\u9023\u9396\u524a\u9664\uff09\u3055\u308c\u308b\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\n-- CASCADE\u8a2d\u5b9a\u3092\u6301\u3064\u5b50\u30c6\u30fc\u30d6\u30eb\nCREATE TABLE orders_cascade (\n  order_id INT PRIMARY KEY,\n  customer_id INT,\n  product_name VARCHAR(100),\n  FOREIGN KEY (customer_id)\n    REFERENCES customers(customer_id)\n    ON DELETE CASCADE  -- \u3053\u306e\u90e8\u5206\u304cCASCADE\u8a2d\u5b9a\n);\n\n-- \u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u767b\u9332\nINSERT INTO orders_cascade VALUES (101, 1, '\u5546\u54c1A'), (102, 2, '\u5546\u54c1B');\n\n-- customer_id = 1 \u306e\u7530\u4e2d\u3055\u3093\u3092\u524a\u9664\u3057\u3066\u307f\u308b\nDELETE FROM customers WHERE customer_id = 1;\n<\/code><\/pre>\n<p><strong>\u7d50\u679c<\/strong>\uff1a\u3053\u306e<code>DELETE<\/code>\u6587\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001<code>customers<\/code>\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u7530\u4e2d\u3055\u3093\u306e\u30c7\u30fc\u30bf\u304c\u6d88\u3048\u308b\u3060\u3051\u3067\u306a\u304f\u3001<code>orders_cascade<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u3042\u3063\u305f<code>order_id = 101<\/code>\u306e\u6ce8\u6587\u30c7\u30fc\u30bf\u3082<strong>\u81ea\u52d5\u7684\u306b\u524a\u9664\u3055\u308c\u307e\u3059<\/strong>\u3002<\/p>\n<h3>\u2461 ON DELETE SET NULL\uff08\u5916\u90e8\u30ad\u30fc\u3092NULL\u306b\uff09<\/h3>\n<p><code>ON DELETE SET NULL<\/code> \u306f\u3001\u89aa\u30ec\u30b3\u30fc\u30c9\u304c\u524a\u9664\u3055\u308c\u305f\u3068\u304d\u3001\u5b50\u30ec\u30b3\u30fc\u30c9\u306f\u524a\u9664\u305b\u305a\u3001\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u306e\u5024\u3060\u3051\u3092 <code>NULL<\/code> \u306b\u5909\u66f4\u3059\u308b\u8a2d\u5b9a\u3067\u3059\u3002<br \/>\u203b\u3053\u306e\u8a2d\u5b9a\u3092\u4f7f\u3046\u306b\u306f\u3001\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u304c<code>NULL<\/code>\u5024\u3092\u8a31\u53ef\u3057\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\n-- SET NULL\u8a2d\u5b9a\u3092\u6301\u3064\u5b50\u30c6\u30fc\u30d6\u30eb\nCREATE TABLE orders_setnull (\n  order_id INT PRIMARY KEY,\n  customer_id INT, -- NULL\u3092\u8a31\u5bb9\n  product_name VARCHAR(100),\n  FOREIGN KEY (customer_id)\n    REFERENCES customers(customer_id)\n    ON DELETE SET NULL -- \u3053\u306e\u90e8\u5206\u304cSET NULL\u8a2d\u5b9a\n);\n\n-- \u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u767b\u9332\nINSERT INTO orders_setnull VALUES (201, 1, '\u5546\u54c1A'), (202, 2, '\u5546\u54c1B');\n\n-- customer_id = 1 \u306e\u7530\u4e2d\u3055\u3093\u3092\u524a\u9664\u3057\u3066\u307f\u308b\nDELETE FROM customers WHERE customer_id = 1;\n<\/code><\/pre>\n<p><strong>\u7d50\u679c<\/strong>\uff1a<code>customers<\/code>\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u7530\u4e2d\u3055\u3093\u306e\u30c7\u30fc\u30bf\u306f\u524a\u9664\u3055\u308c\u307e\u3059\u304c\u3001<code>orders_setnull<\/code>\u30c6\u30fc\u30d6\u30eb\u306e<code>order_id = 201<\/code>\u306e\u30ec\u30b3\u30fc\u30c9\u306f\u6b8b\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u305d\u306e\u30ec\u30b3\u30fc\u30c9\u306e<strong><code>customer_id<\/code>\u30ab\u30e9\u30e0\u306e\u5024\u304c<code>NULL<\/code>\u306b\u5909\u66f4\u3055\u308c\u307e\u3059<\/strong>\u3002\u300c\u6ce8\u6587\u5c65\u6b74\u306f\u6b8b\u3057\u305f\u3044\u304c\u3001\u9000\u4f1a\u3057\u305f\u9867\u5ba2\u3068\u306e\u7d10\u4ed8\u3051\u306f\u5207\u308a\u305f\u3044\u300d\u5834\u5408\u306b\u6709\u52b9\u3067\u3059\u3002<\/p>\n<h3>\u2462 ON DELETE RESTRICT \/ NO ACTION\uff08\u89aa\u524a\u9664\u3092\u7981\u6b62\uff09<\/h3>\n<p><code>ON DELETE RESTRICT<\/code>\uff08\u307e\u305f\u306f<code>NO ACTION<\/code>\uff09\u306f\u3001\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u30ec\u30b3\u30fc\u30c9\u304c1\u4ef6\u3067\u3082\u5b58\u5728\u3059\u308b\u9650\u308a\u3001\u89aa\u30ec\u30b3\u30fc\u30c9\u306e\u524a\u9664\u3092<strong>\u30a8\u30e9\u30fc\u306b\u3057\u3066\u7981\u6b62<\/strong>\u3059\u308b\u3001\u6700\u3082\u5b89\u5168\u306a\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\n-- RESTRICT\u8a2d\u5b9a\u3092\u6301\u3064\u5b50\u30c6\u30fc\u30d6\u30eb\nCREATE TABLE orders_restrict (\n  order_id INT PRIMARY KEY,\n  customer_id INT,\n  product_name VARCHAR(100),\n  FOREIGN KEY (customer_id)\n    REFERENCES customers(customer_id)\n    ON DELETE RESTRICT -- \u3053\u306e\u90e8\u5206\u304cRESTRICT\u8a2d\u5b9a\n);\n\n-- \u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u767b\u9332\nINSERT INTO orders_restrict VALUES (301, 2, '\u5546\u54c1B');\n\n-- customer_id = 2 \u306e\u4f50\u85e4\u3055\u3093\u3092\u524a\u9664\u3057\u3066\u307f\u308b\nDELETE FROM customers WHERE customer_id = 2;\n<\/code><\/pre>\n<p><strong>\u7d50\u679c<\/strong>\uff1a\u3053\u306e<code>DELETE<\/code>\u6587\u3092\u5b9f\u884c\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u300c\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306b\u9055\u53cd\u3057\u3066\u3044\u307e\u3059\u300d\u3068\u3044\u3046<strong>\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3001\u524a\u9664\u306f\u5931\u6557\u3057\u307e\u3059<\/strong>\u3002<code>orders_restrict<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u4f50\u85e4\u3055\u3093\u306e\u6ce8\u6587\u30c7\u30fc\u30bf\u304c\u6b8b\u3063\u3066\u3044\u308b\u305f\u3081\u3067\u3059\u3002\u4f50\u85e4\u3055\u3093\u3092\u524a\u9664\u3059\u308b\u306b\u306f\u3001\u5148\u306b\u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u2463 ON DELETE SET DEFAULT\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306b\u7f6e\u304d\u63db\u3048\u308b\uff09<\/h3>\n<p><code>ON DELETE SET DEFAULT<\/code> \u306f\u3001\u89aa\u30ec\u30b3\u30fc\u30c9\u304c\u524a\u9664\u3055\u308c\u305f\u3068\u304d\u3001\u5b50\u306e\u5916\u90e8\u30ad\u30fc\u3092\u3042\u3089\u304b\u3058\u3081\u6307\u5b9a\u3057\u305f<code>DEFAULT<\/code>\u5024\u306b\u7f6e\u304d\u63db\u3048\u308b\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">\n-- SET DEFAULT\u8a2d\u5b9a\u3092\u6301\u3064\u5b50\u30c6\u30fc\u30d6\u30eb\nCREATE TABLE orders_setdefault (\n  order_id INT PRIMARY KEY,\n  customer_id INT DEFAULT 3, -- \u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u5c71\u7530\u3055\u3093(ID:3)\u306b\u8a2d\u5b9a\n  product_name VARCHAR(100),\n  FOREIGN KEY (customer_id)\n    REFERENCES customers(customer_id)\n    ON DELETE SET DEFAULT -- \u3053\u306e\u90e8\u5206\u304cSET DEFAULT\u8a2d\u5b9a\n);\n\n-- \u6ce8\u6587\u30c7\u30fc\u30bf\u3092\u767b\u9332\nINSERT INTO orders_setdefault VALUES (401, 1, '\u5546\u54c1A');\n\n-- customer_id = 1 \u306e\u7530\u4e2d\u3055\u3093\u3092\u524a\u9664\u3057\u3066\u307f\u308b\nDELETE FROM customers WHERE customer_id = 1;\n<\/code><\/pre>\n<p><strong>\u7d50\u679c<\/strong>\uff1a\u7530\u4e2d\u3055\u3093\u306e\u30c7\u30fc\u30bf\u304c\u524a\u9664\u3055\u308c\u308b\u3068\u3001<code>orders_setdefault<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u3042\u3063\u305f\u6ce8\u6587\uff08<code>order_id = 401<\/code>\uff09\u306e<strong><code>customer_id<\/code>\u304c\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3067\u3042\u308b<code>3<\/code>\uff08\u5c71\u7530\u3055\u3093\uff09\u306b\u81ea\u52d5\u3067\u7f6e\u304d\u63db\u308f\u308a\u307e\u3059<\/strong>\u3002\u9000\u4f1a\u8005\u306e\u62c5\u5f53\u3092\u7279\u5b9a\u306e\u30e6\u30fc\u30b6\u30fc\u306b\u5f15\u304d\u7d99\u3050\u3001\u3068\u3044\u3063\u305f\u696d\u52d9\u3067\u5229\u7528\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<h2>ER\u56f3\u3068\u5916\u90e8\u30ad\u30fc\u306e\u95a2\u4fc2\u3092\u307e\u3068\u3081\u3066\u7406\u89e3\u2502\u5fdc\u7528\u60c5\u5831 \u5348\u5f8c\u8a66\u9a13\u306e\u57fa\u790e<\/h2>\n<p>\u3053\u3053\u307e\u3067\u5b66\u3093\u3067\u304d\u305f\u77e5\u8b58\u3092\u7e4b\u304e\u5408\u308f\u305b\u3001ER\u56f3\u3068\u5916\u90e8\u30ad\u30fc\u306e\u95a2\u4fc2\u6027\u3092\u4e00\u679a\u306e\u7d75\u3068\u3057\u3066\u7406\u89e3\u3057\u307e\u3057\u3087\u3046\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u3001\u7279\u306b\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306e\u5348\u5f8c\u554f\u984c\u306a\u3069\u3067\u306f\u3001\u3053\u306e\u5168\u4f53\u50cf\u3092\u628a\u63e1\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u304c\u554f\u308f\u308c\u307e\u3059\u3002<\/p>\n<p>\u7d50\u8ad6\u304b\u3089\u8a00\u3046\u3068\u3001<strong>ER\u56f3\u306b\u63cf\u304b\u308c\u308b\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u300c\u7dda\u300d\u306e\u6b63\u4f53\u306f\u3001SQL\u306b\u304a\u3051\u308b\u300c\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u300d<\/strong>\u3067\u3059\u3002<\/p>\n<p>\u8a2d\u8a08\u306e\u601d\u8003\u30d7\u30ed\u30bb\u30b9\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li><strong>ER\u56f3\u3067\u95a2\u4fc2\u6027\u3092\u5b9a\u7fa9\u3059\u308b<\/strong>:<br \/>\n    \u307e\u305a\u3001\u6982\u5ff5\u8a2d\u8a08\u306e\u6bb5\u968e\u3067\u300c\u9867\u5ba2\u3068\u6ce8\u6587\u306f\u4e00\u5bfe\u591a\u306e\u95a2\u4fc2\u3060\u306a\u300d\u3068\u3044\u3046\u3088\u3046\u306b\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\uff08\u30c6\u30fc\u30d6\u30eb\uff09\u540c\u58eb\u306e\u95a2\u4fc2\u6027\u3092ER\u56f3\u3067\u53ef\u8996\u5316\u3057\u307e\u3059\u3002<br \/>\n    <code>[\u9867\u5ba2] 1 ----- N [\u6ce8\u6587]<\/code><\/li>\n<li><strong>\u30c6\u30fc\u30d6\u30eb\u8a2d\u8a08\u306b\u843d\u3068\u3057\u8fbc\u3080<\/strong>:<br \/>\n    \u6b21\u306b\u3001ER\u56f3\u3092\u5143\u306b\u5177\u4f53\u7684\u306a\u30c6\u30fc\u30d6\u30eb\u69cb\u9020\uff08\u7269\u7406\u8a2d\u8a08\uff09\u3092\u8003\u3048\u307e\u3059\u3002\u3053\u306e\u3068\u304d\u3001\u300c\u6ce8\u6587\u30c6\u30fc\u30d6\u30eb\u306b\u3001\u3069\u306e\u9867\u5ba2\u306e\u6ce8\u6587\u304b\u3092\u793a\u3059\u305f\u3081\u306e\u30ab\u30e9\u30e0\u304c\u5fc5\u8981\u3060\u300d\u3068\u8003\u3048\u3001<code>customer_id<\/code>\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/li>\n<li><strong>SQL\u3067\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u5b9f\u88c5\u3059\u308b<\/strong>:<br \/>\n    \u6700\u5f8c\u306b\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308bSQL\u6587\u3067\u3001<code>FOREIGN KEY<\/code>\u53e5\u3092\u7528\u3044\u3066\u300c\u6ce8\u6587\u30c6\u30fc\u30d6\u30eb\u306e<code>customer_id<\/code>\u306f\u3001\u9867\u5ba2\u30c6\u30fc\u30d6\u30eb\u306e<code>customer_id<\/code>\u3092\u53c2\u7167\u3059\u308b\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u3092\u660e\u78ba\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u3053\u308c\u304c\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u5b9f\u88c5\u3067\u3059\u3002<\/li>\n<\/ol>\n<p>\u3053\u306e<strong>\u300cER\u56f3 \u2192 \u30c6\u30fc\u30d6\u30eb\u8a2d\u8a08 \u2192 \u5916\u90e8\u30ad\u30fc\u5236\u7d04 \u2192 \u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u78ba\u4fdd\u300d<\/strong>\u3068\u3044\u3046\u4e00\u9023\u306e\u6d41\u308c\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u304c\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002ER\u56f3\u3092\u63cf\u3051\u308b\u3088\u3046\u306b\u306a\u308b\u3068\u3001SQL\u304c\u8aad\u3081\u308b\u3088\u3046\u306b\u306a\u308a\u3001\u9006\u306bSQL\u3092\u898b\u308c\u3070\u30b7\u30b9\u30c6\u30e0\u306e\u30c7\u30fc\u30bf\u69cb\u9020\uff08ER\u56f3\uff09\u304c\u982d\u306b\u601d\u3044\u6d6e\u304b\u3076\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u30b9\u30ad\u30eb\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u6271\u3046\u3059\u3079\u3066\u306e\u30a8\u30f3\u30b8\u30cb\u30a2\u306b\u3068\u3063\u3066\u5fc5\u9808\u306e\u57fa\u790e\u77e5\u8b58\u3068\u8a00\u3048\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<h2>\u3088\u304f\u3042\u308b\u30df\u30b9\u3068\u8a2d\u8a08\u306e\u30b3\u30c4\u2502\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5348\u5f8c\u8a66\u9a13 \u653b\u7565\u30dd\u30a4\u30f3\u30c8<\/h2>\n<p>ER\u56f3\u3068\u5916\u90e8\u30ad\u30fc\u306e\u6982\u5ff5\u3092\u7406\u89e3\u3057\u3066\u3082\u3001\u5b9f\u969b\u306e\u8a2d\u8a08\u3084\u8a66\u9a13\u554f\u984c\u3067\u601d\u308f\u306c\u843d\u3068\u3057\u7a74\u306b\u306f\u307e\u3063\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u521d\u5fc3\u8005\u304c\u3084\u308a\u304c\u3061\u306a\u30df\u30b9\u3068\u3001\u305d\u308c\u3092\u907f\u3051\u308b\u305f\u3081\u306e\u8a2d\u8a08\u306e\u30b3\u30c4\u3092\u3044\u304f\u3064\u304b\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3057\u5fd8\u308c\u3066\u300c\u5b64\u7acb\u30c7\u30fc\u30bf\u300d\u304c\u767a\u751f<\/h3>\n<p>\u6700\u3082\u57fa\u672c\u7684\u304b\u3064\u91cd\u5927\u306a\u30df\u30b9\u304c\u3001\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u305d\u306e\u3082\u306e\u3092\u8a2d\u5b9a\u3057\u5fd8\u308c\u308b\u3053\u3068\u3067\u3059\u3002\u3053\u308c\u3092\u5fd8\u308c\u308b\u3068\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f\u300c\u5b58\u5728\u3057\u306a\u3044\u9867\u5ba2ID\u3092\u6301\u3064\u6ce8\u6587\u300d\u306e\u3088\u3046\u306a\u3001\u89aa\u3068\u306f\u3050\u308c\u305f<strong>\u5b64\u7acb\u30c7\u30fc\u30bf\uff08\u8ff7\u5b50\u30c7\u30fc\u30bf\uff09<\/strong>\u306e\u767b\u9332\u3092\u8a31\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u304c\u5d29\u308c\u308b\u539f\u56e0\u306b\u306a\u308b\u305f\u3081\u3001\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u95a2\u9023\u3092\u5b9a\u7fa9\u3057\u305f\u3089\u3001\u5fc5\u305aSQL\u3067<code>FOREIGN KEY<\/code>\u5236\u7d04\u3092\u5b9f\u88c5\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u591a\u5bfe\u591a\u306e\u95a2\u4fc2\u30921\u5bfeN\u306b\u8aa4\u89e3\u3059\u308b<\/h3>\n<p>\u300c\u5b66\u751f\u300d\u3068\u300c\u8b1b\u7fa9\u300d\u306e\u3088\u3046\u306b\u30011\u4eba\u306e\u5b66\u751f\u304c\u8907\u6570\u306e\u8b1b\u7fa9\u3092\u5c65\u4fee\u3057\u30011\u3064\u306e\u8b1b\u7fa9\u306b\u306f\u8907\u6570\u306e\u5b66\u751f\u304c\u6240\u5c5e\u3059\u308b\u95a2\u4fc2\u306f\u300c<strong>\u591a\u5bfe\u591a<\/strong>\u300d\u3067\u3059\u3002\u3053\u308c\u3092\u7121\u7406\u306b\u300c\u4e00\u5bfe\u591a\u300d\u3067\u8868\u73fe\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u8a2d\u8a08\u304c\u7834\u7dbb\u3057\u307e\u3059\u3002\u591a\u5bfe\u591a\u306e\u95a2\u4fc2\u306f\u3001\u4e21\u8005\u3092\u3064\u306a\u3050\u300c<strong>\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb<\/strong>\uff08\u9023\u95a2\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\uff09\u300d\u3092\u9593\u306b\u631f\u3093\u3067\u30012\u3064\u306e\u300c\u4e00\u5bfe\u591a\u300d\u306e\u95a2\u4fc2\u306b\u5206\u89e3\u3059\u308b\u306e\u304c\u5b9a\u77f3\u3067\u3059\u3002<\/p>\n<pre><code>[\u5b66\u751f] 1 --- N [\u5c65\u4fee\u30c6\u30fc\u30d6\u30eb] N --- 1 [\u8b1b\u7fa9]<\/code><\/pre>\n<h3>ER\u56f3\u306e\u6bb5\u968e\u3067\u300c\u89aa\u30fb\u5b50\u300d\u3092\u660e\u78ba\u306b\u3059\u308b<\/h3>\n<p>\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u8003\u3048\u308b\u969b\u306f\u3001\u3069\u3061\u3089\u304c\u300c1\u300d\u3067\u3069\u3061\u3089\u304c\u300c\u591a\uff08N\uff09\u300d\u306a\u306e\u304b\u3001\u3064\u307e\u308a\u3069\u3061\u3089\u304c\u89aa\u3067\u3069\u3061\u3089\u304c\u5b50\u306a\u306e\u304b\u3092\u660e\u78ba\u306b\u610f\u8b58\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u4e00\u822c\u7684\u306b\u3001<strong>\u300c\u25cb\u25cb\u3092\u6301\u3064\u5074\u300d\u304c\u89aa<\/strong>\u3001<strong>\u300c\u25cb\u25cb\u306b\u6240\u5c5e\u3059\u308b\u5074\u300d\u304c\u5b50<\/strong>\u306b\u306a\u308a\u307e\u3059\u3002\u300c\u9867\u5ba2\u300d\u306f\u8907\u6570\u306e\u300c\u6ce8\u6587\u300d\u3092\u6301\u3064\u306e\u3067\u3001\u9867\u5ba2\u304c\u89aa\u3067\u3059\u3002\u3053\u306e\u95a2\u4fc2\u3092\u9006\u306b\u3059\u308b\u3068\u3001\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u304c\u9006\u306b\u306a\u308a\u3001\u6b63\u3057\u304f\u30c7\u30fc\u30bf\u3092\u8868\u73fe\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<h3>`RESTRICT`\u3092\u4f7f\u3046\u3068\u304d\u306f\u524a\u9664\u9806\u5e8f\u306b\u3082\u6ce8\u610f<\/h3>\n<p>\u30c7\u30fc\u30bf\u306e\u5b89\u5168\u6027\u3092\u6700\u3082\u9ad8\u304f\u4fdd\u3066\u308b<code>ON DELETE RESTRICT<\/code>\u3067\u3059\u304c\u3001\u904b\u7528\u4e0a\u306e\u6ce8\u610f\u70b9\u304c\u3042\u308a\u307e\u3059\u3002\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u89aa\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u305f\u3044\u5834\u5408\u3001\u5fc5\u305a<strong>\u5148\u306b\u5b50\u30c7\u30fc\u30bf\u3092\u3059\u3079\u3066\u524a\u9664\uff08\u307e\u305f\u306f\u5916\u90e8\u30ad\u30fc\u3092\u66f4\u65b0\uff09<\/strong>\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u524a\u9664\u9806\u5e8f\u3092\u8003\u616e\u305b\u305a\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u7d44\u3080\u3068\u3001\u30c7\u30fc\u30bf\u524a\u9664\u51e6\u7406\u3067\u610f\u56f3\u3057\u306a\u3044\u30a8\u30e9\u30fc\u304c\u591a\u767a\u3059\u308b\u539f\u56e0\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u307e\u3068\u3081\uff1aER\u56f3\u3068\u5916\u90e8\u30ad\u30fc\u3092\u7406\u89e3\u3059\u308c\u3070\u30c7\u30fc\u30bf\u304c\u201c\u3064\u306a\u304c\u308b\u201d<\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u306e\u57fa\u790e\u3067\u3042\u308bER\u56f3\u3001\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3001\u4e3b\u30ad\u30fc\u3068\u5916\u90e8\u30ad\u30fc\u306e\u9055\u3044\u3001\u305d\u3057\u3066\u53c2\u7167\u6574\u5408\u6027\u5236\u7d04\u306b\u3064\u3044\u3066\u3001SQL\u306e\u5b9f\u4f8b\u3092\u4ea4\u3048\u306a\u304c\u3089\u89e3\u8aac\u3057\u3066\u304d\u307e\u3057\u305f\u3002\u6700\u5f8c\u306b\u3001\u305d\u308c\u305e\u308c\u306e\u6982\u5ff5\u304c\u3069\u306e\u3088\u3046\u306a\u5f79\u5272\u3092\u679c\u305f\u3057\u3066\u3044\u308b\u306e\u304b\u3092\u3001\u3082\u3046\u4e00\u5ea6\u30b7\u30f3\u30d7\u30eb\u306b\u632f\u308a\u8fd4\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li><strong>ER\u56f3\u306f\u300c\u8a2d\u8a08\u306e\u5730\u56f3\u300d<\/strong><br \/>\n    \u30b7\u30b9\u30c6\u30e0\u5168\u4f53\u306e\u30c7\u30fc\u30bf\u306e\u69cb\u9020\u3068\u95a2\u4fc2\u6027\u3092\u53ef\u8996\u5316\u3057\u3001\u8a2d\u8a08\u306e\u30d6\u30ec\u3092\u9632\u304e\u307e\u3059\u3002<\/li>\n<li><strong>\u5916\u90e8\u30ad\u30fc\u306f\u300c\u30c7\u30fc\u30bf\u306e\u4ea4\u901a\u30eb\u30fc\u30eb\u300d<\/strong><br \/>\n    \u30c6\u30fc\u30d6\u30eb\u540c\u58eb\u3092\u6b63\u3057\u304f\u3064\u306a\u304e\u3001\u300c\u5b58\u5728\u3057\u306a\u3044\u89aa\u300d\u3092\u6301\u3064\u300c\u8ff7\u5b50\u306e\u30c7\u30fc\u30bf\u300d\u304c\u751f\u307e\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/li>\n<li><strong>\u53c2\u7167\u6574\u5408\u6027\u306f\u300c\u5b89\u5168\u306a\u30c7\u30fc\u30bf\u7ba1\u7406\u306e\u4ed5\u7d44\u307f\u300d<\/strong><br \/>\n    \u89aa\u30c7\u30fc\u30bf\u306e\u5909\u66f4\u3084\u524a\u9664\u304c\u767a\u751f\u3057\u305f\u969b\u306b\u3001\u95a2\u9023\u3059\u308b\u5b50\u30c7\u30fc\u30bf\u304c\u77db\u76fe\u3057\u305f\u72b6\u614b\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u3001\u632f\u308b\u821e\u3044\u306e\u30eb\u30fc\u30eb\u3092\u5b9a\u3081\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>\u3053\u308c\u3089\u306e\u6982\u5ff5\u306f\u3001\u4e00\u898b\u3059\u308b\u3068\u8907\u96d1\u306b\u611f\u3058\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u3053\u306e3\u3064\u306e\u95a2\u4fc2\u6027\u3092\u4e00\u5ea6\u7406\u89e3\u3057\u3066\u3057\u307e\u3048\u3070\u3001\u3069\u3093\u306a\u306b\u8907\u96d1\u306a\u30b7\u30b9\u30c6\u30e0\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u3082\u3001\u305d\u306e\u69cb\u9020\u3092\u8aad\u307f\u89e3\u304f\u529b\u304c\u8eab\u306b\u3064\u304d\u307e\u3059\u3002\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306e\u5bfe\u7b56\u306f\u3082\u3061\u308d\u3093\u3001\u5b9f\u52d9\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u6271\u3046\u4e0a\u3067\u306e\u5f37\u529b\u306a\u571f\u53f0\u3068\u306a\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<p>\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3068\u3057\u3066\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u3088\u308a\u52b9\u7387\u7684\u306b\u6574\u7406\u3059\u308b\u305f\u3081\u306e\u300c<strong>\u6b63\u898f\u5316<\/strong>\u300d\u3084\u3001\u3088\u308a\u8907\u96d1\u306a\u95a2\u4fc2\u6027\u3092\u8868\u73fe\u3059\u308b\u300c<strong>\u30b9\u30fc\u30d1\u30fc\u30bf\u30a4\u30d7\uff0f\u30b5\u30d6\u30bf\u30a4\u30d7<\/strong>\u300d\u3068\u3044\u3063\u305f\u6982\u5ff5\u3092\u5b66\u3093\u3067\u3044\u304f\u3068\u3001\u3055\u3089\u306b\u7406\u89e3\u304c\u6df1\u307e\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u8a2d\u8a08\u3001\u7279\u306b\u5fdc\u7528\u60c5\u5831\u6280\u8853\u8005\u8a66\u9a13\u306e\u52c9\u5f37\u3092\u59cb\u3081\u308b\u3068\u3001\u5fc5\u305a\u3068\u8a00\u3063\u3066\u3044\u3044\u307b\u3069\u767b\u5834\u3059\u308b\u306e\u304c\u300cER\u56f3\u300d\u3084\u300c\u5916\u90e8\u30ad\u30fc\u300d\u3068\u3044\u3063\u305f\u5c02\u9580\u7528\u8a9e\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u300c\u4e3b\u30ad\u30fc\u3068\u5916\u90e8\u30ad\u30fc\u3063\u3066\u3001\u540d\u524d\u306f\u4f3c\u3066\u3044\u308b\u3051\u3069\u4f55\u304c\u9055\u3046\u306e\uff1f &#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","columnck":"","stmeta_robots":"index, follow","st_titlewords":"","st_title_extra":"","st_keywords":"","st_description":"","st_display_ad_mark":"","st_display_ad_mark_hide":"","textcopyck":"","st_copyright":"","st_copyurl":"","eyecatch_set":"","st_youtube_url":"","st_youtube_eyecatch":"","headerwidget_set":"","updatewidget_set":"","kanrenwidget_set":"","ikkatuwidget_set":"","koukoku_set":"","auto_adsense_koukoku_set":"","st_redirect":"","st_redirect_url_as_canonical":"","st_redirect_pvm_do_not_track":"","post_data_updatewidget_set":"","st_post_header_under_bg":"","st_twitter_tag":"","affinger_note":"","rankdisplayck":"","st_head_code":"","st_footer_code":"","st_post_header_under_code":"","_st_toc_override":false,"_st_toc_settings":[]},"categories":[3],"tags":[6],"class_list":["post-6196","post","type-post","status-publish","format-standard","hentry","category-ipa","tag-6"],"_links":{"self":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts\/6196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/comments?post=6196"}],"version-history":[{"count":0,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts\/6196\/revisions"}],"wp:attachment":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/media?parent=6196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/categories?post=6196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/tags?post=6196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}