{"id":739,"date":"2019-05-01T17:54:43","date_gmt":"2019-05-01T09:54:43","guid":{"rendered":"http:\/\/www.eait.co\/?p=739"},"modified":"2019-05-01T17:54:43","modified_gmt":"2019-05-01T09:54:43","slug":"mysql-%e4%b8%89","status":"publish","type":"post","link":"https:\/\/notes.coremix.net\/?p=739","title":{"rendered":"mysql \u4e09"},"content":{"rendered":"<div>desc student;<\/div>\n<div><\/div>\n<div>int\u00a0\u53ea\u670911\u4f4d\u957f\u5ea6<\/div>\n<div><\/div>\n<div>\u8eab\u4efd\u8bc1\u662f\u7528varchar<\/div>\n<div><\/div>\n<div>alter table\u00a0\u8868\u540d rename to\u00a0\u65b0\u8868\u540d;<\/div>\n<div>\u4fee\u6539\u8868\u540d<\/div>\n<div>alter table tb_name change\u00a0name new_name data_type;<\/div>\n<div>\u4fee\u6539\u5b57\u6bb5\u540d<\/div>\n<div>alter table tb_name modify fiele_name data_type;<\/div>\n<div>\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b<\/div>\n<div>alter table tb_name add [column]\u00a0field_name data_type;<\/div>\n<div>\u6dfb\u52a0\u5b57\u6bb5<\/div>\n<div>alter table tb_name drop [column] fileld_name;<\/div>\n<div>\u5220\u9664\u5b57\u6bb5<\/div>\n<div><\/div>\n<div><\/div>\n<div>\u7ea6\u675f\u6761\u4ef6\uff1a<\/div>\n<div>\u9ed8\u8ba4\uff1a default<\/div>\n<div>create table tb(id int defaule 1,name varchar(20));<\/div>\n<div><\/div>\n<div>\u975e\u7a7a\uff1a not null<\/div>\n<div>create talbe tb(id int not null, name varchar(20));(\u7a7a\u5b57\u7b26\u4e0d\u7b49\u4e8enull\uff09<\/div>\n<div><\/div>\n<div>\u552f\u4e00\uff1a unique key<\/div>\n<div>create\u00a0table tb(id int unique key, name varchar(20));<\/div>\n<div><\/div>\n<div>\u81ea\u589e\u957f\uff1a auto_increment<\/div>\n<div>\u4e3b\u952e\uff1a primary key<\/div>\n<div>create table tb( id int primary key auto_increment, name varchar(20));<\/div>\n<div>\u81ea\u52a8\u7f16\u53f7\uff0c\u548c\u4e3b\u952e\u7ec4\u5408\u4f7f\u7528\uff0c\u4e00\u4e2a\u8868\u91cc\u9762\u53ea\u80fd\u6709\u4e00\u4e2a\u81ea\u589e\u957f\uff0cauto_increment\u00a0\u8981\u6c42\u7528\u5728\u4e3b\u952e\u4e0a<\/div>\n<div>\u5916\u952e\uff1aforeign key<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>\u4f5c\u4e1a\uff1a<\/div>\n<div>\u5efa\u7acb\u9009\u8bfe\u7cfb\u7edf\u4e2d\u76844\u5f20\u8868: (\u5b66\u9662\u8868\uff0c\u5b66\u751f\u8868\uff0c\u8bfe\u7a0b\u8868\uff0c\u9009\u8bfe\u8868) , \u5e76\u6bcf\u5f20\u8868\u63d2\u51654\u6761\u6570\u636e<\/div>\n<div><\/div>\n<div>create database relation;<\/div>\n<div>\u521b\u5efa\u6570\u636e\u5e93<\/div>\n<div>create table collage(id int primary key, c_name varchar(20));<\/div>\n<div>\u521b\u5efa\u5b66\u9662\u8868#\u00a0\u8bbe\u5b9a\u4e3b\u952e\u4e3a\u5b66\u9662id<\/div>\n<div>create\u00a0table\u00a0student(id int primary key ,name varchar(20), c_id int , foreign key(c_id)\u00a0 references collage(id));<\/div>\n<div>\u521b\u5efa\u5b66\u751f\u8868#\u00a0\u8bbe\u5b9a\u4e3b\u952e\u4e3a\u5b66\u751fid\uff0c\u5e76\u4e14\u4ee5\u5b66\u9662id\u4e3a\u5916\u952e\u5173\u8054\u5b66\u9662\u8868\u7684id\u4e3a\u4e3b\u952e<\/div>\n<div>create table cours ( id int primary key ,name varchar(20), c_id int, foreign key(c_id) references collage(id));<\/div>\n<div>\u521b\u5efa\u8bfe\u7a0b\u8868#\u00a0\u8bbe\u7f6e\u8bfe\u7a0bid\u4e3a\u4e3b\u952e\uff0c\u5e76\u4e14\u5173\u8054\u5b66\u9662\u4e3a\u4e3b\u952e<\/div>\n<div>create table s_cours(stu_id int ,cours_id int ,primary key(stu_id,cours_id), foreign key(stu_id) references student(id) , foreign key(cours_id) references cours(id));<\/div>\n<div>\u521b\u5efa\u9009\u8bfe\u8868\uff0c\u7528\u5b66\u751fid\u548c\u9009\u8bfeid\u5206\u522b\u5173\u8054\u8bfe\u7a0b\u8868\u548c\u5b66\u751f\u8868\uff0c\u4ee5\u4fdd\u8bc1\u5b66\u751fid\u548c\u6240\u9009\u8bfe\u7684id\u7684\u6b63\u786e\u6027\u3002(\u6570\u636e\u7c7b\u578b\u4e0d\u4e00\u81f4\u65e0\u6cd5\u521b\u5efa\u4e3b\u952e\uff09<\/div>\n<div>insert into collage values(1,&#8217;shangxueyuan&#8217;),(2,&#8217;meishuxueyuan&#8217;),(3,&#8217;jisuanjixueyuan&#8217;),(4,&#8217;ligongxueyuan&#8217;);<\/div>\n<div>\u63d2\u5165\u56db\u6761\u5b66\u9662\u4fe1\u606f<\/div>\n<div>insert into student values(1,&#8217;zhangsan&#8217;,3),(2,&#8217;lisi&#8217;,2),(3,&#8217;moran1&#8242;,2),(4,&#8217;moran2&#8242;,4);<\/div>\n<div>\u63d2\u5165\u56db\u6761\u5b66\u751f\u4fe1\u606f<\/div>\n<div>insert into cours values(1,&#8217;zhengzhi1&#8242;,3),(2,&#8217;zhengzhi2&#8242;,2),(3,&#8217;zhengzhi3&#8242;,2),(4,&#8217;zhengzhi4&#8242;,4);<\/div>\n<div>\u63d2\u5165\u56db\u6761\u8bfe\u7a0b\u4fe1\u606f<\/div>\n<div>insert into s_cours values(1,3),(2,2),(3,2),(4,4),(1,2);<\/div>\n<div>\u63d2\u5165\u4e94\u6761\u5b66\u751f\u548c\u9009\u8bfe\u4fe1\u606f<\/div>\n<div><\/div>\n<div><\/div>\n<div>\u67e5\u8be2\uff1a<\/div>\n<div>\u67e5\u8be2\u7f16\u53f7\u4e3a1\u7684\u5b66\u751f\u9009\u4e86\u54ea\u4e9b\u8bfe<\/div>\n<div>select name from cours where id = (select cours_id from s_cours where stu_id = 1);<\/div>\n<div><\/div>\n<div><\/div>\n<div>ysql&gt; select name from cours where id = (select cours_id from s_cours where stu_id = 1);<\/div>\n<div>ERROR 1242 (21000): Subquery returns more than 1 row\u00a0 \u8fd4\u56de\u8d85\u8fc7\u4e24\u4e2a\u5982\u4f55\u89e3\u51b3\uff1f<\/div>\n<div><\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>desc student; int\u00a0\u53ea\u670911\u4f4d\u957f\u5ea6 \u8eab\u4efd\u8bc1\u662f\u7528varchar alter table\u00a0\u8868\u540d r [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-739","post","type-post","status-publish","format-standard","hentry","category-python_note"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=739"}],"version-history":[{"count":1,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions"}],"predecessor-version":[{"id":740,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions\/740"}],"wp:attachment":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}