{"id":17990,"date":"2026-07-18T11:41:12","date_gmt":"2026-07-18T02:41:12","guid":{"rendered":"https:\/\/genai-ai.co.jp\/ai-kanri\/?p=17990"},"modified":"2026-07-18T11:41:12","modified_gmt":"2026-07-18T02:41:12","slug":"cc-sql-foreign-key","status":"publish","type":"post","link":"https:\/\/genai-ai.co.jp\/ai-kanri\/blog\/cc-sql-foreign-key\/","title":{"rendered":"\u3010SQL\u5916\u90e8\u30ad\u30fc\u5b8c\u5168\u89e3\u8aac\u3011FOREIGN KEY\u306e\u4f5c\u6210\u30fb\u6574\u5408\u6027\u5236\u7d04\u30fb\u5f8c\u4ed8\u3051\u8ffd\u52a0\u30fb\u524a\u9664\u307e\u3067"},"content":{"rendered":"\n<style>\n.g-flow-row{display:flex;gap:8px;justify-content:center;flex-wrap:wrap;align-items:center;}\n.g-flow-item{background:linear-gradient(135deg,#1a1a1a,#2a1015);color:#fff;border-radius:8px;padding:16px 14px;min-width:130px;flex:1;text-align:center;}\n.g-flow-arrow{color:#dc2626;font-size:20px;font-weight:700;}\n.g-card-row{display:flex;gap:12px;flex-wrap:wrap;margin:0 0 32px;}\n.g-card-row>div{flex:1;min-width:220px;}\n@media(max-width:600px){\n  .g-flow-row{flex-direction:column;}\n  .g-flow-arrow{transform:rotate(90deg);}\n  .g-card-row{flex-direction:column;}\n  .g-card-row>div{min-width:100%;}\n}\n<\/style>\n\n\n\n<div style=\"margin:0 0 32px;\">\n  <img decoding=\"async\" src=\"\u3010SQL\u5916\u90e8\u30ad\u30fc\u5b8c\u5168\u89e3\u8aac\u3011FOREIGN KEY\u306e\u4f5c\u6210\u30fb\u6574\u5408\u6027\u5236\u7d04\u30fb\u5f8c\u4ed8\u3051\u8ffd\u52a0\u30fb\u524a\u9664\u307e\u3067\" alt=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/07\/thumb-cc-sql-foreign-key.jpg\" style=\"width:100%;height:auto;border-radius:12px;display:block;\">\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">SQL\u306e\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u3092\u5b8c\u5168\u89e3\u8aac\u3002\u5916\u90e8\u30ad\u30fc\u306e\u5f79\u5272\u30fb\u89aa\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u95a2\u4fc2\u30fbCREATE TABLE\u3067\u306e\u8a2d\u5b9a\u30fbALTER TABLE\u3067\u306e\u5f8c\u4ed8\u3051\u8ffd\u52a0\u30fbDROP FOREIGN KEY\u3067\u306e\u524a\u9664\u30fb\u6574\u5408\u6027\u5236\u7d04\u30a8\u30e9\u30fc\u306e\u5bfe\u51e6\u6cd5\u307e\u3067Claude Code\u306e\u6d3b\u7528\u6cd5\u3068\u5408\u308f\u305b\u3066\u5b9f\u8df5\u7684\u306b\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u3067\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u95a2\u4fc2\uff08\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\uff09\u3092\u7ba1\u7406\u3059\u308b\u3068\u304d\u306b\u6b20\u304b\u305b\u306a\u3044\u306e\u304c\u300c\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u300d\u3067\u3059\u3002\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u53c2\u7167\u6574\u5408\u6027\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30ec\u30d9\u30eb\u3067\u4fdd\u8a3c\u3067\u304d\u3001\u30c7\u30fc\u30bf\u306e\u4e0d\u6574\u5408\u3092\u9632\u3052\u307e\u3059\u3002\u3057\u304b\u3057\u5916\u90e8\u30ad\u30fc\u306e\u6982\u5ff5\u304c\u7406\u89e3\u3067\u304d\u3066\u3044\u306a\u3044\u3068\u3001\u6574\u5408\u6027\u30a8\u30e9\u30fc\u306b\u60a9\u307e\u3055\u308c\u305f\u308a\u3001\u4e0d\u5fc5\u8981\u306a\u5236\u7d04\u3067\u30c7\u30fc\u30bf\u64cd\u4f5c\u304c\u56f0\u96e3\u306b\u306a\u3063\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u5916\u90e8\u30ad\u30fc\u306e\u57fa\u672c\u6982\u5ff5\u304b\u3089\u4f5c\u6210\u30fb\u5f8c\u4ed8\u3051\u8ffd\u52a0\u30fb\u524a\u9664\u307e\u3067\u3001Claude Code\u306e\u6d3b\u7528\u6cd5\u3068\u5408\u308f\u305b\u3066\u4f53\u7cfb\u7684\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"g-flow-row\" style=\"display:flex;align-items:center;flex-wrap:wrap;gap:10px;margin:20px 0;padding:20px;background:#f8fafc;border-radius:12px;\">\n<div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">\u5916\u90e8\u30ad\u30fc\u3068\u306f<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">\u6574\u5408\u6027\u5236\u7d04\u306e\u52d5\u4f5c<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">\u5f8c\u4ed8\u3051\u8ffd\u52a0<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">Claude Code\u6d3b\u7528<\/div>\n<\/div>\n\n\n<div style=\"margin:48px 0 8px;display:flex;gap:12px;justify-content:center;flex-wrap:wrap;\"><a href=\"https:\/\/aikanri.genai-ai.co.jp\/seminar2-blog\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_content=cc-sql-foreign-key&#038;blog_slug=cc-sql-foreign-key\" target=\"_blank\" rel=\"noopener\" aria-label=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff08\u7121\u6599\u30fb1on1\u30fb60\u5206\uff09\u306e\u4e88\u7d04\u753b\u9762\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_seminar_claude_code_2026.jpg\" alt=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff5c\u7d4c\u55b6\u8005\u30fb\u4f1a\u793e\u5f79\u54e1\u5c02\u7528 1on1 60\u5206 \u7121\u6599\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><a href=\"https:\/\/aikanri.genai-ai.co.jp\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_campaign=cc-sql-foreign-key&#038;utm_content=h2-banner-kanri\" target=\"_blank\" rel=\"noopener\" aria-label=\"AI\u9b3c\u7ba1\u7406 \u516c\u5f0f\u30b5\u30a4\u30c8\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_blog_1to1.jpg\" alt=\"Claude Code\u3092\u7d4c\u55b6\u306b\u6d3b\u304b\u3057\u305f\u3044\u65b9\u3078 \u2014 AI\u9b3c\u7ba1\u7406\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-01\">\u5916\u90e8\u30ad\u30fc\u3068\u306f\uff1a\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u53c2\u7167\u6574\u5408\u6027\u3092\u4fdd\u8a3c\u3059\u308bSQL\u6a5f\u80fd<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u306f\u3001\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u306e\u30ab\u30e9\u30e0\u304c\u5225\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\uff08PRIMARY KEY\uff09\u3092\u53c2\u7167\u3059\u308b\u3068\u3044\u3046\u95a2\u4fc2\u3092\u5b9a\u7fa9\u3059\u308bSQL\u6a5f\u80fd\u3067\u3059\u3002\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u300c\u53c2\u7167\u5148\u306b\u5b58\u5728\u3057\u306a\u3044\u5024\u306f\u767b\u9332\u3067\u304d\u306a\u3044\u300d\u300c\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306f\u524a\u9664\u3067\u304d\u306a\u3044\u300d\u3068\u3044\u3046\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30ec\u30d9\u30eb\u306e\u5236\u7d04\u304c\u81ea\u52d5\u7684\u306b\u50cd\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div style=\"background:#f8f9fa;border-left:4px solid #6b7280;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#6b7280;letter-spacing:1px;\">&#128218; \u7528\u8a9e\u89e3\u8aac<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\"><strong>\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09<\/strong>\uff1a\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u306e\u30ab\u30e9\u30e0\u304c\u5225\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u307e\u305f\u306f\u30e6\u30cb\u30fc\u30af\u30ad\u30fc\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u3092\u5ba3\u8a00\u3059\u308bSQL\u5236\u7d04\u3002\u300c\u53c2\u7167\u6574\u5408\u6027\uff08Referential Integrity\uff09\u300d\u3092\u7dad\u6301\u3059\u308b\u305f\u3081\u306e\u6a5f\u80fd\u3067\u3001\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3057\u306a\u3044\u5024\u3092\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u767b\u9332\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002\u95a2\u4fc2\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08RDB\uff09\u3067\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u7ba1\u7406\u3059\u308b\u57fa\u672c\u7684\u306a\u4ed5\u7d44\u307f\u3067\u3059\u3002<\/p>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u306e\u4ed5\u7d44\u307f\u3092\u7406\u89e3\u3059\u308b\u306b\u306f\u300c\u89aa\u30c6\u30fc\u30d6\u30eb\uff08\u53c2\u7167\u3055\u308c\u308b\u5074\uff09\u300d\u3068\u300c\u5b50\u30c6\u30fc\u30d6\u30eb\uff08\u53c2\u7167\u3059\u308b\u5074\uff09\u300d\u306e\u95a2\u4fc2\u3092\u628a\u63e1\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<table style=\"width:100%;border-collapse:collapse;margin:20px 0;font-size:14px;\">\n<thead>\n<tr style=\"background:#1e3a5f;color:#fff;\">\n  <th style=\"padding:10px 14px;text-align:left;border:1px solid #cbd5e1;\">\u7528\u8a9e<\/th>\n  <th style=\"padding:10px 14px;text-align:left;border:1px solid #cbd5e1;\">\u8aac\u660e<\/th>\n  <th style=\"padding:10px 14px;text-align:left;border:1px solid #cbd5e1;\">\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background:#fff;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-weight:700;\">\u89aa\u30c6\u30fc\u30d6\u30eb<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u53c2\u7167\u3055\u308c\u308b\u5074\u306e\u30c6\u30fc\u30d6\u30eb\u3002\u5916\u90e8\u30ad\u30fc\u306e\u53c2\u7167\u5148<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u90e8\u7f72\u30c6\u30fc\u30d6\u30eb\uff08departments\uff09<\/td>\n<\/tr>\n<tr style=\"background:#f8fafc;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-weight:700;\">\u5b50\u30c6\u30fc\u30d6\u30eb<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u53c2\u7167\u3059\u308b\u5074\u306e\u30c6\u30fc\u30d6\u30eb\u3002\u5916\u90e8\u30ad\u30fc\u3092\u6301\u3064<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u5f93\u696d\u54e1\u30c6\u30fc\u30d6\u30eb\uff08employees\uff09<\/td>\n<\/tr>\n<tr style=\"background:#fff;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-weight:700;\">\u53c2\u7167\u30ab\u30e9\u30e0<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u5b50\u30c6\u30fc\u30d6\u30eb\u3067\u5916\u90e8\u30ad\u30fc\u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308b\u30ab\u30e9\u30e0<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">employees.department_id<\/td>\n<\/tr>\n<tr style=\"background:#f8fafc;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-weight:700;\">\u88ab\u53c2\u7167\u30ab\u30e9\u30e0<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u89aa\u30c6\u30fc\u30d6\u30eb\u3067\u53c2\u7167\u3055\u308c\u308b\u4e3b\u30ad\u30fc\u30ab\u30e9\u30e0<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">departments.id<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\n<div style=\"background:#f0fdf4;border-left:4px solid #22c55e;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#22c55e;letter-spacing:1px;\">&#128161; \u5916\u90e8\u30ad\u30fc\u306f\u300c\u30c7\u30fc\u30bf\u306e\u4e00\u8cab\u6027\u3092\u5b88\u308b\u5b88\u885b\u300d<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\">\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5074\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3057\u306a\u304f\u3066\u3082\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u300c\u53c2\u7167\u5148\u306b\u5b58\u5728\u3057\u306a\u3044\u5024\u300d\u306e\u767b\u9332\u3092\u81ea\u52d5\u3067\u62d2\u5426\u3057\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u5f93\u696d\u54e1\u30c6\u30fc\u30d6\u30eb\u306bdepartment_id=99\u3092\u5165\u308c\u3088\u3046\u3068\u3057\u3066\u3082\u3001\u90e8\u7f72\u30c6\u30fc\u30d6\u30eb\u306bID=99\u304c\u5b58\u5728\u3057\u306a\u3051\u308c\u3070\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d0\u30b0\u3067\u3082\u30c7\u30fc\u30bf\u6574\u5408\u6027\u304c\u5b88\u3089\u308c\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n<div style=\"margin:48px 0 8px;display:flex;gap:12px;justify-content:center;flex-wrap:wrap;\"><a href=\"https:\/\/aikanri.genai-ai.co.jp\/seminar2-blog\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_content=cc-sql-foreign-key&#038;blog_slug=cc-sql-foreign-key\" target=\"_blank\" rel=\"noopener\" aria-label=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff08\u7121\u6599\u30fb1on1\u30fb60\u5206\uff09\u306e\u4e88\u7d04\u753b\u9762\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_seminar_claude_code_2026.jpg\" alt=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff5c\u7d4c\u55b6\u8005\u30fb\u4f1a\u793e\u5f79\u54e1\u5c02\u7528 1on1 60\u5206 \u7121\u6599\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><a href=\"https:\/\/aikanri.genai-ai.co.jp\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_campaign=cc-sql-foreign-key&#038;utm_content=h2-banner-kanri\" target=\"_blank\" rel=\"noopener\" aria-label=\"AI\u9b3c\u7ba1\u7406 \u516c\u5f0f\u30b5\u30a4\u30c8\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_blog_1to1.jpg\" alt=\"Claude Code\u3092\u7d4c\u55b6\u306b\u6d3b\u304b\u3057\u305f\u3044\u65b9\u3078 \u2014 AI\u9b3c\u7ba1\u7406\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-02\">\u5916\u90e8\u30ad\u30fc\u306e\u4f5c\u6210\u65b9\u6cd5\uff1aCREATE TABLE\u3067FOREIGN KEY\u5236\u7d04\u3092\u8a2d\u5b9a\u3059\u308b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u306f\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u6642\uff08CREATE TABLE\uff09\u306b\u8a2d\u5b9a\u3059\u308b\u306e\u304c\u57fa\u672c\u3067\u3059\u3002\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u306e\u672b\u5c3e\u306bFOREIGN KEY\u5236\u7d04\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div style=\"background:#f8f9fa;border-left:4px solid #6b7280;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#6b7280;letter-spacing:1px;\">&#128218; \u7528\u8a9e\u89e3\u8aac<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\"><strong>REFERENCES\u53e5<\/strong>\uff1aFOREIGN KEY\u5236\u7d04\u3067\u53c2\u7167\u5148\u30c6\u30fc\u30d6\u30eb\u3068\u30ab\u30e9\u30e0\u3092\u6307\u5b9a\u3059\u308bSQL\u69cb\u6587\u3002\u300cFOREIGN KEY (\u5b50\u306e\u30ab\u30e9\u30e0) REFERENCES \u89aa\u30c6\u30fc\u30d6\u30eb(\u89aa\u306e\u30ab\u30e9\u30e0)\u300d\u306e\u5f62\u5f0f\u3067\u8a18\u8ff0\u3057\u307e\u3059\u3002\u53c2\u7167\u5148\u30ab\u30e9\u30e0\u306f\u4e3b\u30ad\u30fc\uff08PRIMARY KEY\uff09\u307e\u305f\u306f\u30e6\u30cb\u30fc\u30af\u30ad\u30fc\uff08UNIQUE\uff09\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<div style=\"background:#1e1e2e;border-radius:10px;padding:20px 24px;margin:20px 0;font-family:monospace;font-size:14px;line-height:1.8;color:#cdd6f4;overflow-x:auto;white-space:pre;\"><span style=\"color:#6c7086;\">-- \u30b9\u30c6\u30c3\u30d71: \u89aa\u30c6\u30fc\u30d6\u30eb\uff08\u90e8\u7f72\u30c6\u30fc\u30d6\u30eb\uff09\u3092\u5148\u306b\u4f5c\u6210 *\/<\/span>\n<span style=\"color:#cba6f7;\">CREATE TABLE<\/span> <span style=\"color:#89b4fa;\">departments<\/span> (\n    <span style=\"color:#89b4fa;\">id<\/span>         <span style=\"color:#fab387;\">INT<\/span> <span style=\"color:#cba6f7;\">PRIMARY KEY<\/span> AUTO_INCREMENT,\n    <span style=\"color:#89b4fa;\">name<\/span>       <span style=\"color:#fab387;\">VARCHAR<\/span>(<span style=\"color:#fab387;\">100<\/span>) <span style=\"color:#cba6f7;\">NOT NULL<\/span>,\n    <span style=\"color:#89b4fa;\">created_at<\/span> <span style=\"color:#fab387;\">TIMESTAMP<\/span> <span style=\"color:#cba6f7;\">DEFAULT<\/span> CURRENT_TIMESTAMP\n);\n\n<span style=\"color:#6c7086;\">-- \u30b9\u30c6\u30c3\u30d72: \u521d\u671f\u30c7\u30fc\u30bf\u3092\u633f\u5165<\/span>\n<span style=\"color:#cba6f7;\">INSERT INTO<\/span> <span style=\"color:#89b4fa;\">departments<\/span> (<span style=\"color:#89b4fa;\">name<\/span>) <span style=\"color:#cba6f7;\">VALUES<\/span>\n    (<span style=\"color:#a6e3a1;\">'\u55b6\u696d\u90e8'<\/span>),\n    (<span style=\"color:#a6e3a1;\">'\u958b\u767a\u90e8'<\/span>),\n    (<span style=\"color:#a6e3a1;\">'\u7dcf\u52d9\u90e8'<\/span>);\n\n<span style=\"color:#6c7086;\">-- \u30b9\u30c6\u30c3\u30d73: \u5b50\u30c6\u30fc\u30d6\u30eb\uff08\u5f93\u696d\u54e1\u30c6\u30fc\u30d6\u30eb\uff09\u3092\u5916\u90e8\u30ad\u30fc\u4ed8\u304d\u3067\u4f5c\u6210<\/span>\n<span style=\"color:#cba6f7;\">CREATE TABLE<\/span> <span style=\"color:#89b4fa;\">employees<\/span> (\n    <span style=\"color:#89b4fa;\">id<\/span>            <span style=\"color:#fab387;\">INT<\/span> <span style=\"color:#cba6f7;\">PRIMARY KEY<\/span> AUTO_INCREMENT,\n    <span style=\"color:#89b4fa;\">name<\/span>          <span style=\"color:#fab387;\">VARCHAR<\/span>(<span style=\"color:#fab387;\">100<\/span>) <span style=\"color:#cba6f7;\">NOT NULL<\/span>,\n    <span style=\"color:#89b4fa;\">department_id<\/span> <span style=\"color:#fab387;\">INT<\/span>,\n    <span style=\"color:#89b4fa;\">salary<\/span>        <span style=\"color:#fab387;\">DECIMAL<\/span>(<span style=\"color:#fab387;\">10<\/span>,<span style=\"color:#fab387;\">2<\/span>),\n\n    <span style=\"color:#6c7086;\">-- FOREIGN KEY\u5236\u7d04\u306e\u5b9a\u7fa9<\/span>\n    <span style=\"color:#cba6f7;\">CONSTRAINT<\/span> <span style=\"color:#89b4fa;\">fk_dept<\/span> <span style=\"color:#cba6f7;\">FOREIGN KEY<\/span> (<span style=\"color:#89b4fa;\">department_id<\/span>)\n        <span style=\"color:#cba6f7;\">REFERENCES<\/span> <span style=\"color:#89b4fa;\">departments<\/span>(<span style=\"color:#89b4fa;\">id<\/span>)\n);\n\n<span style=\"color:#6c7086;\">-- \u6b63\u5e38\u306a\u767b\u9332\uff08\u90e8\u7f72ID=1\u306f\u5b58\u5728\u3059\u308b\uff09<\/span>\n<span style=\"color:#cba6f7;\">INSERT INTO<\/span> <span style=\"color:#89b4fa;\">employees<\/span> (<span style=\"color:#89b4fa;\">name<\/span>, <span style=\"color:#89b4fa;\">department_id<\/span>) <span style=\"color:#cba6f7;\">VALUES<\/span> (<span style=\"color:#a6e3a1;\">'\u5c71\u7530\u592a\u90ce'<\/span>, <span style=\"color:#fab387;\">1<\/span>);  <span style=\"color:#6c7086;\">-- OK<\/span>\n\n<span style=\"color:#6c7086;\">-- \u30a8\u30e9\u30fc\u306b\u306a\u308b\u767b\u9332\uff08\u90e8\u7f72ID=99\u306f\u5b58\u5728\u3057\u306a\u3044\uff09<\/span>\n<span style=\"color:#cba6f7;\">INSERT INTO<\/span> <span style=\"color:#89b4fa;\">employees<\/span> (<span style=\"color:#89b4fa;\">name<\/span>, <span style=\"color:#89b4fa;\">department_id<\/span>) <span style=\"color:#cba6f7;\">VALUES<\/span> (<span style=\"color:#a6e3a1;\">'\u9234\u6728\u82b1\u5b50'<\/span>, <span style=\"color:#fab387;\">99<\/span>);\n<span style=\"color:#6c7086;\">-- ERROR 1452: Cannot add or update a child row: a foreign key constraint fails<\/span><\/div>\n\n\n\n<div style=\"background:#f0fdf4;border-left:4px solid #22c55e;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#22c55e;letter-spacing:1px;\">&#128161; \u89aa\u30c6\u30fc\u30d6\u30eb\u3092\u5148\u306b\u4f5c\u6210\u30fb\u524a\u9664\u306f\u5b50\u304b\u3089\u884c\u3046<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\">\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3057\u305f\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u3001\u89aa\u30c6\u30fc\u30d6\u30eb\u304c\u5148\u306b\u5b58\u5728\u3057\u3066\u3044\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002\u9006\u306b\u524a\u9664\u3059\u308b\u3068\u304d\u306f\u5b50\u30c6\u30fc\u30d6\u30eb\u3092\u5148\u306b\u524a\u9664\uff08\u307e\u305f\u306fFOREIGN KEY\u5236\u7d04\u3092\u5148\u306b\u524a\u9664\uff09\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u9806\u5e8f\u3092\u9593\u9055\u3048\u308b\u3068\u300c\u53c2\u7167\u5148\u30c6\u30fc\u30d6\u30eb\u304c\u5b58\u5728\u3057\u306a\u3044\u300d\u300c\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u9055\u53cd\u300d\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n<div style=\"margin:48px 0 8px;display:flex;gap:12px;justify-content:center;flex-wrap:wrap;\"><a href=\"https:\/\/aikanri.genai-ai.co.jp\/seminar2-blog\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_content=cc-sql-foreign-key&#038;blog_slug=cc-sql-foreign-key\" target=\"_blank\" rel=\"noopener\" aria-label=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff08\u7121\u6599\u30fb1on1\u30fb60\u5206\uff09\u306e\u4e88\u7d04\u753b\u9762\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_seminar_claude_code_2026.jpg\" alt=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff5c\u7d4c\u55b6\u8005\u30fb\u4f1a\u793e\u5f79\u54e1\u5c02\u7528 1on1 60\u5206 \u7121\u6599\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><a href=\"https:\/\/aikanri.genai-ai.co.jp\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_campaign=cc-sql-foreign-key&#038;utm_content=h2-banner-kanri\" target=\"_blank\" rel=\"noopener\" aria-label=\"AI\u9b3c\u7ba1\u7406 \u516c\u5f0f\u30b5\u30a4\u30c8\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_blog_1to1.jpg\" alt=\"Claude Code\u3092\u7d4c\u55b6\u306b\u6d3b\u304b\u3057\u305f\u3044\u65b9\u3078 \u2014 AI\u9b3c\u7ba1\u7406\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-03\">\u5916\u90e8\u30ad\u30fc\u306e\u6574\u5408\u6027\u5236\u7d04\u306e\u52d5\u4f5c\uff1aON DELETE\u30fbON UPDATE\u30aa\u30d7\u30b7\u30e7\u30f3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3067\u306f\u300c\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u30fb\u66f4\u65b0\u3057\u305f\u3068\u304d\u3001\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u3069\u3046\u6271\u3046\u304b\u300d\u3092<code>ON DELETE<\/code>\u30fb<code>ON UPDATE<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u52d5\u4f5c\u306fRESTRICT\uff08\u5b50\u304c\u5b58\u5728\u3059\u308b\u89aa\u306e\u524a\u9664\u30fb\u66f4\u65b0\u3092\u30a8\u30e9\u30fc\u306b\u3059\u308b\uff09\u3067\u3059\u3002<\/p>\n\n\n\n<div style=\"background:#f8f9fa;border-left:4px solid #6b7280;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#6b7280;letter-spacing:1px;\">&#128218; \u7528\u8a9e\u89e3\u8aac<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\"><strong>\u53c2\u7167\u30a2\u30af\u30b7\u30e7\u30f3\uff08ON DELETE \/ ON UPDATE\uff09<\/strong>\uff1a\u5916\u90e8\u30ad\u30fc\u3067\u53c2\u7167\u3057\u3066\u3044\u308b\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u304c\u524a\u9664\u30fb\u66f4\u65b0\u3055\u308c\u305f\u3068\u304d\u306b\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u9069\u7528\u3055\u308c\u308b\u52d5\u4f5c\u3092\u6307\u5b9a\u3059\u308b\u30aa\u30d7\u30b7\u30e7\u30f3\u3002RESTRICT\uff08\u30a8\u30e9\u30fc\uff09\u3001CASCADE\uff08\u5b50\u3082\u540c\u69d8\u306b\u524a\u9664\u30fb\u66f4\u65b0\uff09\u3001SET NULL\uff08\u5b50\u306e\u5916\u90e8\u30ad\u30fc\u3092NULL\u306b\u3059\u308b\uff09\u3001SET DEFAULT\uff08\u5b50\u306e\u5916\u90e8\u30ad\u30fc\u3092\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306b\u3059\u308b\uff09\u306e4\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<table style=\"width:100%;border-collapse:collapse;margin:20px 0;font-size:14px;\">\n<thead>\n<tr style=\"background:#1e3a5f;color:#fff;\">\n  <th style=\"padding:10px 14px;text-align:left;border:1px solid #cbd5e1;\">\u30aa\u30d7\u30b7\u30e7\u30f3<\/th>\n  <th style=\"padding:10px 14px;text-align:left;border:1px solid #cbd5e1;\">\u52d5\u4f5c<\/th>\n  <th style=\"padding:10px 14px;text-align:left;border:1px solid #cbd5e1;\">\u4f7f\u3044\u6240<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background:#fff;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-family:monospace;color:#dc2626;\">RESTRICT\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\uff09<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u5b50\u306b\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u89aa\u306e\u524a\u9664\u30fb\u66f4\u65b0\u3092\u30a8\u30e9\u30fc<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u30c7\u30fc\u30bf\u306e\u5b89\u5168\u3092\u6700\u512a\u5148\u3059\u308b\u3068\u304d<\/td>\n<\/tr>\n<tr style=\"background:#f8fafc;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-family:monospace;color:#dc2626;\">CASCADE<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u89aa\u3092\u524a\u9664\u30fb\u66f4\u65b0\u3059\u308b\u3068\u5b50\u3082\u540c\u69d8\u306b\u524a\u9664\u30fb\u66f4\u65b0<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u89aa\u524a\u9664\u6642\u306b\u5b50\u3082\u4e00\u7dd2\u306b\u6d88\u3057\u305f\u3044\u3068\u304d\uff08\u6ce8\u6587\u3068\u660e\u7d30\u7b49\uff09<\/td>\n<\/tr>\n<tr style=\"background:#fff;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-family:monospace;color:#dc2626;\">SET NULL<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u89aa\u304c\u524a\u9664\u30fb\u66f4\u65b0\u3055\u308c\u308b\u3068\u5b50\u306e\u5916\u90e8\u30ad\u30fc\u5217\u3092NULL\u306b\u3059\u308b<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">\u62c5\u5f53\u8005\u524a\u9664\u6642\u306b\u62c5\u5f53\u672a\u5272\u5f53\u306b\u3059\u308b\u3068\u304d<\/td>\n<\/tr>\n<tr style=\"background:#f8fafc;\">\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;font-family:monospace;color:#dc2626;\">NO ACTION<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">RESTRICT\u3068\u540c\u69d8\uff08\u30c1\u30a7\u30c3\u30af\u30bf\u30a4\u30df\u30f3\u30b0\u304c\u7570\u306a\u308b\uff09<\/td>\n  <td style=\"padding:9px 14px;border:1px solid #cbd5e1;\">MySQL\u3067\u306fRESTRICT\u3068\u540c\u3058\u52d5\u4f5c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\n<div style=\"background:#1e1e2e;border-radius:10px;padding:20px 24px;margin:20px 0;font-family:monospace;font-size:14px;line-height:1.8;color:#cdd6f4;overflow-x:auto;white-space:pre;\"><span style=\"color:#6c7086;\">-- ON DELETE CASCADE\u306e\u4f8b\uff08\u90e8\u7f72\u524a\u9664\u6642\u306b\u6240\u5c5e\u5f93\u696d\u54e1\u3082\u524a\u9664\uff09<\/span>\n<span style=\"color:#cba6f7;\">CREATE TABLE<\/span> <span style=\"color:#89b4fa;\">employees<\/span> (\n    <span style=\"color:#89b4fa;\">id<\/span>            <span style=\"color:#fab387;\">INT<\/span> <span style=\"color:#cba6f7;\">PRIMARY KEY<\/span> AUTO_INCREMENT,\n    <span style=\"color:#89b4fa;\">name<\/span>          <span style=\"color:#fab387;\">VARCHAR<\/span>(<span style=\"color:#fab387;\">100<\/span>) <span style=\"color:#cba6f7;\">NOT NULL<\/span>,\n    <span style=\"color:#89b4fa;\">department_id<\/span> <span style=\"color:#fab387;\">INT<\/span>,\n    <span style=\"color:#cba6f7;\">FOREIGN KEY<\/span> (<span style=\"color:#89b4fa;\">department_id<\/span>) <span style=\"color:#cba6f7;\">REFERENCES<\/span> <span style=\"color:#89b4fa;\">departments<\/span>(<span style=\"color:#89b4fa;\">id<\/span>)\n        <span style=\"color:#cba6f7;\">ON DELETE CASCADE<\/span>    <span style=\"color:#6c7086;\">-- \u90e8\u7f72\u524a\u9664\u2192\u5f93\u696d\u54e1\u3082\u524a\u9664<\/span>\n        <span style=\"color:#cba6f7;\">ON UPDATE CASCADE<\/span>    <span style=\"color:#6c7086;\">-- \u90e8\u7f72ID\u5909\u66f4\u2192\u5f93\u696d\u54e1\u306e\u53c2\u7167ID\u3082\u5909\u66f4<\/span>\n);\n\n<span style=\"color:#6c7086;\">-- ON DELETE SET NULL\u306e\u4f8b\uff08\u62c5\u5f53\u8005\u524a\u9664\u6642\u306bNULL\u8a2d\u5b9a\uff09<\/span>\n<span style=\"color:#cba6f7;\">CREATE TABLE<\/span> <span style=\"color:#89b4fa;\">tasks<\/span> (\n    <span style=\"color:#89b4fa;\">id<\/span>          <span style=\"color:#fab387;\">INT<\/span> <span style=\"color:#cba6f7;\">PRIMARY KEY<\/span> AUTO_INCREMENT,\n    <span style=\"color:#89b4fa;\">title<\/span>       <span style=\"color:#fab387;\">VARCHAR<\/span>(<span style=\"color:#fab387;\">200<\/span>),\n    <span style=\"color:#89b4fa;\">assignee_id<\/span> <span style=\"color:#fab387;\">INT<\/span>,   <span style=\"color:#6c7086;\">-- NULL\u8a31\u53ef\u5fc5\u9808<\/span>\n    <span style=\"color:#cba6f7;\">FOREIGN KEY<\/span> (<span style=\"color:#89b4fa;\">assignee_id<\/span>) <span style=\"color:#cba6f7;\">REFERENCES<\/span> <span style=\"color:#89b4fa;\">users<\/span>(<span style=\"color:#89b4fa;\">id<\/span>)\n        <span style=\"color:#cba6f7;\">ON DELETE SET NULL<\/span>   <span style=\"color:#6c7086;\">-- \u62c5\u5f53\u8005\u524a\u9664\u2192\u30bf\u30b9\u30af\u306e\u62c5\u5f53\u3092NULL\u306b<\/span>\n);<\/div>\n\n\n\n<div style=\"background:#fff5f5;border-left:4px solid #ef4444;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#ef4444;letter-spacing:1px;\">&#9888;&#65039; CASCADE\u4f7f\u7528\u306f\u614e\u91cd\u306b<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\">ON DELETE CASCADE\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\u30921\u4ef6\u524a\u9664\u3059\u308b\u3060\u3051\u3067\u3001\u305d\u308c\u3092\u53c2\u7167\u3059\u308b\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u304c\u5927\u91cf\u306b\u524a\u9664\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u8aa4\u3063\u3066IMPORTANT\u306a\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3059\u308b\u4e8b\u6545\u306b\u3064\u306a\u304c\u308b\u305f\u3081\u3001CASCADE\u8a2d\u5b9a\u306f\u672c\u5f53\u306b\u5fc5\u8981\u306a\u30b1\u30fc\u30b9\u306b\u9650\u5b9a\u3057\u3001\u666e\u6bb5\u306fRESTRICT\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\uff09\u3092\u4f7f\u3046\u65b9\u304c\u5b89\u5168\u3067\u3059\u3002<\/p>\n<\/div>\n\n\n<div style=\"margin:48px 0 8px;display:flex;gap:12px;justify-content:center;flex-wrap:wrap;\"><a href=\"https:\/\/aikanri.genai-ai.co.jp\/seminar2-blog\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_content=cc-sql-foreign-key&#038;blog_slug=cc-sql-foreign-key\" target=\"_blank\" rel=\"noopener\" aria-label=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff08\u7121\u6599\u30fb1on1\u30fb60\u5206\uff09\u306e\u4e88\u7d04\u753b\u9762\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_seminar_claude_code_2026.jpg\" alt=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff5c\u7d4c\u55b6\u8005\u30fb\u4f1a\u793e\u5f79\u54e1\u5c02\u7528 1on1 60\u5206 \u7121\u6599\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><a href=\"https:\/\/aikanri.genai-ai.co.jp\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_campaign=cc-sql-foreign-key&#038;utm_content=h2-banner-kanri\" target=\"_blank\" rel=\"noopener\" aria-label=\"AI\u9b3c\u7ba1\u7406 \u516c\u5f0f\u30b5\u30a4\u30c8\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_blog_1to1.jpg\" alt=\"Claude Code\u3092\u7d4c\u55b6\u306b\u6d3b\u304b\u3057\u305f\u3044\u65b9\u3078 \u2014 AI\u9b3c\u7ba1\u7406\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-04\">\u5916\u90e8\u30ad\u30fc\u3092\u5f8c\u304b\u3089\u8ffd\u52a0\u3059\u308b\uff1aALTER TABLE ADD FOREIGN KEY<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e2\u5b58\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u5916\u90e8\u30ad\u30fc\u3092\u5f8c\u304b\u3089\u8ffd\u52a0\u3059\u308b\u306b\u306f<code>ALTER TABLE ... ADD FOREIGN KEY<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002\u65e2\u5b58\u30c7\u30fc\u30bf\u306b\u5916\u90e8\u30ad\u30fc\u9055\u53cd\u304c\u3042\u308b\u5834\u5408\u306f\u8ffd\u52a0\u306b\u5931\u6557\u3059\u308b\u305f\u3081\u3001\u4e8b\u524d\u306b\u53c2\u7167\u6574\u5408\u6027\u3092\u78ba\u8a8d\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div style=\"background:#f8f9fa;border-left:4px solid #6b7280;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#6b7280;letter-spacing:1px;\">&#128218; \u7528\u8a9e\u89e3\u8aac<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\"><strong>ALTER TABLE\uff08\u30aa\u30eb\u30bf\u30fc\u30c6\u30fc\u30d6\u30eb\uff09<\/strong>\uff1a\u65e2\u5b58\u306e\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3092\u5909\u66f4\u3059\u308bSQL\u6587\u3002\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\u30fb\u5909\u66f4\u30fb\u524a\u9664\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u8ffd\u52a0\u30fb\u524a\u9664\u3001\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u8ffd\u52a0\u30fb\u524a\u9664\u306a\u3069\u3001\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u5f8c\u306b\u69cb\u9020\u3092\u5909\u66f4\u3059\u308b\u305f\u3081\u306eDDL\u6587\u3067\u3059\u3002\u672c\u756a\u74b0\u5883\u3067\u306e\u5b9f\u884c\u306f\u30c6\u30fc\u30d6\u30eb\u30ed\u30c3\u30af\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6642\u9593\u5e2f\u306b\u884c\u3046\u304b\u3001\u30aa\u30f3\u30e9\u30a4\u30f3DDL\u5bfe\u5fdc\u306eDB\u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<div style=\"background:#1e1e2e;border-radius:10px;padding:20px 24px;margin:20px 0;font-family:monospace;font-size:14px;line-height:1.8;color:#cdd6f4;overflow-x:auto;white-space:pre;\"><span style=\"color:#6c7086;\">-- \u5916\u90e8\u30ad\u30fc\u3092\u5f8c\u304b\u3089\u8ffd\u52a0\u3059\u308b<\/span>\n<span style=\"color:#cba6f7;\">ALTER TABLE<\/span> <span style=\"color:#89b4fa;\">employees<\/span>\n    <span style=\"color:#cba6f7;\">ADD CONSTRAINT<\/span> <span style=\"color:#89b4fa;\">fk_employees_dept<\/span>\n    <span style=\"color:#cba6f7;\">FOREIGN KEY<\/span> (<span style=\"color:#89b4fa;\">department_id<\/span>)\n    <span style=\"color:#cba6f7;\">REFERENCES<\/span> <span style=\"color:#89b4fa;\">departments<\/span>(<span style=\"color:#89b4fa;\">id<\/span>);\n\n<span style=\"color:#6c7086;\">-- \u8ffd\u52a0\u524d\u306b\u6574\u5408\u6027\u30c1\u30a7\u30c3\u30af\uff08\u53c2\u7167\u5148\u306b\u5b58\u5728\u3057\u306a\u3044\u5024\u304c\u306a\u3044\u304b\u78ba\u8a8d\uff09<\/span>\n<span style=\"color:#cba6f7;\">SELECT<\/span> * <span style=\"color:#cba6f7;\">FROM<\/span> <span style=\"color:#89b4fa;\">employees<\/span>\n<span style=\"color:#cba6f7;\">WHERE<\/span> <span style=\"color:#89b4fa;\">department_id<\/span> <span style=\"color:#cba6f7;\">NOT IN<\/span> (<span style=\"color:#cba6f7;\">SELECT<\/span> <span style=\"color:#89b4fa;\">id<\/span> <span style=\"color:#cba6f7;\">FROM<\/span> <span style=\"color:#89b4fa;\">departments<\/span>)\n  <span style=\"color:#cba6f7;\">AND<\/span> <span style=\"color:#89b4fa;\">department_id<\/span> <span style=\"color:#cba6f7;\">IS NOT NULL<\/span>;\n<span style=\"color:#6c7086;\">-- \u3053\u306e\u30af\u30a8\u30ea\u30670\u4ef6\u306a\u3089\u5916\u90e8\u30ad\u30fc\u8ffd\u52a0\u53ef\u80fd<\/span>\n\n<span style=\"color:#6c7086;\">-- \u73fe\u5728\u306e\u5916\u90e8\u30ad\u30fc\u5b9a\u7fa9\u3092\u78ba\u8a8d\u3059\u308b<\/span>\n<span style=\"color:#cba6f7;\">SHOW CREATE TABLE<\/span> <span style=\"color:#89b4fa;\">employees<\/span>\\G<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-05\">\u5916\u90e8\u30ad\u30fc\u3092\u524a\u9664\u3059\u308b\uff1aALTER TABLE DROP FOREIGN KEY<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u524a\u9664\u3059\u308b\u306b\u306f<code>ALTER TABLE ... DROP FOREIGN KEY \u5236\u7d04\u540d<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002\u524a\u9664\u5f8c\u306fFOREIGN KEY\u5236\u7d04\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u304c\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u6b8b\u308b\u305f\u3081\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u5225\u9014\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div style=\"background:#1e1e2e;border-radius:10px;padding:20px 24px;margin:20px 0;font-family:monospace;font-size:14px;line-height:1.8;color:#cdd6f4;overflow-x:auto;white-space:pre;\"><span style=\"color:#6c7086;\">-- \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u540d\u524d\u3092\u78ba\u8a8d\uff08SHOW CREATE TABLE\u3067\u8868\u793a\uff09<\/span>\n<span style=\"color:#cba6f7;\">SHOW CREATE TABLE<\/span> <span style=\"color:#89b4fa;\">employees<\/span>\\G\n\n<span style=\"color:#6c7086;\">-- \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u524a\u9664\uff08\u5236\u7d04\u540d\u304c fk_employees_dept \u306e\u5834\u5408\uff09<\/span>\n<span style=\"color:#cba6f7;\">ALTER TABLE<\/span> <span style=\"color:#89b4fa;\">employees<\/span>\n    <span style=\"color:#cba6f7;\">DROP FOREIGN KEY<\/span> <span style=\"color:#89b4fa;\">fk_employees_dept<\/span>;\n\n<span style=\"color:#6c7086;\">-- \u5916\u90e8\u30ad\u30fc\u524a\u9664\u5f8c\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3082\u4e0d\u8981\u306a\u3089\u524a\u9664<\/span>\n<span style=\"color:#cba6f7;\">ALTER TABLE<\/span> <span style=\"color:#89b4fa;\">employees<\/span>\n    <span style=\"color:#cba6f7;\">DROP INDEX<\/span> <span style=\"color:#89b4fa;\">fk_employees_dept<\/span>;\n\n<span style=\"color:#6c7086;\">-- information_schema\u3067\u5916\u90e8\u30ad\u30fc\u306e\u4e00\u89a7\u3092\u78ba\u8a8d<\/span>\n<span style=\"color:#cba6f7;\">SELECT<\/span>\n    <span style=\"color:#89b4fa;\">CONSTRAINT_NAME<\/span>,\n    <span style=\"color:#89b4fa;\">TABLE_NAME<\/span>,\n    <span style=\"color:#89b4fa;\">COLUMN_NAME<\/span>,\n    <span style=\"color:#89b4fa;\">REFERENCED_TABLE_NAME<\/span>,\n    <span style=\"color:#89b4fa;\">REFERENCED_COLUMN_NAME<\/span>\n<span style=\"color:#cba6f7;\">FROM<\/span> <span style=\"color:#89b4fa;\">information_schema.KEY_COLUMN_USAGE<\/span>\n<span style=\"color:#cba6f7;\">WHERE<\/span> <span style=\"color:#89b4fa;\">TABLE_SCHEMA<\/span> = <span style=\"color:#a6e3a1;\">DATABASE()<\/span>\n  <span style=\"color:#cba6f7;\">AND<\/span> <span style=\"color:#89b4fa;\">REFERENCED_TABLE_NAME<\/span> <span style=\"color:#cba6f7;\">IS NOT NULL<\/span>;<\/div>\n\n\n<div style=\"margin:48px 0 8px;display:flex;gap:12px;justify-content:center;flex-wrap:wrap;\"><a href=\"https:\/\/aikanri.genai-ai.co.jp\/seminar2-blog\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_content=cc-sql-foreign-key&#038;blog_slug=cc-sql-foreign-key\" target=\"_blank\" rel=\"noopener\" aria-label=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff08\u7121\u6599\u30fb1on1\u30fb60\u5206\uff09\u306e\u4e88\u7d04\u753b\u9762\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_seminar_claude_code_2026.jpg\" alt=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff5c\u7d4c\u55b6\u8005\u30fb\u4f1a\u793e\u5f79\u54e1\u5c02\u7528 1on1 60\u5206 \u7121\u6599\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><a href=\"https:\/\/aikanri.genai-ai.co.jp\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_campaign=cc-sql-foreign-key&#038;utm_content=h2-banner-kanri\" target=\"_blank\" rel=\"noopener\" aria-label=\"AI\u9b3c\u7ba1\u7406 \u516c\u5f0f\u30b5\u30a4\u30c8\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_blog_1to1.jpg\" alt=\"Claude Code\u3092\u7d4c\u55b6\u306b\u6d3b\u304b\u3057\u305f\u3044\u65b9\u3078 \u2014 AI\u9b3c\u7ba1\u7406\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-06\">Claude Code\u3067\u5916\u90e8\u30ad\u30fc\u8a2d\u8a08\u30fbSQL\u751f\u6210\u3092\u81ea\u52d5\u5316\u3059\u308b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5916\u90e8\u30ad\u30fc\u8a2d\u8a08\u306f\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u6b63\u78ba\u306b\u628a\u63e1\u3057\u3066\u3044\u306a\u3044\u3068\u30df\u30b9\u304c\u8d77\u304d\u3084\u3059\u3044\u4f5c\u696d\u3067\u3059\u3002Claude Code\u3092\u4f7f\u3048\u3070\u3001\u65e5\u672c\u8a9e\u3067\u30c6\u30fc\u30d6\u30eb\u8a2d\u8a08\u306e\u8981\u4ef6\u3092\u4f1d\u3048\u308b\u3060\u3051\u3067\u3001\u5916\u90e8\u30ad\u30fc\u4ed8\u304d\u306eCREATE TABLE\u6587\u3092\u81ea\u52d5\u751f\u6210\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"g-flow-row\" style=\"display:flex;align-items:center;flex-wrap:wrap;gap:10px;margin:20px 0;padding:20px;background:#f8fafc;border-radius:12px;\">\n<div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">\u8981\u4ef6\u3092\u65e5\u672c\u8a9e\u3067\u8aac\u660e<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">Claude Code\u304c\u8a2d\u8a08<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">SQL\u751f\u6210<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">\u52d5\u4f5c\u78ba\u8a8d<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">\u672c\u756a\u9069\u7528<\/div>\n<\/div>\n\n\n\n<div style=\"background:#1e1e2e;border-radius:10px;padding:20px 24px;margin:20px 0;font-family:monospace;font-size:14px;line-height:1.8;color:#cdd6f4;overflow-x:auto;white-space:pre;\"><span style=\"color:#6c7086;\">\/\/ Claude Code\u3078\u306e\u6307\u793a\u4f8b\uff08\u65e5\u672c\u8a9e\u3067OK\uff09<\/span>\n\n<span style=\"color:#a6e3a1;\">\"EC\u30b5\u30a4\u30c8\u306eDB\u3092\u8a2d\u8a08\u3057\u305f\u3044\u3002\n\u30c6\u30fc\u30d6\u30eb\u69cb\u6210:\n- users\uff08\u30e6\u30fc\u30b6\u30fc\uff09: id, name, email\n- orders\uff08\u6ce8\u6587\uff09: id, user_id, total, created_at\n- order_items\uff08\u6ce8\u6587\u660e\u7d30\uff09: id, order_id, product_id, quantity, price\n- products\uff08\u5546\u54c1\uff09: id, name, price, stock\n\n\u5404\u30c6\u30fc\u30d6\u30eb\u306e\u95a2\u4fc2\u306bFOREIGN KEY\u3092\u8a2d\u5b9a\u3057\u3066\u3002\n\u6ce8\u6587\u524a\u9664\u6642\u306f\u660e\u7d30\u3082\u524a\u9664\uff08CASCADE\uff09\u3002\n\u30e6\u30fc\u30b6\u30fc\u524a\u9664\u6642\u306f\u6ce8\u6587\u306f\u6b8b\u3059\uff08RESTRICT\uff09\u3002\"<\/span>\n\n<span style=\"color:#a6e3a1;\">\"\u5916\u90e8\u30ad\u30fc\u9055\u53cd\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u3044\u308b\u3002\u4ee5\u4e0b\u306eSQL\u6587\u3092\u78ba\u8a8d\u3057\u3066\u539f\u56e0\u3068\u4fee\u6b63\u65b9\u6cd5\u3092\u6559\u3048\u3066:\nINSERT INTO employees (name, department_id) VALUES ('\u7530\u4e2d', 99);\nERROR 1452: Cannot add or update a child row\"<\/span><\/div>\n\n\n\n<div style=\"background:#f0fdf4;border-left:4px solid #22c55e;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#22c55e;letter-spacing:1px;\">&#128161; \u30c6\u30fc\u30d6\u30eb\u8a2d\u8a08\u3082Claude Code\u306b\u76f8\u8ac7\u3067\u304d\u308b<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\">\u300c\u3053\u306e\u30b7\u30b9\u30c6\u30e0\u306b\u5fc5\u8981\u306a\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u308c\u3067\u8db3\u308a\u307e\u3059\u304b\uff1f\u5916\u90e8\u30ad\u30fc\u306e\u8a2d\u5b9a\u306f\u3069\u3046\u3059\u3079\u304d\u3067\u3059\u304b\uff1f\u300d\u3068Claude Code\u306b\u8cea\u554f\u3059\u308c\u3070\u3001\u6b63\u898f\u5316\u306e\u89b3\u70b9\u304b\u3089\u30c6\u30fc\u30d6\u30eb\u8a2d\u8a08\u306e\u6539\u5584\u63d0\u6848\u3082\u53d7\u3051\u3089\u308c\u307e\u3059\u3002\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306eON DELETE\u8a2d\u5b9a\u306b\u3064\u3044\u3066\u3082\u300c\u3069\u3061\u3089\u304c\u9069\u5207\u304b\u300d\u3092\u65e5\u672c\u8a9e\u3067\u76f8\u8ac7\u3059\u308b\u3060\u3051\u3067\u3001\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u5408\u3063\u305f\u7b54\u3048\u3092\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u6574\u5408\u6027\u3092\u4fdd\u8a3c\u3059\u308b\u305f\u3081\u306e\u91cd\u8981\u306a\u6a5f\u80fd\u3067\u3059\u3002\u5358\u306bSQL\u306e\u6587\u6cd5\u3092\u899a\u3048\u308b\u3060\u3051\u3067\u306a\u304f\u3001\u300c\u306a\u305c\u5916\u90e8\u30ad\u30fc\u304c\u5fc5\u8981\u304b\u300d\u300c\u3069\u306e\u30a2\u30af\u30b7\u30e7\u30f3\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u9069\u5207\u304b\u300d\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u5805\u7262\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u304c\u3067\u304d\u307e\u3059\u3002Claude Code\u3092\u6d3b\u7528\u3057\u3066\u52b9\u7387\u3088\u304fSQL\u8a2d\u8a08\u30fb\u5b9f\u88c5\u3092\u9032\u3081\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n<div style=\"margin:48px 0 8px;display:flex;gap:12px;justify-content:center;flex-wrap:wrap;\"><a href=\"https:\/\/aikanri.genai-ai.co.jp\/seminar2-blog\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_content=cc-sql-foreign-key&#038;blog_slug=cc-sql-foreign-key\" target=\"_blank\" rel=\"noopener\" aria-label=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff08\u7121\u6599\u30fb1on1\u30fb60\u5206\uff09\u306e\u4e88\u7d04\u753b\u9762\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_seminar_claude_code_2026.jpg\" alt=\"Claude Code \u5b8c\u5168\u89e3\u8aac\u30bb\u30df\u30ca\u30fc\uff5c\u7d4c\u55b6\u8005\u30fb\u4f1a\u793e\u5f79\u54e1\u5c02\u7528 1on1 60\u5206 \u7121\u6599\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><a href=\"https:\/\/aikanri.genai-ai.co.jp\/?utm_source=blog&#038;utm_medium=h2banner&#038;utm_campaign=cc-sql-foreign-key&#038;utm_content=h2-banner-kanri\" target=\"_blank\" rel=\"noopener\" aria-label=\"AI\u9b3c\u7ba1\u7406 \u516c\u5f0f\u30b5\u30a4\u30c8\u3078\" style=\"flex:1 1 280px;max-width:360px;text-decoration:none;\"><img decoding=\"async\" src=\"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-content\/uploads\/2026\/05\/cta_blog_1to1.jpg\" alt=\"Claude Code\u3092\u7d4c\u55b6\u306b\u6d3b\u304b\u3057\u305f\u3044\u65b9\u3078 \u2014 AI\u9b3c\u7ba1\u7406\" style=\"width:100%;height:auto;border-radius:8px;display:block;\"><\/a><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-07\">\u5916\u90e8\u30ad\u30fc\u95a2\u9023\u306e\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u3068\u5bfe\u51e6\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u3092\u4f7f\u3063\u305f\u958b\u767a\u3067\u306f\u7279\u5b9a\u306e\u30a8\u30e9\u30fc\u304c\u7e70\u308a\u8fd4\u3057\u767a\u751f\u3057\u307e\u3059\u3002\u4ee3\u8868\u7684\u306a\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u3068\u5bfe\u51e6\u6cd5\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"g-flow-row\" style=\"display:flex;align-items:center;flex-wrap:wrap;gap:10px;margin:20px 0;padding:20px;background:#f8fafc;border-radius:12px;\">\n<div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">ERROR 1452<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">ERROR 1451<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">ERROR 1005<\/div><div style=\"font-size:22px;color:#64748b;margin:0 6px;\">&#8594;<\/div><div style=\"background:#1e3a5f;color:#fff;border-radius:8px;padding:12px 18px;font-size:14px;font-weight:600;text-align:center;min-width:120px;\">ERROR 1215<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ERROR 1452: Cannot add or update a child row<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u300c\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3057\u306a\u3044\u5916\u90e8\u30ad\u30fc\u5024\u300d\u3092\u633f\u5165\u30fb\u66f4\u65b0\u3057\u3088\u3046\u3068\u3057\u305f\u3068\u304d\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u5bfe\u51e6\u6cd5\u306f\u633f\u5165\u3059\u308b\u5916\u90e8\u30ad\u30fc\u306e\u5024\u304c\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3059\u308b\u304b\u78ba\u8a8d\u3057\u3001\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u5148\u306b\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u30c6\u30b9\u30c8\u74b0\u5883\u3067\u306f\u300cSET FOREIGN_KEY_CHECKS=0;\u300d\u3067\u4e00\u6642\u7684\u306b\u5916\u90e8\u30ad\u30fc\u30c1\u30a7\u30c3\u30af\u3092\u7121\u52b9\u5316\u3057\u3066\u30c7\u30fc\u30bf\u3092\u6295\u5165\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u672c\u756a\u74b0\u5883\u3067\u306f\u4f7f\u308f\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ERROR 1451: Cannot delete or update a parent row<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u30fb\u66f4\u65b0\u3057\u3088\u3046\u3068\u3057\u305f\u3068\u304d\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u5bfe\u51e6\u6cd5\u306f\u5148\u306b\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u53c2\u7167\u3092\u524a\u9664\u3059\u308b\u304b\u66f4\u65b0\u3059\u308b\u3001\u307e\u305f\u306f\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306eON DELETE\/ON UPDATE\u306bCASCADE\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ERROR 1005: Can't create table \/ ERROR 1215: Cannot add foreign key constraint<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306e\u8a2d\u5b9a\u306b\u554f\u984c\u304c\u3042\u308b\u5834\u5408\u306e\u30a8\u30e9\u30fc\u3067\u3059\u3002\u4e3b\u306a\u539f\u56e0\u306f\u2460\u53c2\u7167\u5148\u30c6\u30fc\u30d6\u30eb\u30fb\u30ab\u30e9\u30e0\u304c\u5b58\u5728\u3057\u306a\u3044\u3001\u2461\u53c2\u7167\u5148\u30ab\u30e9\u30e0\u304cPRIMARY KEY\u30fbUNIQUE\u3067\u306a\u3044\u3001\u2462\u30c7\u30fc\u30bf\u578b\u304c\u4e00\u81f4\u3057\u306a\u3044\uff08INT\u3068BIGINT\u7b49\u306e\u4e0d\u4e00\u81f4\uff09\u3001\u2463\u6587\u5b57\u30bb\u30c3\u30c8\u30fb\u7167\u5408\u9806\u5e8f\u304c\u7570\u306a\u308b\u3001\u306e\u3044\u305a\u308c\u304b\u3067\u3059\u3002SHOW ENGINE INNODB STATUS\\G\u30b3\u30de\u30f3\u30c9\u3067\u8a73\u7d30\u306a\u30a8\u30e9\u30fc\u60c5\u5831\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<ul style=\"list-style:none;padding:0;margin:16px 0;background:#f8fafc;border-radius:8px;padding:16px 20px;\">\n<li style=\"padding:6px 0;border-bottom:1px solid #e2e8f0;\">&#x2705; \u5916\u90e8\u30ad\u30fc\u8ffd\u52a0\u524d\u306b\u53c2\u7167\u5148\u30c6\u30fc\u30d6\u30eb\u3068\u53c2\u7167\u5148\u30ab\u30e9\u30e0\u304c\u5b58\u5728\u3059\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b<\/li><li style=\"padding:6px 0;border-bottom:1px solid #e2e8f0;\">&#x2705; \u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u3068\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u53c2\u7167\u30ab\u30e9\u30e0\u306e\u30c7\u30fc\u30bf\u578b\u3092\u4e00\u81f4\u3055\u305b\u308b<\/li><li style=\"padding:6px 0;border-bottom:1px solid #e2e8f0;\">&#x2705; CASCADE\u8a2d\u5b9a\u3092\u4f7f\u3046\u3068\u304d\u306f\u524a\u9664\u30fb\u66f4\u65b0\u306e\u5f71\u97ff\u7bc4\u56f2\u3092\u4e8b\u524d\u306b\u628a\u63e1\u3059\u308b<\/li><li style=\"padding:6px 0;border-bottom:1px solid #e2e8f0;\">&#x2705; \u5916\u90e8\u30ad\u30fc\u5236\u7d04\u540d\uff08CONSTRAINT\u540d\uff09\u306fDB\u5185\u3067\u30e6\u30cb\u30fc\u30af\u306b\u3059\u308b<\/li><li style=\"padding:6px 0;border-bottom:1px solid #e2e8f0;\">&#x2705; \u958b\u767a\u74b0\u5883\u3067\u306e\u4e00\u6642\u7684\u306a\u5916\u90e8\u30ad\u30fc\u7121\u52b9\u5316\u306fSET FOREIGN_KEY_CHECKS=0\u3092\u4f7f\u3046\uff08\u672c\u756a\u7981\u6b62\uff09<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq\">\u3088\u304f\u3042\u308b\u8cea\u554f<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Q. SQL\u306e\u5916\u90e8\u30ad\u30fc\u3068\u306f\u4f55\u3067\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A. \u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u306f\u3001\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u306e\u30ab\u30e9\u30e0\u304c\u5225\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u3092\u53c2\u7167\u3059\u308b\u3068\u3044\u3046\u95a2\u4fc2\u3092\u5b9a\u7fa9\u3059\u308bSQL\u5236\u7d04\u3067\u3059\u3002\u300c\u53c2\u7167\u5148\u306b\u5b58\u5728\u3057\u306a\u3044\u5024\u306f\u767b\u9332\u3067\u304d\u306a\u3044\u300d\u300c\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306f\u524a\u9664\u3067\u304d\u306a\u3044\u300d\u3068\u3044\u3046\u53c2\u7167\u6574\u5408\u6027\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u81ea\u52d5\u7684\u306b\u4fdd\u8a3c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q. \u5916\u90e8\u30ad\u30fc\u306eON DELETE CASCADE\u306f\u3069\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u4f7f\u3044\u307e\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A. \u89aa\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3057\u305f\u3068\u304d\u3001\u305d\u308c\u3092\u53c2\u7167\u3059\u308b\u5b50\u30ec\u30b3\u30fc\u30c9\u3082\u4e00\u7dd2\u306b\u524a\u9664\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u3044\u307e\u3059\u3002\u6ce8\u6587\u30c6\u30fc\u30d6\u30eb\u3092\u524a\u9664\u3059\u308b\u3068\u6ce8\u6587\u660e\u7d30\u30c6\u30fc\u30d6\u30eb\u3082\u524a\u9664\u3059\u308b\u3001\u3068\u3044\u3063\u305f\u30b1\u30fc\u30b9\u306b\u9069\u3057\u3066\u3044\u307e\u3059\u3002\u305f\u3060\u3057\u610f\u56f3\u305b\u305a\u5927\u91cf\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3059\u308b\u4e8b\u6545\u306e\u30ea\u30b9\u30af\u304c\u3042\u308b\u305f\u3081\u3001\u4f7f\u7528\u306f\u614e\u91cd\u306b\u5224\u65ad\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q. \u5916\u90e8\u30ad\u30fc\u3092\u5f8c\u304b\u3089\u8ffd\u52a0\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A. ALTER TABLE \u30c6\u30fc\u30d6\u30eb\u540d ADD CONSTRAINT \u5236\u7d04\u540d FOREIGN KEY (\u30ab\u30e9\u30e0\u540d) REFERENCES \u89aa\u30c6\u30fc\u30d6\u30eb(\u30ab\u30e9\u30e0\u540d);\u3067\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002\u8ffd\u52a0\u524d\u306b\u65e2\u5b58\u30c7\u30fc\u30bf\u304c\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306b\u9055\u53cd\u3057\u3066\u3044\u306a\u3044\u304b\u78ba\u8a8d\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q. \u5916\u90e8\u30ad\u30fc\u3092\u524a\u9664\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A. ALTER TABLE \u30c6\u30fc\u30d6\u30eb\u540d DROP FOREIGN KEY \u5236\u7d04\u540d;\u3067\u524a\u9664\u3067\u304d\u307e\u3059\u3002\u5236\u7d04\u540d\u306fSHOW CREATE TABLE \u30c6\u30fc\u30d6\u30eb\u540d\\G\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u5916\u90e8\u30ad\u30fc\u524a\u9664\u5f8c\u3082\u81ea\u52d5\u4f5c\u6210\u3055\u308c\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u6b8b\u308b\u305f\u3081\u3001\u4e0d\u8981\u3067\u3042\u308c\u3070ALTER TABLE \u30c6\u30fc\u30d6\u30eb\u540d DROP INDEX \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u540d;\u3067\u5225\u9014\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q. ERROR 1452\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u3069\u3046\u5bfe\u51e6\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A. ERROR 1452\u306f\u300c\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3057\u306a\u3044\u5916\u90e8\u30ad\u30fc\u5024\u3092\u633f\u5165\u3057\u3088\u3046\u3068\u3057\u305f\u300d\u30a8\u30e9\u30fc\u3067\u3059\u3002\u633f\u5165\u3059\u308b\u5916\u90e8\u30ad\u30fc\u306e\u5024\u304c\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3059\u308b\u304b\u78ba\u8a8d\u3057\u3001\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u5148\u306b\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u304b\u3089\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u633f\u5165\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [\n    {\n      \"@type\": \"Question\",\n      \"name\": \"SQL\u306e\u5916\u90e8\u30ad\u30fc\u3068\u306f\u4f55\u3067\u3059\u304b\uff1f\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u306f\u3001\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u306e\u30ab\u30e9\u30e0\u304c\u5225\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u3092\u53c2\u7167\u3059\u308b\u3068\u3044\u3046\u95a2\u4fc2\u3092\u5b9a\u7fa9\u3059\u308bSQL\u5236\u7d04\u3067\u3059\u3002\u300c\u53c2\u7167\u5148\u306b\u5b58\u5728\u3057\u306a\u3044\u5024\u306f\u767b\u9332\u3067\u304d\u306a\u3044\u300d\u300c\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306f\u524a\u9664\u3067\u304d\u306a\u3044\u300d\u3068\u3044\u3046\u53c2\u7167\u6574\u5408\u6027\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u81ea\u52d5\u7684\u306b\u4fdd\u8a3c\u3057\u307e\u3059\u3002\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"\u5916\u90e8\u30ad\u30fc\u306eON DELETE CASCADE\u306f\u3069\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u4f7f\u3044\u307e\u3059\u304b\uff1f\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"\u89aa\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3057\u305f\u3068\u304d\u3001\u305d\u308c\u3092\u53c2\u7167\u3059\u308b\u5b50\u30ec\u30b3\u30fc\u30c9\u3082\u4e00\u7dd2\u306b\u524a\u9664\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u3044\u307e\u3059\u3002\u6ce8\u6587\u30c6\u30fc\u30d6\u30eb\u3092\u524a\u9664\u3059\u308b\u3068\u6ce8\u6587\u660e\u7d30\u30c6\u30fc\u30d6\u30eb\u3082\u524a\u9664\u3059\u308b\u3001\u3068\u3044\u3063\u305f\u30b1\u30fc\u30b9\u306b\u9069\u3057\u3066\u3044\u307e\u3059\u3002\u305f\u3060\u3057\u610f\u56f3\u305b\u305a\u5927\u91cf\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3059\u308b\u4e8b\u6545\u306e\u30ea\u30b9\u30af\u304c\u3042\u308b\u305f\u3081\u3001\u4f7f\u7528\u306f\u614e\u91cd\u306b\u5224\u65ad\u3057\u3066\u304f\u3060\u3055\u3044\u3002\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"\u5916\u90e8\u30ad\u30fc\u3092\u5f8c\u304b\u3089\u8ffd\u52a0\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"ALTER TABLE \u30c6\u30fc\u30d6\u30eb\u540d ADD CONSTRAINT \u5236\u7d04\u540d FOREIGN KEY (\u30ab\u30e9\u30e0\u540d) REFERENCES \u89aa\u30c6\u30fc\u30d6\u30eb(\u30ab\u30e9\u30e0\u540d);\u3067\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002\u8ffd\u52a0\u524d\u306b\u65e2\u5b58\u30c7\u30fc\u30bf\u304c\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u306b\u9055\u53cd\u3057\u3066\u3044\u306a\u3044\u304b\u78ba\u8a8d\u304c\u5fc5\u8981\u3067\u3059\u3002\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"\u5916\u90e8\u30ad\u30fc\u3092\u524a\u9664\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"ALTER TABLE \u30c6\u30fc\u30d6\u30eb\u540d DROP FOREIGN KEY \u5236\u7d04\u540d;\u3067\u524a\u9664\u3067\u304d\u307e\u3059\u3002\u5236\u7d04\u540d\u306fSHOW CREATE TABLE \u30c6\u30fc\u30d6\u30eb\u540d\\\\G\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u5916\u90e8\u30ad\u30fc\u524a\u9664\u5f8c\u3082\u81ea\u52d5\u4f5c\u6210\u3055\u308c\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u6b8b\u308b\u305f\u3081\u3001\u4e0d\u8981\u3067\u3042\u308c\u3070ALTER TABLE \u30c6\u30fc\u30d6\u30eb\u540d DROP INDEX \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u540d;\u3067\u5225\u9014\u524a\u9664\u3057\u307e\u3059\u3002\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"ERROR 1452\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u3069\u3046\u5bfe\u51e6\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"ERROR 1452\u306f\u300c\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3057\u306a\u3044\u5916\u90e8\u30ad\u30fc\u5024\u3092\u633f\u5165\u3057\u3088\u3046\u3068\u3057\u305f\u300d\u30a8\u30e9\u30fc\u3067\u3059\u3002\u633f\u5165\u3059\u308b\u5916\u90e8\u30ad\u30fc\u306e\u5024\u304c\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u5b58\u5728\u3059\u308b\u304b\u78ba\u8a8d\u3057\u3001\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f\u5148\u306b\u89aa\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u304b\u3089\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u633f\u5165\u3057\u3066\u304f\u3060\u3055\u3044\u3002\"\n      }\n    }\n  ]\n}\n<\/script>\n\n\n\n<div style=\"background:#f8f9fa;border-left:4px solid #6b7280;border-radius:0 8px 8px 0;padding:16px 20px;margin:20px 0;\">\n  <p style=\"margin:0 0 4px;font-size:13px;font-weight:700;color:#6b7280;letter-spacing:1px;\">&#128218; \u7528\u8a9e\u89e3\u8aac<\/p>\n  <p style=\"margin:0;font-size:15px;line-height:1.7;\"><strong>\u53c2\u7167\u6574\u5408\u6027\uff08Referential Integrity\uff09<\/strong>\uff1a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u304a\u3051\u308b\u30c7\u30fc\u30bf\u306e\u4e00\u8cab\u6027\u539f\u5247\u306e\u4e00\u3064\u3002\u5916\u90e8\u30ad\u30fc\u3067\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\u306f\u5fc5\u305a\u53c2\u7167\u5148\u30c6\u30fc\u30d6\u30eb\u306b\u5b9f\u969b\u306b\u5b58\u5728\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3001\u3068\u3044\u3046\u5236\u7d04\u3067\u3059\u3002\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5074\u306e\u30d0\u30b0\u3084\u64cd\u4f5c\u30df\u30b9\u306b\u3088\u3063\u3066\u30c7\u30fc\u30bf\u304c\u4e0d\u6574\u5408\u306b\u306a\u308b\u3053\u3068\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a8\u30f3\u30b8\u30f3\u304c\u81ea\u52d5\u7684\u306b\u9632\u304e\u307e\u3059\u3002\u3053\u306e\u5236\u7d04\u304c\u306a\u3044\u3068\u300c\u5b58\u5728\u3057\u306a\u3044\u90e8\u7f72ID\u300d\u3092\u6301\u3064\u5f93\u696d\u54e1\u30ec\u30b3\u30fc\u30c9\u304c\u84c4\u7a4d\u3055\u308c\u308b\u306a\u3069\u3001\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u56f0\u96e3\u306a\u30c7\u30fc\u30bf\u6c5a\u67d3\u304c\u8d77\u304d\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<h3 style=\"font-size:18px;font-weight:700;margin:32px 0 16px;padding-left:12px;border-left:4px solid #7c3aed;\">\u5916\u90e8\u30ad\u30fc\u306e\u8a2d\u8a08\u30d1\u30bf\u30fc\u30f3\uff1a\u5b9f\u52d9\u3067\u3088\u304f\u4f7f\u3046\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u8a2d\u8a08<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9f\u969b\u306e\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u3067\u5916\u90e8\u30ad\u30fc\u3092\u4f7f\u3046\u3068\u304d\u306b\u3088\u304f\u767b\u5834\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u308c\u3089\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u7406\u89e3\u3057\u3066\u304a\u304f\u3068\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u306e\u901f\u5ea6\u3068\u54c1\u8cea\u304c\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u30d1\u30bf\u30fc\u30f31\uff1a1\u5bfe\u591a\uff08One-to-Many\uff09\u306e\u95a2\u4fc2<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u3082\u3088\u304f\u4f7f\u308f\u308c\u308b\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u30011\u3064\u306e\u89aa\u30ec\u30b3\u30fc\u30c9\u306b\u5bfe\u3057\u3066\u8907\u6570\u306e\u5b50\u30ec\u30b3\u30fc\u30c9\u304c\u5b58\u5728\u3057\u307e\u3059\u3002\u90e8\u7f72\uff081\uff09\u3068\u5f93\u696d\u54e1\uff08\u591a\uff09\u3001\u30e6\u30fc\u30b6\u30fc\uff081\uff09\u3068\u6ce8\u6587\uff08\u591a\uff09\u3001\u30ab\u30c6\u30b4\u30ea\uff081\uff09\u3068\u5546\u54c1\uff08\u591a\uff09\u306a\u3069\u304c\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u306b\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u4e3b\u30ad\u30fc\u3092\u683c\u7d0d\u3057\u307e\u3059\u3002EC\u30b5\u30a4\u30c8\u3067\u3042\u308c\u3070\u300c\u30e6\u30fc\u30b6\u30fc\u306f\u8907\u6570\u306e\u6ce8\u6587\u3092\u6301\u3066\u308b\u3002\u6ce8\u6587\u306f1\u4eba\u306e\u30e6\u30fc\u30b6\u30fc\u306b\u7d10\u4ed8\u304f\u300d\u3068\u3044\u30461\u5bfe\u591a\u306e\u95a2\u4fc2\u3092\u3001orders.user_id\u306bFOREIGN KEY\u5236\u7d04\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u8868\u73fe\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u30d1\u30bf\u30fc\u30f32\uff1a\u591a\u5bfe\u591a\uff08Many-to-Many\uff09\u306e\u95a2\u4fc2<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b66\u751f\u3068\u79d1\u76ee\uff081\u4eba\u306e\u5b66\u751f\u304c\u8907\u6570\u306e\u79d1\u76ee\u3092\u53d7\u8b1b\u3057\u30011\u3064\u306e\u79d1\u76ee\u3092\u8907\u6570\u306e\u5b66\u751f\u304c\u53d7\u8b1b\u3059\u308b\uff09\u306e\u3088\u3046\u306a\u591a\u5bfe\u591a\u306e\u95a2\u4fc2\u306f\u3001\u76f4\u63a5\u5916\u90e8\u30ad\u30fc\u3067\u306f\u8868\u73fe\u3067\u304d\u307e\u305b\u3093\u3002\u300c\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\uff08\u95a2\u9023\u30c6\u30fc\u30d6\u30eb\u30fb\u63a5\u5408\u30c6\u30fc\u30d6\u30eb\uff09\u300d\u3092\u8a2d\u3051\u3066\u3001\u305d\u306e\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u4e21\u65b9\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u305f\u3068\u3048\u3070student_courses\u30c6\u30fc\u30d6\u30eb\u306bstudent_id\u3068course_id\u306e2\u30ab\u30e9\u30e0\u3092\u6301\u3061\u3001\u305d\u308c\u305e\u308c\u306bFOREIGN KEY\u5236\u7d04\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u306f\u30bf\u30b0\u7ba1\u7406\uff08\u8a18\u4e8b\u3068\u30bf\u30b0\uff09\u3001\u6a29\u9650\u7ba1\u7406\uff08\u30e6\u30fc\u30b6\u30fc\u3068\u30ed\u30fc\u30eb\uff09\u306a\u3069\u5e45\u5e83\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u30d1\u30bf\u30fc\u30f33\uff1a\u81ea\u5df1\u53c2\u7167\uff08Self-Referencing\uff09\u306e\u95a2\u4fc2<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u4e00\u30c6\u30fc\u30d6\u30eb\u5185\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u4ed6\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u53c2\u7167\u3059\u308b\u69cb\u9020\u3067\u3059\u3002\u7d44\u7e54\u306e\u4e0a\u4e0b\u95a2\u4fc2\uff08\u7ba1\u7406\u8005\u3068\u90e8\u4e0b\uff09\u3001\u30ab\u30c6\u30b4\u30ea\u306e\u89aa\u5b50\u95a2\u4fc2\uff08\u30e1\u30cb\u30e5\u30fc\u306e\u968e\u5c64\u69cb\u9020\uff09\u3001\u30b3\u30e1\u30f3\u30c8\u306e\u8fd4\u4fe1\u69cb\u9020\u306a\u3069\u3067\u4f7f\u308f\u308c\u307e\u3059\u3002employees\u30c6\u30fc\u30d6\u30eb\u306bmanager_id\u30ab\u30e9\u30e0\u3092\u8a2d\u3051\u3066\u3001\u540c\u3058employees\u30c6\u30fc\u30d6\u30eb\u306eid\u3092\u53c2\u7167\u3059\u308b\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u81ea\u5df1\u53c2\u7167\u306e\u5916\u90e8\u30ad\u30fc\u306fCASCADE\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u30c7\u30fc\u30bf\u524a\u9664\u304c\u9023\u9396\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u614e\u91cd\u306b\u8a2d\u8a08\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3 style=\"font-size:18px;font-weight:700;margin:32px 0 16px;padding-left:12px;border-left:4px solid #059669;\">\u5916\u90e8\u30ad\u30fc\u3092\u4f7f\u308f\u306a\u3044\u8a2d\u8a08\u306e\u8003\u3048\u65b9\u3068\u4f7f\u3044\u5206\u3051<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u306f\u30c7\u30fc\u30bf\u6574\u5408\u6027\u3092\u4fdd\u8a3c\u3059\u308b\u5f37\u529b\u306a\u6a5f\u80fd\u3067\u3059\u304c\u3001\u3059\u3079\u3066\u306e\u30b1\u30fc\u30b9\u3067\u4f7f\u3046\u3079\u304d\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u4f7f\u308f\u306a\u3044\u8a2d\u8a08\u304c\u9078\u629e\u3055\u308c\u308b\u7406\u7531\u3068\u3001\u305d\u306e\u5224\u65ad\u57fa\u6e96\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u3092\u4f7f\u308f\u306a\u3044\u4e3b\u306a\u7406\u7531\u306e\u4e00\u3064\u306f\u300c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u300d\u3067\u3059\u3002\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u3068\u3001INSERT\u3084UPDATE\u30fbDELETE\u6642\u306b\u53c2\u7167\u5148\u30c6\u30fc\u30d6\u30eb\u306e\u78ba\u8a8d\u30af\u30a8\u30ea\u304c\u5185\u90e8\u7684\u306b\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u5927\u91cf\u30c7\u30fc\u30bf\u3092\u9ad8\u901f\u306bINSERT\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\uff08\u30d0\u30c3\u30c1\u51e6\u7406\u30fb\u30c7\u30fc\u30bf\u79fb\u884c\u7b49\uff09\u306f\u3001\u5916\u90e8\u30ad\u30fc\u30c1\u30a7\u30c3\u30af\u304c\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002MySQL\u3067\u306f\u300cSET FOREIGN_KEY_CHECKS=0;\u300d\u3067\u4e00\u6642\u7684\u306b\u7121\u52b9\u5316\u3067\u304d\u3001\u51e6\u7406\u5f8c\u306b\u300cSET FOREIGN_KEY_CHECKS=1;\u300d\u3067\u518d\u5ea6\u6709\u52b9\u5316\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3053\u306e\u9593\u306f\u6574\u5408\u6027\u304c\u4fdd\u8a3c\u3055\u308c\u306a\u3044\u305f\u3081\u3001\u30c7\u30fc\u30bf\u6295\u5165\u5f8c\u306e\u691c\u8a3c\u304c\u5fc5\u9808\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3082\u3046\u4e00\u3064\u306e\u7406\u7531\u306f\u300c\u30b9\u30b1\u30fc\u30eb\u30a2\u30a6\u30c8\u8a2d\u8a08\u300d\u3067\u3059\u3002\u30b7\u30e3\u30fc\u30c7\u30a3\u30f3\u30b0\uff08\u6c34\u5e73\u5206\u5272\uff09\u3084\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067\u306f\u3001\u95a2\u9023\u30c6\u30fc\u30d6\u30eb\u304c\u5225\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b5\u30fc\u30d0\u30fc\u306b\u5b58\u5728\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u5834\u5408\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a8\u30f3\u30b8\u30f3\u30ec\u30d9\u30eb\u306e\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u304c\u52b9\u304b\u306a\u3044\u305f\u3081\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5c64\u3067\u306e\u6574\u5408\u6027\u30c1\u30a7\u30c3\u30af\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002NoSQL\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08MongoDB\u306a\u3069\uff09\u3067\u306f\u5916\u90e8\u30ad\u30fc\u306e\u6982\u5ff5\u304c\u306a\u3044\u305f\u3081\u3001\u6574\u5408\u6027\u7dad\u6301\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5074\u3067\u5b8c\u5168\u306b\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c0f\u898f\u6a21\u304b\u3089\u4e2d\u898f\u6a21\u306e\u30b7\u30b9\u30c6\u30e0\u3067\u3042\u308c\u3070\u5916\u90e8\u30ad\u30fc\u3092\u7a4d\u6975\u7684\u306b\u4f7f\u3046\u3053\u3068\u3067\u30c7\u30fc\u30bf\u54c1\u8cea\u304c\u683c\u6bb5\u306b\u5411\u4e0a\u3057\u307e\u3059\u3002\u30b9\u30b1\u30fc\u30eb\u3084\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u8981\u4ef6\u304c\u9ad8\u3044\u5834\u5408\u306f\u5916\u90e8\u30ad\u30fc\u3092\u5916\u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5074\u3067\u7ba1\u7406\u3059\u308b\u30a2\u30d7\u30ed\u30fc\u30c1\u3082\u6709\u52b9\u3067\u3059\u3002Claude Code\u306b\u300c\u3053\u306e\u30b7\u30b9\u30c6\u30e0\u306b\u5916\u90e8\u30ad\u30fc\u3092\u4f7f\u3046\u3079\u304d\u304b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5c64\u3067\u7ba1\u7406\u3059\u3079\u304d\u304b\u300d\u3068\u76f8\u8ac7\u3059\u308b\u3053\u3068\u3067\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u898f\u6a21\u30fb\u8981\u4ef6\u306b\u5408\u3063\u305f\u5224\u65ad\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u306fSQL\u8a2d\u8a08\u306b\u304a\u3051\u308b\u91cd\u8981\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002FOREIGN KEY\u5236\u7d04\u306e\u4f5c\u6210\u30fbON DELETE\/ON UPDATE\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u4f7f\u3044\u5206\u3051\u30fbALTER TABLE\u3067\u306e\u5f8c\u4ed8\u3051\u8ffd\u52a0\u30fbDROP FOREIGN KEY\u3067\u306e\u524a\u9664\u3068\u3044\u3046\u4e00\u9023\u306e\u64cd\u4f5c\u3092\u8eab\u306b\u3064\u3051\u3001\u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u3092\u4fdd\u8a3c\u3059\u308b\u5805\u7262\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u3092\u5b9f\u73fe\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u5916\u90e8\u30ad\u30fc\u95a2\u9023\u306e\u30a8\u30e9\u30fc\u5bfe\u51e6\u3082Claude Code\u306b\u8cea\u554f\u3059\u308b\u3060\u3051\u3067\u7684\u78ba\u306a\u89e3\u6c7a\u7b56\u3092\u63d0\u6848\u3057\u3066\u3082\u3089\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<h3 style=\"font-size:18px;font-weight:700;margin:32px 0 16px;padding-left:12px;border-left:4px solid #dc2626;\">\u5916\u90e8\u30ad\u30fc\u3068\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u95a2\u4fc2\uff1a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u3092\u7406\u89e3\u3059\u308b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL\u306eInnoDB\u30a8\u30f3\u30b8\u30f3\u3067\u306f\u3001\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u306b\u81ea\u52d5\u7684\u306b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f\u53c2\u7167\u6574\u5408\u6027\u30c1\u30a7\u30c3\u30af\u306e\u305f\u3081\u306bInnoDB\u304c\u5185\u90e8\u7684\u306b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u5fc5\u8981\u3068\u3059\u308b\u305f\u3081\u3067\u3059\u3002\u3053\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u30af\u30a8\u30ea\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5411\u4e0a\u306b\u3082\u8ca2\u732e\u3057\u307e\u3059\u304c\u3001\u30c6\u30fc\u30d6\u30eb\u306e\u30b9\u30c8\u30ec\u30fc\u30b8\u30b5\u30a4\u30ba\u304c\u5897\u52a0\u3059\u308b\u3053\u3068\u3092\u7406\u89e3\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u306bJOIN\u3092\u983b\u7e41\u306b\u4f7f\u3046\u5834\u5408\u306f\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u5b58\u5728\u3059\u308b\u3053\u3068\u3067\u5927\u304d\u306a\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5411\u4e0a\u304c\u671f\u5f85\u3067\u304d\u307e\u3059\u3002\u300cSELECT * FROM employees e JOIN departments d ON e.department_id = d.id;\u300d\u306e\u3088\u3046\u306aJOIN\u30af\u30a8\u30ea\u3067\u306f\u3001department_id\u30ab\u30e9\u30e0\u306b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u3042\u308b\u3053\u3068\u3067\u5168\u4ef6\u30b9\u30ad\u30e3\u30f3\u3092\u907f\u3051\u3089\u308c\u307e\u3059\u3002\u5916\u90e8\u30ad\u30fc\u306e\u81ea\u52d5\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u3053\u3046\u3057\u305fJOIN\u306e\u9ad8\u901f\u5316\u306b\u76f4\u63a5\u8ca2\u732e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305f\u3060\u3057\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u3092\u524a\u9664\u3057\u3066\u3082\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u81ea\u52d5\u7684\u306b\u524a\u9664\u3055\u308c\u307e\u305b\u3093\u3002\u5916\u90e8\u30ad\u30fc\u304c\u4e0d\u8981\u306b\u306a\u3063\u305f\u5834\u5408\u306fDROP FOREIGN KEY\u3067\u5236\u7d04\u3092\u524a\u9664\u3057\u3001\u3055\u3089\u306bDROP INDEX\u3067\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3082\u524a\u9664\u3059\u308b2\u30b9\u30c6\u30c3\u30d7\u304c\u5fc5\u8981\u3067\u3059\u3002\u9006\u306b\u5916\u90e8\u30ad\u30fc\u524a\u9664\u5f8c\u3082JOIN\u304c\u983b\u7e41\u306b\u884c\u308f\u308c\u308b\u30ab\u30e9\u30e0\u3067\u3042\u308c\u3070\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u6b8b\u3057\u3066\u304a\u3044\u305f\u65b9\u304c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u4e0a\u6709\u5229\u3067\u3059\u3002\u3053\u306e\u5224\u65ad\u306f\u30c6\u30fc\u30d6\u30eb\u306e\u5229\u7528\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u30b1\u30fc\u30b9\u30d0\u30a4\u30b1\u30fc\u30b9\u3067\u884c\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3 style=\"font-size:18px;font-weight:700;margin:32px 0 16px;padding-left:12px;border-left:4px solid #1e3a5f;\">\u5916\u90e8\u30ad\u30fc\u8a2d\u8a08\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u307e\u3068\u3081<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u3092\u6b63\u3057\u304f\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u6574\u7406\u3057\u307e\u3059\u3002\u3053\u308c\u3089\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u3067\u3001\u4fdd\u5b88\u6027\u3068\u4fe1\u983c\u6027\u306e\u9ad8\u3044\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u304c\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u307e\u305a\u300c\u547d\u540d\u898f\u5247\u3092\u7d71\u4e00\u3059\u308b\u300d\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u5916\u90e8\u30ad\u30fc\u5236\u7d04\u540d\u306ffk_\uff08\u30c6\u30fc\u30d6\u30eb\u540d\uff09_\uff08\u30ab\u30e9\u30e0\u540d\uff09\u306e\u5f62\u5f0f\u3067\u7d71\u4e00\u3059\u308b\u3053\u3068\u3067\u3001SHOW CREATE TABLE\u306e\u51fa\u529b\u3084\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304b\u3089\u5236\u7d04\u306e\u5185\u5bb9\u3092\u5373\u5ea7\u306b\u628a\u63e1\u3067\u304d\u307e\u3059\u3002\u30c1\u30fc\u30e0\u958b\u767a\u3067\u306f\u547d\u540d\u898f\u5247\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u7528\u610f\u3057\u3001\u5168\u54e1\u304c\u540c\u3058\u5f62\u5f0f\u3067\u5236\u7d04\u540d\u3092\u3064\u3051\u308b\u3053\u3068\u3092\u5fb9\u5e95\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b21\u306b\u300cON DELETE\/ON UPDATE\u306f\u660e\u793a\u7684\u306b\u6307\u5b9a\u3059\u308b\u300d\u7fd2\u6163\u3092\u3064\u3051\u3066\u304f\u3060\u3055\u3044\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306eRESTRICT\uff08NO ACTION\uff09\u306e\u307e\u307e\u3067\u554f\u984c\u306a\u3044\u30b1\u30fc\u30b9\u3082\u591a\u3044\u3067\u3059\u304c\u3001\u610f\u56f3\u3092\u660e\u78ba\u306b\u3059\u308b\u305f\u3081\u306b\u3082\u660e\u793a\u7684\u306b\u6307\u5b9a\u3059\u308b\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002\u7279\u306bCASCADE\u306f\u5f71\u97ff\u7bc4\u56f2\u304c\u5927\u304d\u3044\u305f\u3081\u3001\u8a2d\u5b9a\u6642\u306b\u300c\u3053\u306e\u89aa\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u305f\u3068\u304d\u4f55\u4ef6\u306e\u5b50\u30c7\u30fc\u30bf\u304c\u524a\u9664\u3055\u308c\u308b\u304b\u300d\u3092\u4e8b\u524d\u306b\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u307e\u305f\u300c\u5916\u90e8\u30ad\u30fc\u306e\u30c7\u30fc\u30bf\u578b\u3092\u5fc5\u305a\u4e00\u81f4\u3055\u305b\u308b\u300d\u3053\u3068\u3082\u91cd\u8981\u3067\u3059\u3002\u89aa\u30c6\u30fc\u30d6\u30eb\u306e\u53c2\u7167\u30ab\u30e9\u30e0\u304cINT\uff08\u7b26\u53f7\u3042\u308a\uff09\u306e\u5834\u5408\u3001\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u5916\u90e8\u30ad\u30fc\u30ab\u30e9\u30e0\u3082INT\uff08\u7b26\u53f7\u3042\u308a\uff09\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002BIGINT\u3068INT\u306e\u7d44\u307f\u5408\u308f\u305b\u3001\u307e\u305f\u306funsigned\u3068signed\u306e\u4e0d\u4e00\u81f4\u306f\u30a8\u30e9\u30fc1215\u306e\u539f\u56e0\u306b\u306a\u308a\u307e\u3059\u3002\u8a2d\u8a08\u6bb5\u968e\u3067\u30c7\u30fc\u30bf\u578b\u3092\u63c3\u3048\u308b\u3053\u3068\u3067\u3001\u5f8c\u4ed8\u3051\u5916\u90e8\u30ad\u30fc\u8a2d\u5b9a\u3067\u306e\u30c8\u30e9\u30d6\u30eb\u3092\u9632\u3052\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u306b\u304a\u3044\u3066\u300c\u30c7\u30fc\u30bf\u306e\u4fe1\u983c\u6027\u3092\u4fdd\u8a3c\u3059\u308b\u57fa\u76e4\u300d\u3068\u3057\u3066\u6a5f\u80fd\u3057\u307e\u3059\u3002\u9069\u5207\u306b\u8a2d\u5b9a\u3055\u308c\u305f\u5916\u90e8\u30ad\u30fc\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d0\u30b0\u3084\u904b\u7528\u30df\u30b9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u5b88\u308a\u3001\u9577\u671f\u306b\u308f\u305f\u3063\u3066\u30b7\u30b9\u30c6\u30e0\u3092\u5b89\u5b9a\u7a3c\u50cd\u3055\u305b\u308b\u529b\u306b\u306a\u308a\u307e\u3059\u3002\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3057\u306a\u3044\u30b7\u30b9\u30c6\u30e0\u3067\u306f\u3001\u6642\u9593\u306e\u7d4c\u904e\u3068\u3068\u3082\u306b\u5b64\u7acb\u3057\u305f\u30ec\u30b3\u30fc\u30c9\uff08orphan records\uff09\u304c\u84c4\u7a4d\u3057\u3001\u30c7\u30fc\u30bf\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u306b\u591a\u5927\u306a\u5de5\u6570\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002CREATE TABLE\u3067\u306e\u5916\u90e8\u30ad\u30fc\u5b9a\u7fa9\u3001ALTER TABLE\u3067\u306e\u5f8c\u4ed8\u3051\u8ffd\u52a0\u3001ON DELETE\/ON UPDATE\u306e\u9069\u5207\u306a\u9078\u629e\u3001\u30a8\u30e9\u30fc\u767a\u751f\u6642\u306e\u5bfe\u51e6\u6cd5\u3068\u3044\u3046\u3053\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u305f\u5185\u5bb9\u3092\u5b9f\u8df5\u3059\u308b\u3053\u3068\u3067\u3001\u4fe1\u983c\u6027\u306e\u9ad8\u3044\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u304c\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002Claude Code\u3092\u6d3b\u7528\u3057\u3066SQL\u8a2d\u8a08\u3092\u52b9\u7387\u5316\u3057\u3001\u30c7\u30fc\u30bf\u54c1\u8cea\u306e\u9ad8\u3044\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u3092\u6b63\u3057\u304f\u7406\u89e3\u3057\u3066\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306b\u306f\u3001\u5b9f\u969b\u306b\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3066INSERT\u30fbDELETE\u30fbUPDATE\u64cd\u4f5c\u3092\u8a66\u3057\u306a\u304c\u3089\u5236\u7d04\u306e\u52d5\u4f5c\u3092\u4f53\u9a13\u3059\u308b\u3053\u3068\u304c\u4e00\u756a\u306e\u8fd1\u9053\u3067\u3059\u3002\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u306f\u7126\u3089\u305a\u300cERROR 1452\u306a\u3089\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u89aa\u304c\u5b58\u5728\u3057\u306a\u3044\u5024\u3092\u5165\u308c\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u300d\u300cERROR 1451\u306a\u3089\u5b50\u30c6\u30fc\u30d6\u30eb\u306b\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u89aa\u3092\u524a\u9664\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u300d\u3068\u539f\u56e0\u3092\u7279\u5b9a\u3057\u3001\u5bfe\u51e6\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308c\u3070\u5916\u90e8\u30ad\u30fc\u306f\u6016\u304f\u3042\u308a\u307e\u305b\u3093\u3002SHOW CREATE TABLE\u3067\u5236\u7d04\u306e\u5b9a\u7fa9\u3092\u78ba\u8a8d\u3057\u3001information_schema.KEY_COLUMN_USAGE\u3067DB\u5168\u4f53\u306e\u5916\u90e8\u30ad\u30fc\u95a2\u4fc2\u3092\u628a\u63e1\u3059\u308b\u7fd2\u6163\u3092\u3064\u3051\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a2d\u8a08\u3068\u904b\u7528\u306e\u8cea\u304c\u4e0a\u304c\u308a\u307e\u3059\u3002\u5916\u90e8\u30ad\u30fc\u306e\u4ed5\u7d44\u307f\u3092\u3057\u3063\u304b\u308a\u30de\u30b9\u30bf\u30fc\u3057\u3066\u3001\u5b89\u5fc3\u3057\u3066\u4f7f\u3048\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u90e8\u30ad\u30fc\u8a2d\u8a08\u306e\u826f\u3057\u60aa\u3057\u306f\u30b7\u30b9\u30c6\u30e0\u306e\u9577\u671f\u7684\u306a\u4fdd\u5b88\u6027\u306b\u76f4\u7d50\u3057\u307e\u3059\u3002\u8a2d\u8a08\u6bb5\u968e\u304b\u3089\u5916\u90e8\u30ad\u30fc\u306e\u9069\u5207\u306a\u8a2d\u5b9a\u3068\u547d\u540d\u898f\u5247\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u304c\u3001\u54c1\u8cea\u306e\u9ad8\u3044\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3059\u308b\u7b2c\u4e00\u6b69\u3067\u3059\u3002Claude Code\u3092\u6d3b\u7528\u3057\u3066\u5916\u90e8\u30ad\u30fc\u8a2d\u8a08\u306e\u76f8\u8ac7\u3084SQL\u6587\u306e\u751f\u6210\u3092\u884c\u3044\u3001\u52b9\u7387\u7684\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u958b\u767a\u3092\u5b9f\u73fe\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9069\u5207\u306a\u5916\u90e8\u30ad\u30fc\u8a2d\u8a08\u306f\u958b\u767a\u30c1\u30fc\u30e0\u5168\u4f53\u306e\u751f\u7523\u6027\u5411\u4e0a\u306b\u3082\u3064\u306a\u304c\u308a\u307e\u3059\u3002\u5236\u7d04\u304c\u3057\u3063\u304b\u308a\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308c\u3070\u3001\u65b0\u3057\u3044\u30e1\u30f3\u30d0\u30fc\u304c\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3092\u898b\u308b\u3060\u3051\u3067\u30c6\u30fc\u30d6\u30eb\u9593\u306e\u95a2\u4fc2\u304c\u628a\u63e1\u3067\u304d\u3001\u8aa4\u3063\u305f\u30c7\u30fc\u30bf\u64cd\u4f5c\u3092\u9632\u6b62\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>SQL\u306e\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u3092\u5b8c\u5168\u89e3\u8aac\u3002\u5916\u90e8\u30ad\u30fc\u306e\u5f79\u5272\u30fb\u89aa\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u95a2\u4fc2\u30fbCREATE TABLE\u3067\u306e\u8a2d\u5b9a\u30fbALTER TABLE\u3067\u306e\u5f8c\u4ed8\u3051\u8ffd\u52a0\u30fbDROP FOREIGN KEY\u3067\u306e\u524a\u9664\u30fb\u6574\u5408\u6027\u5236\u7d04\u30a8\u30e9\u30fc\u306e\u5bfe\u51e6\u6cd5\u307e\u3067Claude Code\u306e\u6d3b\u7528\u6cd5\u3068\u5408\u308f\u305b\u3066\u5b9f\u8df5\u7684\u306b\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":17989,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sitemap_hide":"","_veu_custom_css":"","vkexunit_cta_each_option":"","footnotes":"","rank_math_description":"SQL\u306e\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u3092\u5b8c\u5168\u89e3\u8aac\u3002\u5916\u90e8\u30ad\u30fc\u306e\u5f79\u5272\u30fb\u89aa\u5b50\u30c6\u30fc\u30d6\u30eb\u306e\u95a2\u4fc2\u30fbCREATE TABLE\u3067\u306e\u8a2d\u5b9a\u30fbALTER TABLE\u3067\u306e\u5f8c\u4ed8\u3051\u8ffd\u52a0\u30fbDROP FOREIGN KEY\u3067\u306e\u524a\u9664\u30fb\u6574\u5408\u6027\u5236\u7d04\u30a8\u30e9\u30fc\u306e\u5bfe\u51e6\u6cd5\u307e\u3067Claude Code\u306e\u6d3b\u7528\u6cd5\u3068\u5408\u308f\u305b\u3066\u5b9f\u8df5\u7684\u306b\u7d39\u4ecb\u3057\u307e\u3059\u3002","rank_math_focus_keyword":"SQL \u5916\u90e8\u30ad\u30fc FOREIGN KEY","rank_math_title":"SQL\u5916\u90e8\u30ad\u30fc\uff08FOREIGN KEY\uff09\u5b8c\u5168\u89e3\u8aac\uff5c\u4f5c\u6210\u30fb\u6574\u5408\u6027\u5236\u7d04\u30fb\u5f8c\u4ed8\u3051\u30fb\u524a\u9664\u307e\u3067","pending_rewrite_html":"","pending_rewrite_id":"","pending_rewrite_kw":"","pending_rewrite_at":"","pending_rewrite_source":"","pending_rewrite_brief":"","pending_rewrite_evidence":"","approved_rewrite_html":"","approved_rewrite_id":"","approved_rewrite_kw":"","approved_rewrite_at":"","approved_rewrite_by":"","approved_rewrite_brief":"","approved_rewrite_evidence":"","rewrite_tracker_baseline":"","rewrite_tracker_7day":"","rewrite_tracker_14day":"","rewrite_tracker_30day":"","rewrite_tracker_notified":""},"categories":[2],"tags":[],"class_list":["post-17990","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-claude-tips"],"_links":{"self":[{"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/posts\/17990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/comments?post=17990"}],"version-history":[{"count":7,"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/posts\/17990\/revisions"}],"predecessor-version":[{"id":17997,"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/posts\/17990\/revisions\/17997"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/media\/17989"}],"wp:attachment":[{"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/media?parent=17990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/categories?post=17990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/genai-ai.co.jp\/ai-kanri\/wp-json\/wp\/v2\/tags?post=17990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}