﻿{"id":11320,"date":"2021-12-12T08:12:13","date_gmt":"2021-12-12T00:12:13","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=11320"},"modified":"2021-12-11T20:38:20","modified_gmt":"2021-12-11T12:38:20","slug":"ubuntu-20-04-sqlite","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/ubuntu-20-04-sqlite.html","title":{"rendered":"\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5 SQLite\uff0c\u4ee5\u53ca SQLite \u7684\u589e\u5220\u6539\u67e5"},"content":{"rendered":"<h3 id=\"introduction\">\u4ecb\u7ecd<\/h3>\n<p>SQLite\u662f\u4e00\u4e2a\u514d\u8d39\u7684\u8de8\u5e73\u53f0\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u3002\u5b83\u56e0\u5176\u6548\u7387\u548c\u4e0e\u8bb8\u591a\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u63a5\u53e3\u7684\u80fd\u529b\u800c\u5e7f\u53d7\u6b22\u8fce\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u60a8\u5c06\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5 SQLite\u3002\u7136\u540e\uff0c\u60a8\u5c06\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u3001\u4ece\u4e2d\u8bfb\u53d6\u6570\u636e\u3001\u63d2\u5165\u9879\u76ee\u3001\u5220\u9664\u9879\u76ee\u4ee5\u53ca\u4ece\u5355\u72ec\u7684\u8868\u4e2d\u8fde\u63a5\u9879\u76ee\u3002<\/p>\n<h2 id=\"prerequisites\">\u5148\u51b3\u6761\u4ef6<\/h2>\n<p>\u8981\u5b8c\u6210\u672c\u6559\u7a0b\uff0c\u60a8\u5c06\u9700\u8981\uff1a<\/p>\n<ul>\n<li>\u8fd0\u884c Ubuntu 20.04 \u7684\u672c\u5730\u673a\u5668\u6216\u670d\u52a1\u5668\u3002\u8981\u8bbe\u7f6e\u670d\u52a1\u5668\uff0c\u5305\u62ec\u975e root sudo \u7528\u6237\u548c\u9632\u706b\u5899\u3002<\/li>\n<\/ul>\n<h2 id=\"step-1-mdash-installing-sqlite-on-ubuntu-20-04\">\u7b2c 1 \u6b65\uff1a\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5 SQLite<\/h2>\n<p>\u8981\u5728 Ubuntu \u4e0a\u5b89\u88c5 SQLite \u547d\u4ee4\u884c\u754c\u9762\uff0c\u9996\u5148\u66f4\u65b0\u60a8\u7684\u8f6f\u4ef6\u5305\u5217\u8868\uff1a<\/p>\n<p>linuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<\/span><\/p>\n<p>\u73b0\u5728\u5b89\u88c5 SQLite\uff1a<\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\">\n<p>linuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> sqlite3<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11323\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/1.png\" alt=\"\" width=\"1056\" height=\"773\" \/><\/p>\n<\/div>\n<\/div>\n<p>\u8981\u9a8c\u8bc1\u5b89\u88c5\uff0c\u8bf7\u68c0\u67e5\u8f6f\u4ef6\u7684\u7248\u672c\uff1a<\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\">\n<p>linuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\">sqlite3 &#8211;version<\/span><\/p>\n<\/div>\n<\/div>\n<p>\u60a8\u5c06\u6536\u5230\u5982\u4e0b\u8f93\u51fa\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">3.37.0 2021-11-27 14:13:22 bd41822c7424d393a30e92ff6cb254d25c26769889c1499a18a0b9339f5d6c8a<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11324 size-full\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/2.png\" alt=\"\" width=\"1056\" height=\"287\" \/><\/p>\n<p>\u5b89\u88c5 SQLite \u540e\uff0c\u60a8\u73b0\u5728\u53ef\u4ee5\u521b\u5efa\u65b0\u6570\u636e\u5e93\u4e86\u3002<\/p>\n<h2 id=\"step-2-mdash-creating-a-sqlite-database\">\u7b2c 2 \u6b65\uff1a\u521b\u5efa SQLite \u6570\u636e\u5e93<\/h2>\n<p>\u5728\u6b64\u6b65\u9aa4\u4e2d\uff0c\u60a8\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u9ca8\u9c7c\u53ca\u5176\u5c5e\u6027\u7684\u6570\u636e\u5e93\u3002\u8981\u521b\u5efa\u6570\u636e\u5e93\uff0c\u8bf7\u6253\u5f00\u7ec8\u7aef\u5e76\u8fd0\u884c\u4ee5\u4e0b<code>sqlite3<\/code>\u547d\u4ee4\uff1a<\/p>\n<p>linuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\">sqlite3 linuxmi.db<\/span><\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>linuxmi<\/code> \u5982\u679c\u6587\u4ef6<code>linuxmi.db<\/code>\u5df2\u7ecf\u5b58\u5728\uff0cSQLite \u5c06\u6253\u5f00\u4e00\u4e2a\u8fde\u63a5\uff1b\u5982\u679c\u5b83\u4e0d\u5b58\u5728\uff0cSQLite \u5c06\u521b\u5efa\u5b83\u3002<\/p>\n<p>\u60a8\u5c06\u6536\u5230\u5982\u4e0b\u8f93\u51fa\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">SQLite version 3.37.0 2021-11-27 14:13:22\r\nEnter \".help\" for usage hints.<\/code><\/pre>\n<p>\u5728\u6b64\u4e4b\u540e\uff0c\u60a8\u7684\u63d0\u793a\u5c06\u53d1\u751f\u53d8\u5316\u3002\u4e00\u4e2a\u65b0\u7684\u524d\u7f00<code>sqlite&gt;<\/code>, \u73b0\u5728\u51fa\u73b0\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt;<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11326\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/3.png\" alt=\"\" width=\"1056\" height=\"260\" \/><\/p>\n<p>\u5982\u679c\u8be5\u6587\u4ef6<code>linuxmi.db<\/code>\u5c1a\u4e0d\u5b58\u5728\uff0c\u5e76\u4e14\u60a8\u5728<code>sqlite<\/code>\u672a\u8fd0\u884c\u4efb\u4f55\u67e5\u8be2\u7684\u60c5\u51b5\u4e0b\u9000\u51fa\u5347\u7ea7\uff0c\u5219\u4e0d\u4f1a\u521b\u5efa<code>sharks.db<\/code>\u6587\u4ef6\u3002\u4e3a\u4e86\u786e\u4fdd\u6587\u4ef6\u88ab\u521b\u5efa\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u952e\u5165<code>;<\/code>\u7136\u540e\u6309\u201cEnter\u201d\u6765\u8fd0\u884c\u4e00\u4e2a\u7a7a\u67e5\u8be2\u3002\u8fd9\u6837\uff0c\u60a8\u5c06\u786e\u4fdd\u5b9e\u9645\u521b\u5efa\u4e86\u6570\u636e\u5e93\u6587\u4ef6\u3002<\/p>\n<p>\u521b\u5efa Shark \u6570\u636e\u5e93\u540e\uff0c\u60a8\u73b0\u5728\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u8868\u5e76\u7528\u6570\u636e\u586b\u5145\u5b83\u3002<\/p>\n<h3>\u7b2c 3 \u6b65\uff1a\u521b\u5efa SQLite \u8868<\/h3>\n<p>SQLite \u6570\u636e\u5e93\u88ab\u7ec4\u7ec7\u6210\u8868\u3002\u8868\u5b58\u50a8\u4fe1\u606f\u3002\u4e3a\u4e86\u66f4\u597d\u5730\u53ef\u89c6\u5316\u8868\u683c\uff0c\u53ef\u4ee5\u60f3\u8c61\u884c\u548c\u5217\u3002<\/p>\n<p>\u672c\u6559\u7a0b\u7684\u5176\u4f59\u90e8\u5206\u5c06\u9075\u5faa\u8f93\u5165 SQLite \u547d\u4ee4\u7684\u901a\u7528\u7ea6\u5b9a\u3002SQLite \u547d\u4ee4\u662f\u5927\u5199\u7684\uff0c\u7528\u6237\u4fe1\u606f\u662f\u5c0f\u5199\u7684\u3002\u884c<strong>\u5fc5\u987b<\/strong>\u4ee5\u5206\u53f7\u7ed3\u5c3e\u3002<\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u4e3a\u5404\u79cd\u6570\u636e\u521b\u5efa\u4e00\u4e2a\u8868\u548c\u4e00\u4e9b\u5217\uff1a<\/p>\n<ul>\n<li>ID<\/li>\n<li>name\uff08\u540d\u5b57\uff09<\/li>\n<li>type\uff08\u7c7b\u578b\uff09<\/li>\n<li>\u6570\u503c<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u8868\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; CREATE TABLE linuxmi(id integer NOT NULL, name text NOT NULL, sharktype text NOT NULL, length integer NOT NULL);<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11327\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/4.png\" alt=\"\" width=\"964\" height=\"57\" \/><\/p>\n<p>\u4f7f\u7528<code>NOT NULL<\/code>\u4f7f\u8be5\u5b57\u6bb5\u6210\u4e3a\u5fc5\u9700\u7684\u3002\u6211\u4eec\u5c06<code>NOT NULL<\/code>\u5728\u4e0b\u4e00\u8282\u4e2d\u66f4\u8be6\u7ec6\u5730\u8ba8\u8bba\u3002<\/p>\n<p>\u521b\u5efa\u8868\u540e\uff0c\u5c06\u8fd4\u56de\u4e00\u4e2a\u7a7a\u63d0\u793a\u3002\u73b0\u5728\u8ba9\u6211\u4eec\u5728\u5176\u4e2d\u63d2\u5165\u4e00\u4e9b\u503c\u3002<\/p>\n<h3 id=\"inserting-values-into-tables\">\u5c06\u503c\u63d2\u5165\u8868\u4e2d<\/h3>\n<p>\u5728 SQLite \u4e2d\uff0c\u5c06\u503c\u63d2\u5165\u8868\u7684\u547d\u4ee4\u9075\u5faa\u4ee5\u4e0b\u4e00\u822c\u5f62\u5f0f\uff1a<\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; INSERT INTO tablename VALUES(\u503c\u5230\u8fd9\u91cc);<\/code><\/pre>\n<\/div>\n<\/div>\n<p>\u8868\u7684\u540d\u79f0\u5728<code><span class=\"highlight\">tablename<\/span><\/code>\u8fd9\u91cc\uff0c<code><span class=\"highlight\">values<\/span><\/code>\u503c\u5728\u62ec\u53f7\u5185\u3002<\/p>\n<p>\u73b0\u5728\u5728<code>linuxmi<\/code>\u8868\u4e2d\u7684<code>VALUES<\/code>\u4e2d\u63d2\u5165\u4e09\u884c\uff1a<\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\">\n<ul class=\"prefixed\">\n<li class=\"line\" style=\"box-sizing: border-box; margin: 0px 0px 0px -5px; padding: 0px; list-style: outside none none; white-space: pre;\" data-prefix=\"sqlite&gt;\">sqlite&gt; INSERT INTO linuxmi VALUES <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span>, <span class=\"token string\">&#8220;Ubuntu&#8221;<\/span>, <span class=\"token string\">&#8220;Linux&#8221;<\/span>, <span class=\"token number\">500<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li>\n<li class=\"line\" style=\"box-sizing: border-box; margin: 0px 0px 0px -5px; padding: 0px; list-style: outside none none; white-space: pre;\" data-prefix=\"sqlite&gt;\">sqlite&gt; INSERT INTO linuxmi VALUES <span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span>, <span class=\"token string\">&#8220;SQLite&#8221;<\/span>, <span class=\"token string\">&#8220;SQL&#8221;<\/span>, <span class=\"token number\">600<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li>\n<li class=\"line\" style=\"box-sizing: border-box; margin: 0px 0px 0px -5px; padding: 0px; list-style: outside none none; white-space: pre;\" data-prefix=\"sqlite&gt;\">sqlite&gt; INSERT INTO linuxmi VALUES <span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span>, <span class=\"token string\">&#8220;Python&#8221;<\/span>, <span class=\"token string\">&#8220;Programming&#8221;<\/span>, <span class=\"token number\">1000<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p>\u56e0\u4e3a\u60a8\u4e4b\u524d<code>NOT NULL<\/code>\u4e3a\u8868\u4e2d\u7684\u6bcf\u4e2a\u53d8\u91cf\u6307\u5b9a\u4e86\u503c\uff0c\u6240\u4ee5\u60a8\u5fc5\u987b\u4e3a\u6bcf\u4e2a\u53d8\u91cf\u8f93\u5165\u4e00\u4e2a\u503c\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5c1d\u8bd5\u6dfb\u52a0\u53e6\u4e00\u6761linuxmi\u800c\u4e0d\u8bbe\u7f6e\u5176\u6570\u503c\uff1a<\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; INSERT INTO linuxmi VALUES (4, \"Html\", \"WEB\");<\/code><\/pre>\n<p>\u60a8\u5c06\u6536\u5230\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n<\/div>\n<\/div>\n<p><code>Error: in prepare, table linuxmi has 4 columns but 3 values were supplied (1)Error: table sharks has 4 columns but 3 values were supplied<\/code><\/p>\n<p>\u4ee5\u4e0a\u6b65\u9aa4\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11328\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/5.png\" alt=\"\" width=\"1056\" height=\"287\" \/><\/p>\n<p>\u5728\u6b64\u6b65\u9aa4\u4e2d\uff0c\u60a8\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\u5e76\u5411\u5176\u4e2d\u63d2\u5165\u4e86\u503c\u3002\u5728\u4e0b\u4e00\u6b65\u4e2d\uff0c\u60a8\u5c06\u4ece\u6570\u636e\u5e93\u8868\u4e2d\u8bfb\u53d6\u3002<\/p>\n<h2 id=\"step-4-mdash-reading-tables-in-sqlite\">\u7b2c 4 \u6b65\uff1a\u5728 SQLite \u4e2d\u8bfb\u53d6\u8868<\/h2>\n<p>\u5728\u8fd9\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u4ece\u8868\u4e2d\u8bfb\u53d6\u6570\u636e\u7684\u6700\u57fa\u672c\u65b9\u6cd5\u3002\u8ba4\u8bc6\u5230 SQLite \u63d0\u4f9b\u4e86\u66f4\u5177\u4f53\u7684\u65b9\u6cd5\u6765\u67e5\u770b\u8868\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<p>\u8981\u67e5\u770b\u5305\u542b\u6240\u6709\u63d2\u5165\u503c\u7684\u8868\uff0c\u8bf7\u4f7f\u7528<code>SELECT<\/code>\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; SELECT * FROM linuxmi;<\/code><\/pre>\n<p>\u60a8\u5c06\u770b\u5230\u4e4b\u524d\u63d2\u5165\u7684\u6761\u76ee\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">1|Ubuntu|Linux|500\r\n2|SQLite|SQL|600\r\n3|Python|Programming|1000<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11329\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/6.png\" alt=\"\" width=\"1056\" height=\"260\" \/><\/p>\n<p>\u8981\u6839\u636e\u6761\u76ee<code>id<\/code>\uff08\u6211\u4eec\u624b\u52a8\u8bbe\u7f6e\u7684\u503c\uff09\u67e5\u770b\u6761\u76ee\uff0c\u8bf7\u5c06<code>WHERE<\/code>\u547d\u4ee4\u6dfb\u52a0\u5230\u60a8\u7684\u67e5\u8be2\u4e2d\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; SELECT * FROM linuxmi WHERE id IS 2;<\/code><\/pre>\n<p>\u8fd9\u5c06\u8fd4\u56de<code>id<\/code>\u7b49\u4e8e\u7684linuxmi<code>2<\/code>\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">2|SQLite|SQL|600<\/code><\/pre>\n<p>\u8ba9\u6211\u4eec\u4ed4\u7ec6\u770b\u770b\u8fd9\u4e2a\u547d\u4ee4\u3002<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u6211\u4eec<code>SELECT<\/code>\u6240\u6709\u7684 (\u00a0<code>*<\/code>) \u503c\u90fd\u6765\u81ea\u6211\u4eec\u7684\u6570\u636e\u5e93\uff0c<code>linuxmi<\/code>.<\/li>\n<li>\u7136\u540e\u6211\u4eec\u67e5\u770b\u6240\u6709<code>id<\/code>\u503c\u3002<\/li>\n<li>\u7136\u540e\u6211\u4eec\u8fd4\u56de\u6240\u6709<code>id<\/code>\u7b49\u4e8e \u7684\u8868\u6761\u76ee<code>2<\/code>\u3002<\/li>\n<\/ol>\n<p>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11330\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/7.png\" alt=\"\" width=\"1056\" height=\"206\" \/><\/p>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u60a8\u5df2\u7ecf\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\uff0c\u5411\u5176\u4e2d\u63d2\u5165\u4e86\u6570\u636e\uff0c\u5e76\u67e5\u8be2\u4e86\u4fdd\u5b58\u7684\u6570\u636e\u3002\u73b0\u5728\u60a8\u5c06\u66f4\u65b0\u73b0\u6709\u8868\u3002<\/p>\n<h2 id=\"step-5-mdash-updating-tables-in-sqlite\">\u7b2c 5 \u6b65\uff1a\u5728 SQLite \u4e2d\u66f4\u65b0\u8868<\/h2>\n<p>\u5728\u4ee5\u4e0b\u4e24\u90e8\u5206\u4e2d\uff0c\u60a8\u5c06\u9996\u5148\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u5217\uff0c\u7136\u540e\u66f4\u65b0\u8868\u4e2d\u7684\u73b0\u6709\u503c\u3002<\/p>\n<h3 id=\"adding-columns-to-sqlite-tables\">\u5411 SQLite \u8868\u6dfb\u52a0\u5217<\/h3>\n<p>SQLite \u5141\u8bb8\u60a8\u4f7f\u7528<code>ALTER TABLE<\/code>\u547d\u4ee4\u66f4\u6539\u8868\u3002\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u521b\u5efa\u65b0\u7684\u884c\u548c\u5217\uff0c\u6216\u4fee\u6539\u73b0\u6709\u7684\u884c\u548c\u5217\u3002<\/p>\n<p>\u4f7f\u7528<code>ALTER TABLE<\/code>\u521b\u5efa\u4e00\u4e2a\u65b0\u5217\u3002<\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; ALTER TABLE linuxmi ADD COLUMN xxvi integer;<\/code><\/pre>\n<p>\u60a8\u73b0\u5728\u6709\u7b2c\u4e94\u5217\uff0c<code>xxvi<\/code>.<\/p>\n<\/div>\n<\/div>\n<h3 id=\"updating-values-in-sqlite-tables\">\u66f4\u65b0 SQLite \u8868\u4e2d\u7684\u503c<\/h3>\n<p>\u4f7f\u7528\u8be5<code>UPDATE<\/code>\u547d\u4ee4\uff0c<code>xxvi<\/code>\u4e3a\u6bcf\u6761linuxmi\u6dfb\u52a0\u65b0\u503c\uff1a<\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\"><\/div>\n<\/div>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; UPDATE linuxmi SET xxvi = 168 WHERE id=1;\r\nsqlite&gt; UPDATE linuxmi SET xxvi = 178 WHERE id=2;\r\nsqlite&gt; UPDATE linuxmi SET xxvi = 688 WHERE id=3;<\/code><\/pre>\n<p>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11333\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/9.png\" alt=\"\" width=\"1056\" height=\"260\" \/><\/p>\n<p>\u5728\u6b64\u6b65\u9aa4\u4e2d\uff0c\u60a8\u66f4\u6539\u4e86\u8868\u683c\u7684\u7ec4\u6210\uff0c\u7136\u540e\u66f4\u65b0\u4e86\u8868\u683c\u5185\u7684\u503c\u3002\u5728\u4e0b\u4e00\u6b65\u4e2d\uff0c\u60a8\u5c06\u4ece\u8868\u4e2d\u5220\u9664\u4fe1\u606f\u3002<\/p>\n<h2 id=\"step-6-mdash-deleting-information-in-sqlite\">\u7b2c 6 \u6b65\uff1a\u5728 SQLite \u4e2d\u5220\u9664\u4fe1\u606f<\/h2>\n<p>\u5728\u6b64\u6b65\u9aa4\u4e2d\uff0c\u60a8\u5c06\u6839\u636e\u5bf9\u53c2\u6570\u7684\u8bc4\u4f30\u5220\u9664\u8868\u4e2d\u7684\u6761\u76ee\u3002<\/p>\n<p>\u5728\u4e0b\u9762\u7684\u547d\u4ee4\u4e2d\uff0c\u60a8\u5c06\u67e5\u8be2\u6570\u636e\u5e93\u5e76\u8bf7\u6c42\u5b83\u5220\u9664\u8868\u4e2dxxvi\u5c0f\u4e8e200\u7684\u6240\u6709linuxmi:<\/p>\n<pre class=\"pure-highlightjs\">sqlite&gt; DELETE FROM linuxmi WHERE xxvi &lt;= 200;<\/pre>\n<p>\u952e\u5165<span style=\"color: #222222; font-family: Monaco, Consolas, Andale Mono, DejaVu Sans Mono, monospace;\"><span style=\"background-color: #e9ebec;\"> SELECT * FROM linuxmi;<\/span><\/span><code><\/code>\u5c06\u9a8c\u8bc1<code>Ubuntu<\/code>\u548c<code>SQLite<\/code>\uff0cxxvi \u5217\u90fd\u5c0f\u4e8e 200 \uff0c\u5c06\u88ab\u5220\u9664\u3002\u53ea\u5269<code>Python<\/code>\u8fd9\u4e00\u884c\uff1a<\/p>\n<p>\u5982\u4e0b\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">3|Python|Programming|1000|688<\/code><\/pre>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11334\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/10.png\" alt=\"\" width=\"1056\" height=\"233\" \/><\/h2>\n<h2 id=\"step-7-mdash-joining-information-in-sqlite\">\u7b2c 7 \u6b65\uff1a\u5728 SQLite \u4e2d\u52a0\u5165\u4fe1\u606f<\/h2>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u8868\uff1a\u5f53\u524d<code>linuxmi<\/code>\u8868\u548c\u4e00\u4e2a<code>dashixiong<\/code>\u8868\u3002\u73b0\u5728\uff0c\u5982\u679c\u8be5<code>dashixiong<\/code>\u8868\u6709\u4e00\u4e2a<code>id<\/code>\u6620\u5c04\u5230<code>linuxmi<\/code>\u8868\u4e2d<code>id<\/code>\u7684\u503c\uff0c\u5e76\u4e14\u5b83\u8fd8\u6709\u4e00\u4e2a<code>status<\/code>\u503c\u6765\u6307\u793alinuxmi\u7684\u72b6\u6001\uff1f<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u4ece\u4e24\u4e2a\u8868\u4e2d\u67e5\u8be2\u6570\u636e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 SQLite \u7684\u56db\u4e2a<code>JOIN<\/code>\u8fde\u63a5\u547d\u4ee4\u4e4b\u4e00\uff1a<\/p>\n<ul>\n<li><code>INNER JOIN<\/code><\/li>\n<li><code>OUTER JOIN<\/code><\/li>\n<li><code>LEFT JOIN<\/code><\/li>\n<li><code>CROSS JOIN<\/code><\/li>\n<\/ul>\n<p>\u8ba9\u6211\u4eec\u521b\u5efa\u7b2c\u4e8c\u4e2a\u8868\uff0c\u7136\u540e\u7528\u4e8e<code>INNER JOIN<\/code>\u8fde\u63a5\u4e00\u4e9b\u6570\u636e\u3002<\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u4f60\u7684<code>dashixiong<\/code>\u8868\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; CREATE TABLE dashixiong (id integer NOT NULL, status text NOT NULL);\r\nsqlite&gt; INSERT INTO dashixiong VALUES (1, \"www.linuxmi.com\");<\/code><\/pre>\n<p>\u5982\u4e0b\u56fe<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11337\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/13.png\" alt=\"\" width=\"1056\" height=\"206\" \/><\/p>\n<p>\u73b0\u5728\u52a0\u5165\u4f60\u7684\u8868\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; SELECT * FROM linuxmi INNER JOIN dashixiong on linuxmi.id = dashixiong.id;<\/code><\/pre>\n<p>\u60a8\u7684\u8f93\u51fa\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"code-pre \"><code>1|Ubuntu|Linux|500|168|1|www.linuxmi.comr<\/code><\/pre>\n<p>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11336\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/12.png\" alt=\"\" width=\"1056\" height=\"233\" \/><\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u8f93\u51fa\u8fd8\u5305\u62ec\u6765\u81ea <code>dashixiong<\/code>\u00a0\u7684<code>id<\/code> \u503c\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u66f4\u660e\u786e\u7684\u547d\u4ee4\u6307\u5b9a\u6240\u9700\u7684\u8f93\u51fa<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">sqlite&gt; SELECT linuxmi.id, linuxmi.name, linuxmi.sharktype, linuxmi.length, linuxmi.xxvi, dashixiong.status FROM linuxmi INNER JOIN dashixiong on linuxmi.id = dashixiong.id;<\/code><\/pre>\n<p>\u8fd9\u6b21\u8f93\u51fa\u4e0d\u5305\u62ec\u7b2c\u4e8c\u4e2a\u503c\u7684<code>id<\/code>\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">1|Ubuntu|Linux|500|168|www.linuxmi.com<\/code><\/pre>\n<p>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11338\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/15.png\" alt=\"\" width=\"1056\" height=\"260\" \/><\/p>\n<p>\u60a8\u73b0\u5728\u5df2\u7ecf\u6210\u529f\u5730\u8fde\u63a5\u4e86\u6765\u81ea\u591a\u4e2a\u8868\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 \u53ef\u89c6\u5316\u6570\u636e\u5e93\u6d4f\u89c8\u5668 DB Browser for SQLite \u6765\u6d4f\u89c8\u4fee\u6539 SQLite \u6570\u636e\u5e93\uff0c\u5177\u4f53\u89c1\uff1a<a href=\"https:\/\/www.linuxmi.com\/db-browser-for-sqlite-linux.html\">https:\/\/www.linuxmi.com\/db-browser-for-sqlite-linux.html<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11344\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/12\/16.png\" alt=\"\" width=\"1027\" height=\"719\" \/><\/p>\n<h2 id=\"conclusion\">\u7ed3\u8bba<\/h2>\n<p>SQLite \u662f\u4e00\u4e2a\u6709\u7528\u7684\u6570\u636e\u5e93\u7ba1\u7406\u5de5\u5177\u3002\u4eba\u4eec\u53ef\u4ee5\u5feb\u901f\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u5e76\u4f7f\u7528\u5404\u79cd\u547d\u4ee4\u5bf9\u5176\u8fdb\u884c\u64cd\u4f5c\u3002\u6309\u7167\u672c\u6559\u7a0b\uff0c\u60a8\u73b0\u5728\u5bf9 SQLite \u6709\u4e86\u57fa\u672c\u7684\u4e86\u89e3\uff0c\u5e76\u51c6\u5907\u6df1\u5165\u4e86\u89e3\u8fd9\u4e2a\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u3002<\/p>\n<p>\u5bf9\u4e8e SQLite \u8bed\u6cd5\u7684\u5177\u4f53\u5e2e\u52a9\uff0c\u5e94\u8be5\u8bf4<a href=\"https:\/\/www.sqlite.org\/docs.html\" target=\"_blank\" rel=\"nofollow noopener\">\u5b98\u65b9\u6587\u6863<\/a>\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u8d44\u6e90\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd SQLite\u662f\u4e00\u4e2a\u514d\u8d39\u7684\u8de8\u5e73\u53f0\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u3002\u5b83\u56e0\u5176\u6548\u7387\u548c\u4e0e\u8bb8\u591a\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u63a5\u53e3\u7684\u80fd\u529b\u800c\u5e7f\u53d7\u6b22 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[659],"class_list":["post-11320","post","type-post","status-publish","format-standard","hentry","category-linux","tag-sqlite"],"aioseo_notices":[],"views":4432,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/11320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=11320"}],"version-history":[{"count":11,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/11320\/revisions"}],"predecessor-version":[{"id":11345,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/11320\/revisions\/11345"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=11320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=11320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=11320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}