{"id":4928,"date":"2018-06-22T15:50:07","date_gmt":"2018-06-22T06:50:07","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=4928"},"modified":"2023-05-27T21:41:52","modified_gmt":"2023-05-27T12:41:52","slug":"%e3%80%90sql%e3%80%91%e3%80%8c%e5%88%b6%e7%b4%84%e3%80%8d%e3%81%ae%e7%a8%ae%e9%a1%9e%e3%81%a8%e4%bd%bf%e3%81%84%e6%96%b9","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=4928","title":{"rendered":"\u3010SQL\u3011\u300c\u5236\u7d04\u300d\u306e\u7a2e\u985e\u3068\u4f7f\u3044\u65b9"},"content":{"rendered":"<h2>\u5236\u7d04\u306e\u7a2e\u985e<\/h2>\n<table>\n<tbody>\n<tr>\n<th>\u5236\u7d04\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>NOT NULL\u5236\u7d04<\/td>\n<td>NULL\u3092\u8a31\u5bb9\u3057\u306a\u3044\u3002<\/td>\n<\/tr>\n<tr>\n<td>UNIQUE\u5236\u7d04<\/td>\n<td>\u91cd\u8907\u5024\u3092\u8a31\u53ef\u3057\u306a\u3044\u3067\u3059\u3002\uff08\u305f\u3060\u3057\u3001<span style=\"color: #ff0000;\"><strong>NULL\u306e\u91cd\u8907\u306f\u8a31\u53ef<\/strong><\/span>\u3057\u307e\u3059\u3002\uff09<\/td>\n<\/tr>\n<tr>\n<td>PRIMARY KEY\u5236\u7d04(\u4e3b\u30ad\u30fc\u5236\u7d04)<\/td>\n<td>\u8868\u306e\u5024\u3092\u4e00\u610f\u306b\u8b58\u5225\u3067\u304d\u308b\u5024\u306e\u307f\u8a31\u53ef\u3059\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td>FOREIGN KEY\u5236\u7d04(\u5916\u90e8\u30ad\u30fc\u5236\u7d04)<\/td>\n<td>\u53c2\u7167\u5148\u306b\u3042\u308b\u5024\u3001\u307e\u305f\u306fNULL\u5024\u306e\u307f\u8a31\u53ef\u3059\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td>CHECK\u5236\u7d04(\u30c1\u30a7\u30c3\u30af\u5236\u7d04)<\/td>\n<td>\u6307\u5b9a\u3057\u305f\u6761\u4ef6\u306b\u5408\u3046\u5024\u306e\u307f\u8a31\u53ef\u3059\u308b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>NOT NULL\u5236\u7d04<\/h3>\n<h4>\u7279\u5fb4<\/h4>\n<ul>\n<li>NULL\u3092\u8a31\u5bb9\u3057\u306a\u3044\u3002<\/li>\n<li>\u5217\u30ec\u30d9\u30eb\u306b\u3057\u304b\u9069\u7528\u3067\u304d\u307e\u305b\u3093\u3002<\/li>\n<\/ul>\n<h3>UNIQUE\u5236\u7d04<\/h3>\n<h4>\u7279\u5fb4<\/h4>\n<ul>\n<li>\u91cd\u8907\u3057\u305f\u5024\u3092\u683c\u7d0d\u3067\u304d\u306a\u304f\u306a\u308b\u304c\u3001<span style=\"color: #ff0000;\"><strong>NULL\u5024\u306f\u91cd\u8907\u53ef\u80fd<\/strong><\/span>\u3002<\/li>\n<li>\u3053\u306e\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u3068\u3001\u81ea\u52d5\u3067\u3053\u306e\u5236\u7d04\u540d\u306e\u7d22\u5f15\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u8907\u5408\u5217\u3067\u3001UNIQUE\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u8868\u30ec\u30d9\u30eb\u306e\u5236\u7d04\u5b9a\u7fa9<\/strong><\/span>\u3092\u4f7f\u3046\u3002<\/li>\n<\/ul>\n<h3>PRIMARY KEY(\u4e3b\u30ad\u30fc)\u5236\u7d04<\/h3>\n<ul>\n<li>\u91cd\u8907\u5024\u3084\u3001NULL\u5024\u306f\u683c\u7d0d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<\/li>\n<li>\u8868\u306b\u4e00\u3064\u306e\u307f\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>\u3053\u306e\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u3068\u3001\u81ea\u52d5\u3067\u3053\u306e\u5236\u7d04\u540d\u306e\u7d22\u5f15\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>\u8907\u5408\u5217\u3067\u3001PRIMARY KEY\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u8868\u30ec\u30d9\u30eb\u306e\u5236\u7d04\u5b9a\u7fa9<\/strong><\/span>\u3092\u4f7f\u3046\u3002<\/li>\n<\/ul>\n<h3>FOREIGN KEY(\u5916\u90e8\u30ad\u30fc)\u5236\u7d04<\/h3>\n<ul>\n<li>\u53c2\u7167\u5148\u306e\u5217\u306b\u5b58\u5728\u3059\u308b\u5024\u306e\u307f\u3057\u304b\u683c\u7d0d\u3067\u304d\u306a\u304f\u306a\u308b\u3002<\/li>\n<li>NULL\u5024\u3092\u542b\u3081\u308b\u3053\u3068\u306f\u53ef\u80fd\u3002<\/li>\n<li>FOREIGN KEY\u306f\u3001\u300cUNIQUE\u5236\u7d04\u300d\u3001\u300cPRIMARY KEY\u5236\u7d04\u300d\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u5217\u3057\u304b\u5b9a\u7fa9\u3067\u304d\u306a\u3044\u3002<\/li>\n<li>FOREIGN KEY\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u3068\u3001\u89aa\u8868\u306f\u524a\u9664\u3067\u304d\u306a\u3044\u3002<\/li>\n<\/ul>\n<h4>\u89aa\u8868\u304b\u3089\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u305f\u969b\u306e\u3001\u52d5\u4f5c\u3092\u6307\u5b9a\u3067\u304d\u308b\u30ad\u30fc\u30ef\u30fc\u30c9<\/h4>\n<table>\n<tbody>\n<tr>\n<th width=\"200\">\u30ad\u30fc\u30ef\u30fc\u30c9<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>\u6307\u5b9a\u306a\u3057<\/td>\n<td>\u5b50\u8868\u306b\u89aa\u8868\u3092\u53c2\u7167\u3059\u308b\u884c\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u89aa\u8868\u306e\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u884c\u306f\u524a\u9664\u3067\u304d\u306a\u3044\u3002<\/td>\n<\/tr>\n<tr>\n<td>ON DELETE CASCADE<\/td>\n<td>\u5b50\u8868\u306b\u89aa\u8868\u3092\u53c2\u7167\u3059\u308b\u884c\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306b\u3001\u89aa\u8868\u306e\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u884c\u3092\u524a\u9664\u3059\u308b\u3068\u3001<span style=\"color: #ff0000;\"><strong>\u5b50\u8868\u306e\u30c7\u30fc\u30bf\u3082\u524a\u9664\u3055\u308c\u308b\u3002<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td>ON DELETE SET NULL<\/td>\n<td>\u5b50\u8868\u306b\u89aa\u8868\u3092\u53c2\u7167\u3059\u308b\u884c\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306b\u3001\u89aa\u8868\u306e\u53c2\u7167\u3055\u308c\u3066\u3044\u308b\u884c\u3092\u524a\u9664\u3059\u308b\u3068\u3001<span style=\"color: #ff0000;\"><strong>\u5b50\u8868\u306e\u30c7\u30fc\u30bf\u306bNULL\u304c\u8a2d\u5b9a\u3055\u308c\u308b\u3002<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u307e\u305f\u3001\u305d\u3082\u305d\u3082\u5916\u90e8\u30ad\u30fc\u3092\u4f7f\u3063\u305f\u65b9\u304c\u3088\u3044\u306e\u304b\u306e\u898b\u89e3\u306b\u95a2\u3057\u3066\u306f\u3001\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u3057\u3066\u304a\u308a\u307e\u3059\u306e\u3067\u3001\u3054\u53c2\u8003\u4e0b\u3055\u3044\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"s6RqDtniXE\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=713\">\u3010\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3011\u300c\u5916\u90e8\u30ad\u30fc\u300d\u3001\u300c\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u300d\u306b\u3064\u3044\u3066<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=713&#038;embed=true#?secret=s6RqDtniXE\" data-secret=\"s6RqDtniXE\" width=\"500\" height=\"282\" title=\"&#8220;\u3010\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3011\u300c\u5916\u90e8\u30ad\u30fc\u300d\u3001\u300c\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u300d\u306b\u3064\u3044\u3066&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h3>CHECK\u5236\u7d04<\/h3>\n<ul>\n<li>\u305d\u306e\u5217\u306b\u6307\u5b9a\u3057\u305f\u6761\u4ef6\u306b\u5bfe\u3057\u3066\u3001TRUE\u307e\u305f\u306fNULL\u3092\u8fd4\u3059\u5024\u3057\u304b\u683c\u7d0d\u3067\u304d\u306a\u304f\u306a\u308b\u3002<\/li>\n<li>1\u3064\u306e\u5217\u306b\u8907\u6570CHECK\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/li>\n<li>\u57fa\u672c\u7684\u306b\u306f\u3001<span style=\"color: #ff0000;\"><strong>WHERE\u53e5\u306b\u6307\u5b9a\u3059\u308b\u6761\u4ef6\u3068\u540c\u3058\u6761\u4ef6<\/strong><\/span>\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n<h2>\u5236\u7d04\u306e\u5b9a\u7fa9\uff08\u5217\u30ec\u30d9\u30eb\u3001\u8868\u30ec\u30d9\u30eb\uff09<\/h2>\n<p>\u5236\u7d04\u306e\u5b9a\u7fa9\u306e\u7bc4\u56f2\u3068\u3057\u3066\u306f\u3001\u4e0b\u8a18\u306e2\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5217\u30ec\u30d9\u30eb\u5236\u7d04<\/li>\n<li>\u8868\u30ec\u30d9\u30eb\u5236\u7d04<\/li>\n<\/ul>\n<h3>\u5217\u30ec\u30d9\u30eb\u5236\u7d04<\/h3>\n<h4>\u69cb\u6587<\/h4>\n<pre class=\"lang:default decode:true\">CREATE TABLE \u8868\u540d{\r\n  \u5217\u540d \u30c7\u30fc\u30bf\u578b CONSTRAINT \u5236\u7d04\u540d \u5236\u7d04\u306e\u7a2e\u985e\r\n}<\/pre>\n<h4>\u5217\u30ec\u30d9\u30eb\u5236\u7d04\u3092\u9069\u7528\u3059\u308b\u969b\u306e\u30dd\u30a4\u30f3\u30c8<\/h4>\n<p>1\u3064\u306e\u5217\u306b\u8907\u6570\u306e\u5217\u30ec\u30d9\u30eb\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u969b\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u6539\u884c\u307e\u305f\u306f\u30b9\u30da\u30fc\u30b9<\/strong><\/span>\u3067\u533a\u5207\u308a\u307e\u3059\u3002<\/p>\n<h3>\u8868\u30ec\u30d9\u30eb\u5236\u7d04<\/h3>\n<h4>\u69cb\u6587<\/h4>\n<pre class=\"lang:default decode:true\">CREATE TABLE \u8868\u540d{\r\n  \u5217\u540d1 \u30c7\u30fc\u30bf\u578b,\r\n  \u5217\u540d2 \u30c7\u30fc\u30bf\u578b,\r\n  CONSTRAINT \u5236\u7d04\u540d \u5236\u7d04\u306e\u7a2e\u985e(\u5217\u540d1,\u5217\u540d2\u2026)\r\n}<\/pre>\n<h4>\u8868\u30ec\u30d9\u30eb\u5236\u7d04\u3092\u9069\u7528\u3059\u308b\u969b\u306e\u30dd\u30a4\u30f3\u30c8<\/h4>\n<ul>\n<li>\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u5217\u3092\uff11\u3064\u4ee5\u4e0a\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li><span style=\"color: #ff0000;\"><strong>NOT NULL\u5236\u7d04\u306f\u9069\u7528\u3067\u304d\u307e\u305b\u3093\u3002<\/strong><\/span><\/li>\n<li>\u8907\u6570\u5217\u306e\u7d44\u307f\u5408\u308f\u305b\u304b\u3089\u306a\u308b\u5236\u7d04\uff08<span style=\"color: #ff0000;\"><strong>\u8907\u6570\u5217\u306b\u5bfe\u3059\u308bUNIQUE\u5236\u7d04\u306e\u5b9a\u7fa9\u7b49<\/strong><\/span>\uff09\u306f\u3001\u8868\u30ec\u30d9\u30eb\u5236\u7d04\u306e\u307f\u3067\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>1\u3064\u306e\u8868\u306b\u3001\u8907\u6570\u306e\u8868\u30ec\u30d9\u30eb\u5236\u7d04\u3092\u5b9a\u7fa9\u3059\u308b\u969b\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u30ab\u30f3\u30de<\/strong><\/span>\u3067\u533a\u5207\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n<h3>\u5217\u30ec\u30d9\u30eb\u5236\u7d04\u3001\u8868\u30ec\u30d9\u30eb\u5236\u7d04\u5171\u901a\u306e\u30dd\u30a4\u30f3\u30c8<\/h3>\n<ul>\n<li>1\u3064\u306eCREATE\u6587\u306b\u3001\u5217\u30ec\u30d9\u30eb\u5236\u7d04\u3068\u3001\u8868\u30ec\u30d9\u30eb\u5236\u7d04\u3092\u540c\u6642\u306b\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<\/li>\n<li><span style=\"color: #ff0000;\"><strong>NOT NULL\u5236\u7d04\u306f\u3001<\/strong><strong>\u300c\u5217\u30ec\u30d9\u30eb\u5236\u7d04\u306e\u307f\u300d<\/strong><\/span>\u3057\u304b\u5b9a\u7fa9\u3067\u304d\u307e\u305b\u3093\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u5236\u7d04\u306e\u7a2e\u985e \u5236\u7d04\u540d \u8aac\u660e NOT NULL\u5236\u7d04 NULL\u3092\u8a31\u5bb9\u3057\u306a\u3044\u3002 UNIQUE\u5236\u7d04 \u91cd\u8907\u5024\u3092\u8a31\u53ef\u3057\u306a\u3044\u3067\u3059\u3002\uff08\u305f\u3060\u3057\u3001NULL\u306e\u91cd\u8907\u306f\u8a31\u53ef\u3057\u307e\u3059\u3002\uff09 PRIMARY KEY\u5236\u7d04(\u4e3b\u30ad\u30fc\u5236\u7d04) \u8868\u306e\u5024\u3092\u4e00\u610f\u306b\u8b58\u5225\u3067\u304d [&hellip;]","protected":false},"author":1,"featured_media":4823,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,24],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4928"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4928"}],"version-history":[{"count":17,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4928\/revisions"}],"predecessor-version":[{"id":20386,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4928\/revisions\/20386"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/4823"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4928"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}