{"id":89,"date":"2023-05-23T16:52:48","date_gmt":"2023-05-23T08:52:48","guid":{"rendered":"https:\/\/jiachen.de.cool\/blog\/?p=89"},"modified":"2023-05-24T16:11:02","modified_gmt":"2023-05-24T08:11:02","slug":"%e6%95%b0%e6%8d%ae%e6%93%8d%e7%ba%b5%e8%af%ad%e8%a8%80dml","status":"publish","type":"post","link":"https:\/\/jiachen.de.cool\/blog\/2023\/05\/23\/%e6%95%b0%e6%8d%ae%e6%93%8d%e7%ba%b5%e8%af%ad%e8%a8%80dml\/","title":{"rendered":"\u6570\u636e\u64cd\u7eb5\u8bed\u8a00DML"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Data Manipulation Language \u7531\u63d2\u5165insert into\u3001\u4fee\u6539update\u3001\u5220\u9664delete from\u4e09\u4e2a\u547d\u4ee4\u7ec4\u6210\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; show databases;\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| learning           |\n| mysql              |\n| performance_schema |\n| sys                |\n+--------------------+\n5 rows in set (0.00 sec)\n\nmysql&gt; create database learning3;\nQuery OK, 1 row affected (0.01 sec)\n\nmysql&gt; use learning3;\nDatabase changed\nmysql&gt; create table houses (name varchar(100) not null,house_location varchar(10\n0) not null,purchasing_year varchar(100) not null);\nQuery OK, 0 rows affected (0.04 sec)\n\nmysql&gt; select name,house_location,purchasing_year from houses;\nEmpty set (0.00 sec)\n\nmysql&gt; insert into houses(name,house_location,purchasing_year) values ('\u7532','\u5929\n\u6cb3',1997);\nQuery OK, 1 row affected (0.00 sec)\n\nmysql&gt; select name,house_location,purchasing_year from houses;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u7532   | \u5929\u6cb3           | 1997            |\n+------+----------------+-----------------+\n1 row in set (0.00 sec)\n\nmysql&gt; create table houses2 (name varchar(100)not null,house_location varchar(10\n0) not null, purchasing_year varchar(100) not null);\nQuery OK, 0 rows affected (0.04 sec)\n\nmysql&gt; desc houses;\n+-----------------+--------------+------+-----+---------+-------+\n| Field           | Type         | Null | Key | Default | Extra |\n+-----------------+--------------+------+-----+---------+-------+\n| name            | varchar(100) | NO   |     | NULL    |       |\n| house_location  | varchar(100) | NO   |     | NULL    |       |\n| purchasing_year | varchar(100) | NO   |     | NULL    |       |\n+-----------------+--------------+------+-----+---------+-------+\n3 rows in set (0.00 sec)\n\nmysql&gt; desc houses2;\n+-----------------+--------------+------+-----+---------+-------+\n| Field           | Type         | Null | Key | Default | Extra |\n+-----------------+--------------+------+-----+---------+-------+\n| name            | varchar(100) | NO   |     | NULL    |       |\n| house_location  | varchar(100) | NO   |     | NULL    |       |\n| purchasing_year | varchar(100) | NO   |     | NULL    |       |\n+-----------------+--------------+------+-----+---------+-------+\n3 rows in set (0.01 sec)\n\nmysql&gt; select * from houses2;\nEmpty set (0.00 sec)\n\nmysql&gt; insert into houses2 select name,house_location,purchasing_year from house\ns;\nQuery OK, 1 row affected (0.00 sec)\nRecords: 1  Duplicates: 0  Warnings: 0\n\nmysql&gt; select * from houses2;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u7532   | \u5929\u6cb3           | 1997            |\n+------+----------------+-----------------+\n1 row in set (0.00 sec)\n\nmysql&gt; update houses2 set name='\u4e59';\nQuery OK, 1 row affected (0.00 sec)\nRows matched: 1  Changed: 1  Warnings: 0\n\nmysql&gt; select * from houses2;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u4e59   | \u5929\u6cb3           | 1997            |\n+------+----------------+-----------------+\n1 row in set (0.00 sec)\n\n\nmysql&gt; delete from houses2;\nQuery OK, 1 row affected (0.00 sec)\n\nmysql&gt; select * from houses2;\nEmpty set (0.00 sec)\n\nmysql&gt; insert into houses values('\u4e59','\u756a\u79ba',1998);\nQuery OK, 1 row affected (0.00 sec)\n\n\nmysql&gt; select * from houses;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u7532   | \u5929\u6cb3           | 1997            |\n| \u4e59   | \u756a\u79ba           | 1998            |\n+------+----------------+-----------------+\n2 rows in set (0.00 sec)\n\nmysql&gt; insert into houses2 select * from houses where name='\u4e59';\nQuery OK, 1 row affected (0.00 sec)\nRecords: 1  Duplicates: 0  Warnings: 0\n\nmysql&gt; select * from houses2;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u4e59   | \u756a\u79ba           | 1998            |\n+------+----------------+-----------------+\n1 row in set (0.00 sec)\n\nmysql&gt; insert into houses2 select name,house_location,purchasing_year from house\ns where house_location='\u5929\u6cb3';\nQuery OK, 1 row affected (0.00 sec)\nRecords: 1  Duplicates: 0  Warnings: 0\n\nmysql&gt; select * from houses2;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u4e59   | \u756a\u79ba           | 1998            |\n| \u7532   | \u5929\u6cb3           | 1997            |\n+------+----------------+-----------------+\n2 rows in set (0.00 sec)\n\nmysql&gt; delete from houses2;\nQuery OK, 2 rows affected (0.00 sec)\n\nmysql&gt; select * from houses2;\nEmpty set (0.00 sec)\n\nmysql&gt; desc houses2;\n+-----------------+--------------+------+-----+---------+-------+\n| Field           | Type         | Null | Key | Default | Extra |\n+-----------------+--------------+------+-----+---------+-------+\n| name            | varchar(100) | NO   |     | NULL    |       |\n| house_location  | varchar(100) | NO   |     | NULL    |       |\n| purchasing_year | varchar(100) | NO   |     | NULL    |       |\n+-----------------+--------------+------+-----+---------+-------+\n3 rows in set (0.00 sec)\n\nmysql&gt; drop table houses2;\nQuery OK, 0 rows affected (0.02 sec)\n\nmysql&gt; desc houses2;\nERROR 1146 (42S02): Table 'learning3.houses2' doesn't exist\nmysql&gt; show tables;\n+---------------------+\n| Tables_in_learning3 |\n+---------------------+\n| houses              |\n+---------------------+\n1 row in set (0.00 sec)\n\nmysql&gt; select * from houses;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u7532   | \u5929\u6cb3           | 1997            |\n| \u4e59   | \u756a\u79ba           | 1998            |\n+------+----------------+-----------------+\n2 rows in set (0.00 sec)\n\nmysql&gt; update houses set name='yi',house_location='panyu',purchasing_year=1996 w\nhere name='\u4e59';\nQuery OK, 1 row affected (0.00 sec)\nRows matched: 1  Changed: 1  Warnings: 0\n\nmysql&gt; select * from houses;\n+------+----------------+-----------------+\n| name | house_location | purchasing_year |\n+------+----------------+-----------------+\n| \u7532   | \u5929\u6cb3           | 1997            |\n| yi   | panyu          | 1996            |\n+------+----------------+-----------------+\n2 rows in set (0.00 sec)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5220\u9664\u64cd\u4f5c\u57fa\u672c\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DELETE FROM table_name (WHERE Clause);<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u57fa\u672c\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>UPDATE table_name SET field1=new_value1, field2=new_value2 (WHERE Clause);<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data Manipulation Language \u7531\u63d2\u5165insert into\u3001\u4fee\u6539update\u3001\u5220\u9664de&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/jiachen.de.cool\/blog\/2023\/05\/23\/%e6%95%b0%e6%8d%ae%e6%93%8d%e7%ba%b5%e8%af%ad%e8%a8%80dml\/\">Read the full article<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[10,11],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-dml","tag-11"],"_links":{"self":[{"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":2,"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":92,"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/posts\/89\/revisions\/92"}],"wp:attachment":[{"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jiachen.de.cool\/blog\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}