{"id":209767,"date":"2022-08-18T15:23:30","date_gmt":"2022-08-18T07:23:30","guid":{"rendered":"https:\/\/www.keaglegz.com\/209767.html"},"modified":"2026-07-15T06:26:51","modified_gmt":"2026-07-14T22:26:51","slug":"sql%e7%bc%96%e7%a8%8b%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/www.dongwubaike.cn\/fanhao\/209767.html","title":{"rendered":"SQL\u7f16\u7a0b\u5165\u95e8"},"content":{"rendered":"<p> \u3000\u3000<strong>\u5bfc\u5165\u6d4b\u8bd5\u5e93\uff1a<\/strong><br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u6587\u6863\u5730\u5740\uff1a https:\/\/dev.mysql.com\/doc\/employee\/en\/sakila-structure.html<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u4e0b\u8f7d\u5730\u5740\uff1a https:\/\/github.com\/datacharmer\/test_db<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u5bfc\u5165\u6d4b\u8bd5\u5e93\uff1a<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cd<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; mysql -uroot -p -S&nbsp; &lt; employees.sql<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b<strong>&nbsp;&nbsp; &nbsp;\u5e93\u64cd\u4f5c<\/strong><br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u589e\uff1acreate database test character set utf8;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u5220\uff1adrop database test;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u6539\uff1aalter database test character set gbk;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u67e5<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1ashow databases; \u67e5\u770b\u5f53\u524d\u6709\u54ea\u4e9b\u6570\u636e\u5e93<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1ashow create database test; \u67e5\u770b\u521b\u5efatest\u5e93\u7684sql\u8bed\u53e5<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;<strong>\u8868\u64cd\u4f5c<\/strong><br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u589e\uff1acreate table t1 (id int)engine=innodb charset=utf8;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u5220\uff1adrop table t2;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u6539<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aalter table t1 rename to t2; \u4fee\u6539\u8868\u540d\u79f0<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aalter table t2 add name varchar(10); \u6dfb\u52a0\u65b0\u5b57\u6bb5<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aalter table t2 drop name; \u5220\u9664\u5b57\u6bb5<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &amp;nbsp<\/p>\n<p><a href=\"https:\/\/www.dongwubaike.cn\/fanhao\/wp-content\/uploads\/2024\/06\/haode2332337.jpg\" data-fancybox=\"images\"><img decoding=\"async\" src=\"https:\/\/www.dongwubaike.cn\/fanhao\/wp-content\/uploads\/2024\/06\/haode2332337.jpg\" alt=\"\"><\/a><\/p>\n<p>;&nbsp;&nbsp; &nbsp;\uff1aalter table t2 change name title varchar(10); \u4fee\u6539\u5b57\u6bb5\u540d\u79f0<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aalter table t2 modify title varchar(30); \u4fee\u6539\u5b57\u6bb5\u7c7b\u578b\u7ea6\u675f<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aalter table t2 convert to character set gbk; \u4fee\u6539\u5b57\u7b26\u96c6<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aalter table t2 engine=myisam; \u4fee\u6539\u5b58\u50a8\u5f15\u64ce<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u67e5<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1ashow tables; \u67e5\u770b\u5f53\u524d\u5e93\u4e0b\u6709\u54ea\u4e9b\u8868<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1ashow create table t1; \u67e5\u770b\u521b\u5efa\u8868\u7684sql\u8bed\u53e5<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1adesc t1; \u67e5\u770b\u8868\u7ed3\u6784<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1ashow table status like &#039;t1&#039; G; \u67e5\u770b\u8868\u72b6\u6001<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;<strong>\u6570\u636e\u64cd\u4f5c<\/strong><br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u589e<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1ainsert into t1(id, name, gender) values(1, &#039;\u5f20\u4e09&#039;, &#039;m&#039;);<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1ainsert into t1(id, name, gender) values(null, &#039;\u738b\u4e94&#039;, &#039;m&#039;),(null,&#039;\u674e\u56db&#039;,&#039;m&#039;);<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u5220\uff1adelete from t1 where id=1;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u6539\uff1aupdate t1 set name=&#039;ergou&#039; where id=1;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u67e5<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aselect * from t1;<br \/>  \u3000\u3000<br \/>  \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\uff1aselect name from t1; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3000\u5bfc\u5165\u6d4b\u8bd5\u5e93\uff1a \u3000\u3000 \u3000\u3000\u200b&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\u6587\u6863\u5730\u5740\uff1a https:\/\/dev.mysql.com\/doc\/employee\/en\/sakila-structure.html \u3000 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-209767","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/posts\/209767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/comments?post=209767"}],"version-history":[{"count":1,"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/posts\/209767\/revisions"}],"predecessor-version":[{"id":308291,"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/posts\/209767\/revisions\/308291"}],"wp:attachment":[{"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/media?parent=209767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/categories?post=209767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dongwubaike.cn\/fanhao\/wp-json\/wp\/v2\/tags?post=209767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}