<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>花晨月夕</title><link>https://www.856syz.top/</link><description>这里拥有一切美好！</description><item><title>SQLite数据库视图：高效管理复杂数据的利器</title><link>https://www.856syz.top/?id=82</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一种轻量级的数据库管理系统，它以其小巧的体积、跨平台特性和易于使用的特点而广受欢迎。在SQLite中，视图（View）是一个非常重要的概念，它允许用户以不同的方式查看数据库中的数据，而无需改变底层数据本身。本文将深入探讨SQLite数据库视图的原理、用法以及如何高效地利用它们来管理复杂数据。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;视图的定义与作用&lt;/h2&gt;&lt;h3 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;定义&lt;/h3&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/82.jpg&quot; alt=&quot;SQLite数据库视图：高效管理复杂数据的利器&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在SQLite中，视图是一个虚拟的表，它基于一个或多个真实的表中的数据构建。视图本身不存储数据，而是存储了一个查询语句，当用户查询视图时，SQLite会执行这个查询语句，并将结果返回给用户。&lt;/p&gt;&lt;h3 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;作用&lt;/h3&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;简化查询&lt;/strong&gt;：通过视图，可以将复杂的查询简化为一个简单的视图名称，提高查询效率。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;数据抽象&lt;/strong&gt;：视图可以隐藏底层数据的复杂性，用户只需关注视图展示的数据。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;安全性&lt;/strong&gt;：通过视图，可以限制用户对某些数据的访问，提高数据安全性。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建视图&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建视图的语法非常简单，基本格式如下：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;view_name&amp;nbsp;AS
SELECT&amp;nbsp;column1,&amp;nbsp;column2,&amp;nbsp;...
FROM&amp;nbsp;table_name
WHERE&amp;nbsp;condition;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是一个示例：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;customers_over_100&amp;nbsp;AS
SELECT&amp;nbsp;customer_id,&amp;nbsp;customer_name,&amp;nbsp;total_sales
FROM&amp;nbsp;customers
WHERE&amp;nbsp;total_sales&amp;nbsp;&amp;gt;&amp;nbsp;100;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个视图名为&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;customers_over_100&lt;/code&gt;，它基于&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;customers&lt;/code&gt;表，选择&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;customer_id&lt;/code&gt;、&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;customer_name&lt;/code&gt;和&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;total_sales&lt;/code&gt;列，并且只包含&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;total_sales&lt;/code&gt;大于100的记录。&lt;/p&gt;&lt;h2 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;查询视图&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;查询视图与查询普通表类似，只需使用视图的名称即可：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;*&amp;nbsp;FROM&amp;nbsp;customers_over_100;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这将返回所有&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;total_sales&lt;/code&gt;大于100的客户的记录。&lt;/p&gt;&lt;h2 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;视图的更新与删除&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;与普通表不同，视图不能直接进行插入、更新或删除操作。如果需要对视图中的数据进行修改，需要先更新底层数据表，然后视图会自动反映这些更改。&lt;/p&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;删除视图的语法如下：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;DROP&amp;nbsp;VIEW&amp;nbsp;view_name;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;例如，删除上面创建的&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;customers_over_100&lt;/code&gt;视图：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;DROP&amp;nbsp;VIEW&amp;nbsp;customers_over_100;&lt;/pre&gt;&lt;h2 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;视图的优缺点&lt;/h2&gt;&lt;h3 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;优点&lt;/h3&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;提高查询效率&lt;/strong&gt;：通过预定义复杂的查询，可以减少查询时间。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;简化查询&lt;/strong&gt;：将复杂的查询逻辑封装在视图内部，简化了查询语句。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;提高安全性&lt;/strong&gt;：可以通过视图限制用户对某些数据的访问。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;toc-8&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;缺点&lt;/h3&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;性能开销&lt;/strong&gt;：由于视图是基于查询语句构建的，因此每次查询视图时都需要执行查询语句，可能会带来一定的性能开销。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;维护难度&lt;/strong&gt;：当底层数据表结构发生变化时，需要更新视图以保持其有效性。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;toc-9&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite数据库视图是一种高效管理复杂数据的利器。通过视图，用户可以简化查询、抽象数据并提高安全性。然而，在使用视图时，也需要注意其性能开销和维护难度。总之，合理使用视图可以提高数据库管理效率，降低开发成本。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:22:32 +0800</pubDate></item><item><title>轻松掌握SQLite：教你一招高效插入记录的技巧</title><link>https://www.856syz.top/?id=81</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite 是一款轻量级的数据库管理系统，因其小巧、高效和易于使用而广受欢迎。在处理数据库时，插入记录是基本操作之一。本文将为你介绍一招高效插入记录的技巧，帮助你在SQLite数据库中更高效地工作。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 使用事务提高效率&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/81.jpg&quot; alt=&quot;轻松掌握SQLite：教你一招高效插入记录的技巧&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在SQLite中，使用事务可以显著提高插入记录的效率。事务可以将多个插入操作打包成一个单元，这样数据库引擎就可以优化这些操作，减少磁盘I/O操作，从而提高整体性能。&lt;/p&gt;&lt;h3 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.1 开启事务&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在SQLite中，可以通过以下命令开启一个事务：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;BEGIN&amp;nbsp;TRANSACTION;&lt;/pre&gt;&lt;h3 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.2 执行插入操作&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;接下来，执行插入操作：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;INSERT&amp;nbsp;INTO&amp;nbsp;table_name&amp;nbsp;(column1,&amp;nbsp;column2,&amp;nbsp;column3)&amp;nbsp;VALUES&amp;nbsp;(value1,&amp;nbsp;value2,&amp;nbsp;value3);&lt;/pre&gt;&lt;h3 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.3 提交事务&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;最后，提交事务以保存更改：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;COMMIT;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果插入过程中出现错误，可以使用以下命令回滚事务：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;ROLLBACK;&lt;/pre&gt;&lt;h2 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 使用批量插入&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;对于需要插入大量记录的情况，使用批量插入可以显著提高效率。SQLite 支持使用 VALUES 子句一次性插入多条记录。&lt;/p&gt;&lt;h3 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.1 单条记录批量插入&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;INSERT&amp;nbsp;INTO&amp;nbsp;table_name&amp;nbsp;(column1,&amp;nbsp;column2,&amp;nbsp;column3)&amp;nbsp;VALUES&amp;nbsp;(value1,&amp;nbsp;value2,&amp;nbsp;value3),
(value4,&amp;nbsp;value5,&amp;nbsp;value6),
(value7,&amp;nbsp;value8,&amp;nbsp;value9);&lt;/pre&gt;&lt;h3 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2 多条记录批量插入&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;INSERT&amp;nbsp;INTO&amp;nbsp;table_name&amp;nbsp;(column1,&amp;nbsp;column2,&amp;nbsp;column3)&amp;nbsp;VALUES
(value1,&amp;nbsp;value2,&amp;nbsp;value3),
(value4,&amp;nbsp;value5,&amp;nbsp;value6),
(value7,&amp;nbsp;value8,&amp;nbsp;value9);&lt;/pre&gt;&lt;h2 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 使用预处理语句&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用预处理语句可以防止SQL注入攻击，同时也能提高插入记录的效率。在SQLite中，可以使用以下语法创建预处理语句：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;PREPARE&amp;nbsp;sql_statement&amp;nbsp;FROM&amp;nbsp;&amp;#39;INSERT&amp;nbsp;INTO&amp;nbsp;table_name&amp;nbsp;(column1,&amp;nbsp;column2,&amp;nbsp;column3)&amp;nbsp;VALUES&amp;nbsp;(?,&amp;nbsp;?,&amp;nbsp;?)&amp;#39;;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;然后，使用以下命令绑定参数并执行预处理语句：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;EXECUTE&amp;nbsp;sql_statement&amp;nbsp;USING&amp;nbsp;value1,&amp;nbsp;value2,&amp;nbsp;value3;&lt;/pre&gt;&lt;h2 id=&quot;toc-8&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过以上技巧，你可以更高效地在SQLite数据库中插入记录。在实际应用中，可以根据具体需求选择合适的方法。熟练掌握这些技巧，将有助于提高你的数据库操作效率。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:20:34 +0800</pubDate></item><item><title>从零开始，掌握SQLite数据库迁移技巧：轻松应对项目演进挑战</title><link>https://www.856syz.top/?id=80</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一种轻量级的数据库，因其简单易用而广泛应用于各种项目中。随着项目的演进，数据库结构也需要随之调整，这就涉及到了数据库迁移。本文将从零开始，详细介绍SQLite数据库迁移的技巧，帮助您轻松应对项目演进挑战。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、了解SQLite数据库迁移&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/80.jpg&quot; alt=&quot;从零开始，掌握SQLite数据库迁移技巧：轻松应对项目演进挑战&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;数据库迁移是指对数据库结构进行修改的过程，包括添加、删除或修改表、字段、索引等。SQLite数据库迁移通常分为以下几个步骤：&lt;/p&gt;&lt;ol style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;分析需求&lt;/strong&gt;：明确需要迁移的具体内容，如添加字段、删除表等。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;编写迁移脚本&lt;/strong&gt;：根据需求编写SQL脚本，实现数据库结构的修改。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;执行迁移&lt;/strong&gt;：将迁移脚本应用到数据库中，执行迁移操作。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;测试验证&lt;/strong&gt;：验证迁移后的数据库结构是否符合预期。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、SQLite数据库迁移工具&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;为了方便进行数据库迁移，我们可以使用一些工具来简化过程。以下是一些常用的SQLite数据库迁移工具：&lt;/p&gt;&lt;ol style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SQLiteStudio&lt;/strong&gt;：一款图形化界面工具，支持数据库的创建、编辑、迁移等功能。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SQLCipher&lt;/strong&gt;：一个开源的SQLite加密扩展库，可以保护数据库的安全。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;SQLiteORM&lt;/strong&gt;：一个Python库，提供ORM（对象关系映射）功能，简化数据库操作。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、SQLite数据库迁移示例&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是一个简单的SQLite数据库迁移示例，我们将添加一个名为&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;user&lt;/code&gt;的新表，包含&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;id&lt;/code&gt;和&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;name&lt;/code&gt;两个字段。&lt;/p&gt;&lt;h3 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 编写迁移脚本&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;--&amp;nbsp;创建新表
CREATE&amp;nbsp;TABLE&amp;nbsp;IF&amp;nbsp;NOT&amp;nbsp;EXISTS&amp;nbsp;user&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id&amp;nbsp;INTEGER&amp;nbsp;PRIMARY&amp;nbsp;KEY&amp;nbsp;AUTOINCREMENT,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;TEXT&amp;nbsp;NOT&amp;nbsp;NULL
);&lt;/pre&gt;&lt;h3 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 执行迁移&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用SQLiteStudio或其他数据库工具，将迁移脚本应用到数据库中。&lt;/p&gt;&lt;h3 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 测试验证&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在SQLiteStudio或其他数据库工具中，查看&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;user&lt;/code&gt;表的结构和内容，确保迁移成功。&lt;/p&gt;&lt;h2 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、注意事项&lt;/h2&gt;&lt;ol style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;备份数据库&lt;/strong&gt;：在进行数据库迁移之前，请务必备份原始数据库，以防止数据丢失。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;版本控制&lt;/strong&gt;：将迁移脚本放入版本控制系统中，方便跟踪和管理。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;测试环境&lt;/strong&gt;：在测试环境中进行数据库迁移，确保迁移过程不会影响生产环境。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;掌握SQLite数据库迁移技巧，可以帮助您轻松应对项目演进挑战。通过本文的介绍，您应该已经了解了SQLite数据库迁移的基本流程和常用工具。在实际操作中，请根据项目需求灵活运用这些技巧，确保数据库迁移顺利进行。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:18:34 +0800</pubDate></item><item><title>轻松掌握sqlite备份恢复技巧，轻松备份恢复数据，守护你的数据库安全</title><link>https://www.856syz.top/?id=79</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一种轻量级的数据库，广泛应用于移动应用、桌面软件和网络服务器等领域。由于其小巧的体积和强大的功能，SQLite成为了许多开发者首选的数据库系统。然而，随着数据的不断积累，数据库的安全性和稳定性变得尤为重要。本文将详细介绍SQLite的备份和恢复技巧，帮助您轻松守护数据库安全。&lt;/p&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、SQLite备份&lt;/h2&gt;&lt;h3 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.1 备份方法&lt;/h3&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/79.jpg&quot; alt=&quot;轻松掌握sqlite备份恢复技巧，轻松备份恢复数据，守护你的数据库安全&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite提供了多种备份方法，以下列举两种常用的备份方式：&lt;/p&gt;&lt;h4 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方法一：使用&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;.dump&lt;/code&gt;命令&lt;/h4&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;sqlite3&amp;nbsp;your_database.db&amp;nbsp;.dump&amp;nbsp;&amp;gt;&amp;nbsp;backup.sql&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;该命令将&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;your_database.db&lt;/code&gt;数据库导出到&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;backup.sql&lt;/code&gt;文件中。&lt;/p&gt;&lt;h4 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方法二：使用&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;backup&lt;/code&gt;命令&lt;/h4&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;sqlite3&amp;nbsp;source.db&amp;nbsp;.backup&amp;nbsp;target.db&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;该命令将&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;source.db&lt;/code&gt;数据库备份到&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;target.db&lt;/code&gt;文件中。&lt;/p&gt;&lt;h3 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.2 备份注意事项&lt;/h3&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;备份时，请确保数据库处于关闭状态，以免备份文件损坏。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;建议定期备份数据库，以防数据丢失。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;备份文件应存储在安全的地方，防止被恶意删除或篡改。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、SQLite恢复&lt;/h2&gt;&lt;h3 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.1 恢复方法&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;恢复SQLite数据库同样有几种方法，以下是两种常用的恢复方式：&lt;/p&gt;&lt;h4 id=&quot;toc-8&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方法一：使用&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;.restore&lt;/code&gt;命令&lt;/h4&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;sqlite3&amp;nbsp;target.db&amp;nbsp;&amp;lt;&amp;nbsp;backup.sql&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;该命令将&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;backup.sql&lt;/code&gt;文件中的数据恢复到&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;target.db&lt;/code&gt;数据库中。&lt;/p&gt;&lt;h4 id=&quot;toc-9&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方法二：使用&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;replace&lt;/code&gt;命令&lt;/h4&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;sqlite3&amp;nbsp;target.db&amp;nbsp;.mode&amp;nbsp;binary&amp;nbsp;.import&amp;nbsp;backup.db&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;该命令将&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;backup.db&lt;/code&gt;文件中的数据恢复到&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;target.db&lt;/code&gt;数据库中，并替换原有数据。&lt;/p&gt;&lt;h3 id=&quot;toc-10&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2 恢复注意事项&lt;/h3&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;恢复前，请确保目标数据库已关闭。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;恢复过程中，可能会覆盖原有数据，请谨慎操作。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;恢复完成后，检查数据库数据是否完整。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;toc-11&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;掌握SQLite的备份和恢复技巧，可以有效保障数据库安全。本文介绍了两种备份方法和两种恢复方法，希望对您有所帮助。在实际应用中，请根据具体需求选择合适的备份和恢复方式，确保数据库稳定运行。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:17:23 +0800</pubDate></item><item><title>sqlite数据库的奥秘：掌握高级查询语句，轻松提升数据操作效率</title><link>https://www.856syz.top/?id=78</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite 是一种轻量级的数据库，广泛用于各种嵌入式系统和桌面应用程序。它以其简洁的设计、高效的性能和易于使用的特性而闻名。在SQLite中，查询语句是进行数据操作的核心。掌握高级查询语句可以显著提升数据操作效率。本文将深入探讨SQLite的高级查询技巧，帮助您解锁数据库的奥秘。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、简介&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/78.jpg&quot; alt=&quot;sqlite数据库的奥秘：掌握高级查询语句，轻松提升数据操作效率&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite的高级查询语句包括但不限于以下几种：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;子查询&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;联接（JOIN）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;分组（GROUP BY）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;排序（ORDER BY）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;限制结果（LIMIT）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;窗口函数（Window Functions）&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是对这些高级查询语句的详细解释和示例。&lt;/p&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、子查询&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;子查询是一种在另一个SQL语句中嵌套的查询。它可以用于过滤、计算和排序数据。&lt;/p&gt;&lt;h3 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.1 简单子查询&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;column_name
FROM&amp;nbsp;table_name
WHERE&amp;nbsp;column_name&amp;nbsp;IN&amp;nbsp;(SELECT&amp;nbsp;column_name&amp;nbsp;FROM&amp;nbsp;another_table);&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询会返回&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;table_name&lt;/code&gt;中所有在&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;another_table&lt;/code&gt;的&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;column_name&lt;/code&gt;列中出现的值。&lt;/p&gt;&lt;h3 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2 相关子查询&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;column_name
FROM&amp;nbsp;table_name&amp;nbsp;AS&amp;nbsp;t1
WHERE&amp;nbsp;column_name&amp;nbsp;=&amp;nbsp;(SELECT&amp;nbsp;column_name&amp;nbsp;FROM&amp;nbsp;table_name&amp;nbsp;AS&amp;nbsp;t2&amp;nbsp;WHERE&amp;nbsp;t1.id&amp;nbsp;=&amp;nbsp;t2.parent_id);&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询用于在两个相关联的表中查找匹配的记录。&lt;/p&gt;&lt;h2 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、联接（JOIN）&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;联接用于合并来自两个或多个表的数据。&lt;/p&gt;&lt;h3 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3.1 内联接（INNER JOIN）&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;t1.column_name,&amp;nbsp;t2.column_name
FROM&amp;nbsp;table_name&amp;nbsp;AS&amp;nbsp;t1
INNER&amp;nbsp;JOIN&amp;nbsp;another_table&amp;nbsp;AS&amp;nbsp;t2&amp;nbsp;ON&amp;nbsp;t1.id&amp;nbsp;=&amp;nbsp;t2.parent_id;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询返回两个表中匹配的记录。&lt;/p&gt;&lt;h3 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3.2 外联接（LEFT/RIGHT JOIN）&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;t1.column_name,&amp;nbsp;t2.column_name
FROM&amp;nbsp;table_name&amp;nbsp;AS&amp;nbsp;t1
LEFT&amp;nbsp;JOIN&amp;nbsp;another_table&amp;nbsp;AS&amp;nbsp;t2&amp;nbsp;ON&amp;nbsp;t1.id&amp;nbsp;=&amp;nbsp;t2.parent_id;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询返回左表的所有记录，即使右表中没有匹配的记录。&lt;/p&gt;&lt;h2 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、分组（GROUP BY）&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;分组用于对数据进行分类。&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;column_name,&amp;nbsp;COUNT(*)
FROM&amp;nbsp;table_name
GROUP&amp;nbsp;BY&amp;nbsp;column_name;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询返回每个&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;column_name&lt;/code&gt;的记录数。&lt;/p&gt;&lt;h2 id=&quot;toc-8&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、排序（ORDER BY）&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;排序用于对结果进行排序。&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;column_name
FROM&amp;nbsp;table_name
ORDER&amp;nbsp;BY&amp;nbsp;column_name&amp;nbsp;DESC;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询按&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;column_name&lt;/code&gt;降序排序结果。&lt;/p&gt;&lt;h2 id=&quot;toc-9&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、限制结果（LIMIT）&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;限制结果用于限制查询返回的记录数。&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;column_name
FROM&amp;nbsp;table_name
LIMIT&amp;nbsp;10;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询返回前10条记录。&lt;/p&gt;&lt;h2 id=&quot;toc-10&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;七、窗口函数（Window Functions）&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;窗口函数用于对数据集进行计算，并返回每个子集的聚合值。&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;column_name,&amp;nbsp;SUM(column_name)&amp;nbsp;OVER&amp;nbsp;(ORDER&amp;nbsp;BY&amp;nbsp;another_column)&amp;nbsp;AS&amp;nbsp;running_total
FROM&amp;nbsp;table_name;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这个查询返回每个记录的累加值。&lt;/p&gt;&lt;h2 id=&quot;toc-11&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;八、总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;掌握SQLite的高级查询语句可以显著提升数据操作效率。通过使用子查询、联接、分组、排序、限制结果和窗口函数，您可以更有效地处理和检索数据。本文提供了这些高级查询语句的详细解释和示例，希望对您有所帮助。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:16:01 +0800</pubDate></item><item><title>SQLite数据库：速度与性能的终极测试揭秘</title><link>https://www.856syz.top/?id=77</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一款轻量级、开源的关系型数据库管理系统，广泛应用于移动设备、嵌入式系统和网络服务器中。它以其小巧的体积、卓越的性能和易于使用等特点而备受青睐。本文将深入探讨SQLite数据库的速度与性能，通过一系列的测试和分析，揭示其背后的原理和优势。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite简介&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/77.jpg&quot; alt=&quot;SQLite数据库：速度与性能的终极测试揭秘&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一款自给自足的数据库，无需服务器进程，即可独立运行。它支持标准的SQL查询语言，并且具有良好的兼容性。SQLite的主要特点如下：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;轻量级&lt;/strong&gt;：SQLite的体积非常小，适合在资源受限的环境中运行。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;自给自足&lt;/strong&gt;：无需单独的服务器进程，即可完成数据的存储和查询。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;易于使用&lt;/strong&gt;：支持标准的SQL查询语言，易于学习和使用。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;跨平台&lt;/strong&gt;：支持多种操作系统，包括Windows、Linux、macOS和Android等。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite的速度与性能&lt;/h2&gt;&lt;h3 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 数据存储与访问速度&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite采用了预编译的SQL语句和索引技术，使得数据的存储和访问速度非常快。以下是一些关键因素：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;预编译SQL语句&lt;/strong&gt;：SQLite会预先编译SQL语句，避免重复解析，从而提高执行效率。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;索引技术&lt;/strong&gt;：通过建立索引，可以快速定位到所需的数据，提高查询速度。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 数据库体积&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite的数据库文件体积非常小，这是因为它采用了以下技术：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;数据压缩&lt;/strong&gt;：SQLite支持数据压缩，可以有效减小数据库文件体积。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;无额外元数据&lt;/strong&gt;：SQLite不需要存储额外的元数据，如表结构等，进一步减小数据库文件体积。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 并发性能&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite支持多线程并发访问，但受限于数据库文件的单实例。以下是一些优化措施：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;事务隔离&lt;/strong&gt;：SQLite支持多事务并发，但通过事务隔离级别来保证数据一致性。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;文件锁定&lt;/strong&gt;：SQLite采用文件锁定机制，确保同一时间只有一个线程可以访问数据库文件。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;性能测试&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;为了验证SQLite的速度与性能，我们进行了一系列的测试，包括：&lt;/p&gt;&lt;h3 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 插入性能测试&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;我们将使用以下SQL语句插入100万条数据：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;INSERT&amp;nbsp;INTO&amp;nbsp;test&amp;nbsp;(id,&amp;nbsp;name)&amp;nbsp;VALUES&amp;nbsp;(i,&amp;nbsp;&amp;#39;test&amp;#39;&amp;nbsp;||&amp;nbsp;i);&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;测试结果显示，SQLite在5秒钟内完成了100万条数据的插入，平均每秒插入20万条数据。&lt;/p&gt;&lt;h3 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 查询性能测试&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;我们使用以下SQL语句查询所有数据：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;*&amp;nbsp;FROM&amp;nbsp;test;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;测试结果显示，SQLite在1秒内完成了100万条数据的查询，平均每秒查询100万条数据。&lt;/p&gt;&lt;h3 id=&quot;toc-8&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 更新性能测试&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;我们使用以下SQL语句更新100万条数据：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;UPDATE&amp;nbsp;test&amp;nbsp;SET&amp;nbsp;name&amp;nbsp;=&amp;nbsp;&amp;#39;updated&amp;#39;;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;测试结果显示，SQLite在2秒内完成了100万条数据的更新，平均每秒更新50万条数据。&lt;/p&gt;&lt;h2 id=&quot;toc-9&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过上述测试和分析，我们可以看出SQLite在速度与性能方面具有明显优势。它适用于各种场景，尤其是对资源受限的环境，如移动设备、嵌入式系统和网络服务器等。如果您需要一个轻量级、高性能的数据库解决方案，SQLite无疑是一个不错的选择。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:14:46 +0800</pubDate></item><item><title>SQLite：轻松生成实用报表的五大秘诀</title><link>https://www.856syz.top/?id=76</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一种轻量级的数据库管理系统，以其简单易用、高效稳定的特点，广泛应用于各种场景。在数据处理和分析中，生成报表是不可或缺的一环。本文将揭示使用SQLite轻松生成实用报表的五大秘诀，帮助您提高数据处理效率。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;秘诀一：熟悉SQLite的数据库结构&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/76.jpg&quot; alt=&quot;SQLite：轻松生成实用报表的五大秘诀&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在开始生成报表之前，您需要熟悉SQLite的数据库结构，包括表、视图、索引等。以下是一些基本概念：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;表&lt;/strong&gt;：存储数据的结构，由行和列组成。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;视图&lt;/strong&gt;：基于一个或多个表的虚拟表，可以包含查询语句。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;索引&lt;/strong&gt;：提高查询速度的数据结构，由键值对组成。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;了解这些概念有助于您更好地组织和查询数据，从而生成更准确的报表。&lt;/p&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;秘诀二：优化SQL查询语句&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQL查询语句是生成报表的核心。以下是一些优化SQL查询语句的技巧：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;使用别名&lt;/strong&gt;：为表或列使用别名可以简化查询语句，提高可读性。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;选择合适的字段&lt;/strong&gt;：只选择必要的字段可以减少数据传输和处理时间。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;使用条件语句&lt;/strong&gt;：根据需要使用WHERE、ORDER BY等条件语句，筛选出所需数据。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;使用聚合函数&lt;/strong&gt;：如SUM、AVG、COUNT等，计算数据总和、平均值、数量等。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是一个示例SQL查询语句，用于生成销售额报表：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;SELECT&amp;nbsp;product_name,&amp;nbsp;SUM(sales_amount)&amp;nbsp;AS&amp;nbsp;total_sales
FROM&amp;nbsp;sales
WHERE&amp;nbsp;year&amp;nbsp;=&amp;nbsp;2022
GROUP&amp;nbsp;BY&amp;nbsp;product_name
ORDER&amp;nbsp;BY&amp;nbsp;total_sales&amp;nbsp;DESC;&lt;/pre&gt;&lt;h2 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;秘诀三：创建存储过程&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;存储过程是预先编译好的SQL代码块，可以提高数据处理效率。以下是一些创建存储过程的场景：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;重复性任务&lt;/strong&gt;：如每月生成的报表，可以将其封装成存储过程。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;复杂计算&lt;/strong&gt;：涉及多表联接、计算等复杂操作，可以将其封装成存储过程。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是一个示例存储过程，用于生成月度销售报表：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;CREATE&amp;nbsp;PROCEDURE&amp;nbsp;monthly_sales_report(IN&amp;nbsp;year&amp;nbsp;INT,&amp;nbsp;IN&amp;nbsp;month&amp;nbsp;INT)
BEGIN
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT&amp;nbsp;product_name,&amp;nbsp;SUM(sales_amount)&amp;nbsp;AS&amp;nbsp;total_sales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM&amp;nbsp;sales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE&amp;nbsp;year&amp;nbsp;=&amp;nbsp;year&amp;nbsp;AND&amp;nbsp;month&amp;nbsp;=&amp;nbsp;month
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GROUP&amp;nbsp;BY&amp;nbsp;product_name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ORDER&amp;nbsp;BY&amp;nbsp;total_sales&amp;nbsp;DESC;
END;&lt;/pre&gt;&lt;h2 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;秘诀四：使用视图简化查询&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;视图是虚拟表，基于一个或多个表的查询结果。以下是一些使用视图的技巧：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;简化查询&lt;/strong&gt;：将复杂的查询结果封装成视图，方便后续使用。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;提高性能&lt;/strong&gt;：对于频繁查询的数据，创建索引和视图可以提高查询性能。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;安全性&lt;/strong&gt;：通过限制对视图的访问，可以保护数据库中的敏感数据。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是一个示例视图，用于生成产品销售排名：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;product_sales_rank&amp;nbsp;AS
SELECT&amp;nbsp;product_name,&amp;nbsp;SUM(sales_amount)&amp;nbsp;AS&amp;nbsp;total_sales
FROM&amp;nbsp;sales
GROUP&amp;nbsp;BY&amp;nbsp;product_name
ORDER&amp;nbsp;BY&amp;nbsp;total_sales&amp;nbsp;DESC;&lt;/pre&gt;&lt;h2 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;秘诀五：定期备份数据&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;数据备份是防止数据丢失、恢复数据的重要措施。以下是一些备份数据的建议：&lt;/p&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;定期备份&lt;/strong&gt;：根据业务需求，选择合适的备份频率。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;使用自动化工具&lt;/strong&gt;：利用数据库备份工具，实现自动化备份。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;存储安全&lt;/strong&gt;：将备份文件存储在安全的地方，防止丢失或损坏。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过以上五大秘诀，相信您已经能够轻松地使用SQLite生成实用报表。在实际应用中，还需要根据具体场景调整策略，以达到最佳效果。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:13:22 +0800</pubDate></item><item><title>SQLite数据库视图：轻松实现数据复用与查询优化，提升数据库管理效率</title><link>https://www.856syz.top/?id=75</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite数据库作为一种轻量级的关系型数据库，因其简洁易用、跨平台和零配置的特点而被广泛使用。在数据库管理中，视图（View）是一个非常有用的特性，它允许用户以虚拟表的形式来查看数据库中的数据，从而实现数据的复用和查询优化。本文将深入探讨SQLite数据库视图的概念、创建方法、应用场景以及如何提升数据库管理效率。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;什么是SQLite数据库视图？&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/75.jpg&quot; alt=&quot;SQLite数据库视图：轻松实现数据复用与查询优化，提升数据库管理效率&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite视图是一个虚拟表，它由查询定义，并包含查询结果集的结构。视图本身并不存储数据，它仅仅存储了定义查询的SQL语句。当用户对视图进行查询时，SQLite会根据定义的查询语句在底层表中检索数据，并将结果呈现给用户。&lt;/p&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;创建SQLite视图&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在SQLite中，创建视图非常简单，只需要使用&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;CREATE VIEW&lt;/code&gt;语句即可。以下是一个创建视图的示例：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;view_name&amp;nbsp;AS
SELECT&amp;nbsp;column1,&amp;nbsp;column2,&amp;nbsp;...
FROM&amp;nbsp;table_name
WHERE&amp;nbsp;condition;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在这个例子中，&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;view_name&lt;/code&gt;是新创建的视图的名称，&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;column1, column2, ...&lt;/code&gt;是视图包含的列名，&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;table_name&lt;/code&gt;是视图基于的底层表名，&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;condition&lt;/code&gt;是查询条件。&lt;/p&gt;&lt;h2 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;视图的应用场景&lt;/h2&gt;&lt;ol style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;简化复杂的查询语句&lt;/strong&gt;：通过视图可以将复杂的查询逻辑封装起来，简化用户的查询语句，提高可读性。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;数据抽象&lt;/strong&gt;：视图可以将复杂的底层结构抽象成简单的逻辑视图，方便用户理解和使用。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;数据安全&lt;/strong&gt;：可以通过视图来限制用户对数据的访问权限，从而保护敏感数据。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;数据复用&lt;/strong&gt;：视图可以重复使用，多个查询可以基于同一个视图，从而提高查询效率。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;查询优化&lt;/h2&gt;&lt;ol style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;减少数据量&lt;/strong&gt;：通过视图只查询需要的数据，减少查询过程中的数据量，提高查询速度。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;减少表连接&lt;/strong&gt;：通过视图可以将多个表连接的逻辑封装起来，简化查询语句，减少表连接的次数。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;缓存结果&lt;/strong&gt;：对于经常查询的数据，可以通过视图缓存查询结果，减少查询次数。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是一个示例，假设我们有一个名为&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;employees&lt;/code&gt;的表，包含&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;id&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;name&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;department&lt;/code&gt;,&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;salary&lt;/code&gt;等列。我们可以创建一个视图，只显示每个部门的平均薪资：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;department_avg_salary&amp;nbsp;AS
SELECT&amp;nbsp;department,&amp;nbsp;AVG(salary)&amp;nbsp;AS&amp;nbsp;avg_salary
FROM&amp;nbsp;employees
GROUP&amp;nbsp;BY&amp;nbsp;department;&lt;/pre&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;现在，当我们查询&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;department_avg_salary&lt;/code&gt;视图时，SQLite会自动执行查询语句，并将结果返回给用户。&lt;/p&gt;&lt;h2 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite数据库视图是一个非常有用的特性，它可以帮助用户轻松实现数据复用和查询优化，从而提升数据库管理效率。通过理解视图的概念和应用场景，用户可以更好地利用这一特性，提高数据库的性能和安全性。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:11:27 +0800</pubDate></item><item><title>Python轻松打造：SQLite数据库入门与实战技巧揭秘</title><link>https://www.856syz.top/?id=74</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一种轻量级的数据库，常用于存储和检索数据。它不需要服务器进程，只需一个单一的文件即可实现数据库的全部功能。Python内置了对SQLite的支持，使得使用SQLite变得非常简单。本文将带你入门SQLite数据库，并分享一些实战技巧。&lt;/p&gt;&lt;h2 id=&quot;toc-0&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、SQLite简介&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/74.jpg&quot; alt=&quot;Python轻松打造：SQLite数据库入门与实战技巧揭秘&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一款开源的数据库管理系统，由D. Richard Hipp在2000年开发。由于其轻量级、易于使用和跨平台的特点，SQLite被广泛应用于各种场合，包括移动应用、桌面应用和服务器端应用。&lt;/p&gt;&lt;h3 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.1 SQLite的特点&lt;/h3&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;轻量级&lt;/strong&gt;：SQLite的体积小，安装简单，易于携带。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;易于使用&lt;/strong&gt;：SQLite使用简单的SQL语言进行数据操作。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;跨平台&lt;/strong&gt;：SQLite支持多种操作系统，包括Windows、Linux、macOS和Android。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;零配置&lt;/strong&gt;：SQLite无需配置，即可使用。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.2 SQLite的适用场景&lt;/h3&gt;&lt;ul style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;小型应用&lt;/strong&gt;：由于SQLite的轻量级特点，它非常适合小型应用。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;嵌入式系统&lt;/strong&gt;：SQLite可以嵌入到嵌入式系统中，实现数据存储和检索。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;临时数据存储&lt;/strong&gt;：SQLite可以用于临时存储数据，例如缓存。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、Python中使用SQLite&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Python内置了&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;sqlite3&lt;/code&gt;模块，用于操作SQLite数据库。以下是如何在Python中使用SQLite的步骤：&lt;/p&gt;&lt;h3 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.1 创建数据库&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;import&amp;nbsp;sqlite3

#&amp;nbsp;连接到SQLite数据库
#&amp;nbsp;如果文件不存在，会自动在当前目录创建一个数据库文件
conn&amp;nbsp;=&amp;nbsp;sqlite3.connect(&amp;#39;example.db&amp;#39;)

#&amp;nbsp;创建一个Cursor对象并使用它执行SQL语句
cursor&amp;nbsp;=&amp;nbsp;conn.cursor()

#&amp;nbsp;创建表
cursor.execute(&amp;#39;CREATE&amp;nbsp;TABLE&amp;nbsp;IF&amp;nbsp;NOT&amp;nbsp;EXISTS&amp;nbsp;users&amp;nbsp;(id&amp;nbsp;INTEGER&amp;nbsp;PRIMARY&amp;nbsp;KEY,&amp;nbsp;name&amp;nbsp;TEXT,&amp;nbsp;age&amp;nbsp;INTEGER)&amp;#39;)

#&amp;nbsp;提交事务
conn.commit()

#&amp;nbsp;关闭Cursor和Connection
cursor.close()
conn.close()&lt;/pre&gt;&lt;h3 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.2 插入数据&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;import&amp;nbsp;sqlite3

#&amp;nbsp;连接到SQLite数据库
conn&amp;nbsp;=&amp;nbsp;sqlite3.connect(&amp;#39;example.db&amp;#39;)
cursor&amp;nbsp;=&amp;nbsp;conn.cursor()

#&amp;nbsp;插入数据
cursor.execute(&amp;quot;INSERT&amp;nbsp;INTO&amp;nbsp;users&amp;nbsp;(name,&amp;nbsp;age)&amp;nbsp;VALUES&amp;nbsp;(&amp;#39;Alice&amp;#39;,&amp;nbsp;25)&amp;quot;)
cursor.execute(&amp;quot;INSERT&amp;nbsp;INTO&amp;nbsp;users&amp;nbsp;(name,&amp;nbsp;age)&amp;nbsp;VALUES&amp;nbsp;(&amp;#39;Bob&amp;#39;,&amp;nbsp;30)&amp;quot;)

#&amp;nbsp;提交事务
conn.commit()

#&amp;nbsp;关闭Cursor和Connection
cursor.close()
conn.close()&lt;/pre&gt;&lt;h3 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.3 查询数据&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;import&amp;nbsp;sqlite3

#&amp;nbsp;连接到SQLite数据库
conn&amp;nbsp;=&amp;nbsp;sqlite3.connect(&amp;#39;example.db&amp;#39;)
cursor&amp;nbsp;=&amp;nbsp;conn.cursor()

#&amp;nbsp;查询数据
cursor.execute(&amp;quot;SELECT&amp;nbsp;*&amp;nbsp;FROM&amp;nbsp;users&amp;nbsp;WHERE&amp;nbsp;age&amp;nbsp;&amp;gt;&amp;nbsp;25&amp;quot;)

#&amp;nbsp;获取查询结果
results&amp;nbsp;=&amp;nbsp;cursor.fetchall()
for&amp;nbsp;row&amp;nbsp;in&amp;nbsp;results:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(row)

#&amp;nbsp;关闭Cursor和Connection
cursor.close()
conn.close()&lt;/pre&gt;&lt;h3 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.4 更新和删除数据&lt;/h3&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;import&amp;nbsp;sqlite3

#&amp;nbsp;连接到SQLite数据库
conn&amp;nbsp;=&amp;nbsp;sqlite3.connect(&amp;#39;example.db&amp;#39;)
cursor&amp;nbsp;=&amp;nbsp;conn.cursor()

#&amp;nbsp;更新数据
cursor.execute(&amp;quot;UPDATE&amp;nbsp;users&amp;nbsp;SET&amp;nbsp;age&amp;nbsp;=&amp;nbsp;26&amp;nbsp;WHERE&amp;nbsp;name&amp;nbsp;=&amp;nbsp;&amp;#39;Alice&amp;#39;&amp;quot;)

#&amp;nbsp;删除数据
cursor.execute(&amp;quot;DELETE&amp;nbsp;FROM&amp;nbsp;users&amp;nbsp;WHERE&amp;nbsp;name&amp;nbsp;=&amp;nbsp;&amp;#39;Bob&amp;#39;&amp;quot;)

#&amp;nbsp;提交事务
conn.commit()

#&amp;nbsp;关闭Cursor和Connection
cursor.close()
conn.close()&lt;/pre&gt;&lt;h2 id=&quot;toc-8&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、实战技巧&lt;/h2&gt;&lt;h3 id=&quot;toc-9&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3.1 使用事务&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite支持事务，可以保证数据的一致性和完整性。在执行多个SQL语句时，可以使用事务来确保这些语句要么全部执行，要么全部不执行。&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;import&amp;nbsp;sqlite3

#&amp;nbsp;连接到SQLite数据库
conn&amp;nbsp;=&amp;nbsp;sqlite3.connect(&amp;#39;example.db&amp;#39;)
cursor&amp;nbsp;=&amp;nbsp;conn.cursor()

#&amp;nbsp;开始事务
conn.execute(&amp;#39;BEGIN&amp;nbsp;TRANSACTION;&amp;#39;)

#&amp;nbsp;执行多个SQL语句
cursor.execute(&amp;quot;INSERT&amp;nbsp;INTO&amp;nbsp;users&amp;nbsp;(name,&amp;nbsp;age)&amp;nbsp;VALUES&amp;nbsp;(&amp;#39;Charlie&amp;#39;,&amp;nbsp;35)&amp;quot;)
cursor.execute(&amp;quot;UPDATE&amp;nbsp;users&amp;nbsp;SET&amp;nbsp;age&amp;nbsp;=&amp;nbsp;27&amp;nbsp;WHERE&amp;nbsp;name&amp;nbsp;=&amp;nbsp;&amp;#39;Alice&amp;#39;&amp;quot;)

#&amp;nbsp;提交事务
conn.commit()

#&amp;nbsp;关闭Cursor和Connection
cursor.close()
conn.close()&lt;/pre&gt;&lt;h3 id=&quot;toc-10&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3.2 使用预编译语句&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;预编译语句可以提高数据库操作的效率，并防止SQL注入攻击。&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;import&amp;nbsp;sqlite3

#&amp;nbsp;连接到SQLite数据库
conn&amp;nbsp;=&amp;nbsp;sqlite3.connect(&amp;#39;example.db&amp;#39;)
cursor&amp;nbsp;=&amp;nbsp;conn.cursor()

#&amp;nbsp;使用预编译语句
cursor.execute(&amp;quot;INSERT&amp;nbsp;INTO&amp;nbsp;users&amp;nbsp;(name,&amp;nbsp;age)&amp;nbsp;VALUES&amp;nbsp;(?,&amp;nbsp;?)&amp;quot;,&amp;nbsp;(&amp;#39;Dave&amp;#39;,&amp;nbsp;40))

#&amp;nbsp;提交事务
conn.commit()

#&amp;nbsp;关闭Cursor和Connection
cursor.close()
conn.close()&lt;/pre&gt;&lt;h3 id=&quot;toc-11&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3.3 使用连接池&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;连接池可以减少连接数据库的开销，提高应用程序的性能。&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;import&amp;nbsp;sqlite3

#&amp;nbsp;创建连接池
pool&amp;nbsp;=&amp;nbsp;sqlite3.connect(&amp;#39;example.db&amp;#39;,&amp;nbsp;check_same_thread=False)

#&amp;nbsp;从连接池中获取连接
conn&amp;nbsp;=&amp;nbsp;pool.connection()

#&amp;nbsp;使用连接执行SQL语句
cursor&amp;nbsp;=&amp;nbsp;conn.cursor()
cursor.execute(&amp;quot;SELECT&amp;nbsp;*&amp;nbsp;FROM&amp;nbsp;users&amp;quot;)

#&amp;nbsp;获取查询结果
results&amp;nbsp;=&amp;nbsp;cursor.fetchall()
for&amp;nbsp;row&amp;nbsp;in&amp;nbsp;results:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(row)

#&amp;nbsp;关闭Cursor和Connection
cursor.close()
conn.close()

#&amp;nbsp;关闭连接池
pool.close()&lt;/pre&gt;&lt;h2 id=&quot;toc-12&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite是一款功能强大的数据库，非常适合小型应用和嵌入式系统。通过本文的介绍，相信你已经对SQLite有了初步的了解。在实际应用中，你可以根据需要灵活运用SQLite的各种功能，提高应用程序的性能和稳定性。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:09:13 +0800</pubDate></item><item><title>轻松上手，Android SQLite数据库实战攻略揭秘</title><link>https://www.856syz.top/?id=73</link><description>&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Android 开发中，数据存储是不可或缺的一部分。SQLite 作为 Android 系统内置的轻量级数据库，因其简单易用、性能优越等特点，成为 Android 开发者的首选。本文将带你轻松上手 Android SQLite 数据库，并通过实战案例揭秘其应用技巧。&lt;/p&gt;&lt;h2 id=&quot;toc-1&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、SQLite 简介&lt;/h2&gt;&lt;center&gt;&lt;img src=&quot;/zb_users/upload/auto_pic/73.jpg&quot; alt=&quot;轻松上手，Android SQLite数据库实战攻略揭秘&quot;&gt;&lt;/center&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;SQLite 是一个轻量级的数据库引擎，支持标准的 SQL 语句，具有体积小、速度快、易于使用等特点。在 Android 开发中，SQLite 可以通过 JDBC 驱动程序与 Java 代码进行交互。&lt;/p&gt;&lt;h2 id=&quot;toc-2&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、Android 中使用 SQLite&lt;/h2&gt;&lt;h3 id=&quot;toc-3&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 创建数据库&lt;/h3&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在 Android 中，可以使用&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;SQLiteOpenHelper&lt;/code&gt;&amp;nbsp;类来创建和管理数据库。以下是一个创建数据库的示例代码：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;public&amp;nbsp;class&amp;nbsp;MyDatabaseHelper&amp;nbsp;extends&amp;nbsp;SQLiteOpenHelper&amp;nbsp;{

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;final&amp;nbsp;String&amp;nbsp;DATABASE_NAME&amp;nbsp;=&amp;nbsp;&amp;quot;mydatabase.db&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;static&amp;nbsp;final&amp;nbsp;int&amp;nbsp;DATABASE_VERSION&amp;nbsp;=&amp;nbsp;1;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;MyDatabaseHelper(Context&amp;nbsp;context)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;super(context,&amp;nbsp;DATABASE_NAME,&amp;nbsp;null,&amp;nbsp;DATABASE_VERSION);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;onCreate(SQLiteDatabase&amp;nbsp;db)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.execSQL(&amp;quot;CREATE&amp;nbsp;TABLE&amp;nbsp;IF&amp;nbsp;NOT&amp;nbsp;EXISTS&amp;nbsp;user&amp;nbsp;(&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&amp;quot;id&amp;nbsp;INTEGER&amp;nbsp;PRIMARY&amp;nbsp;KEY&amp;nbsp;AUTOINCREMENT,&amp;nbsp;&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&amp;quot;name&amp;nbsp;TEXT&amp;nbsp;NOT&amp;nbsp;NULL,&amp;nbsp;&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&amp;quot;age&amp;nbsp;INTEGER&amp;nbsp;NOT&amp;nbsp;NULL)&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;onUpgrade(SQLiteDatabase&amp;nbsp;db,&amp;nbsp;int&amp;nbsp;oldVersion,&amp;nbsp;int&amp;nbsp;newVersion)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;数据库升级逻辑
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;h3 id=&quot;toc-4&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 操作数据库&lt;/h3&gt;&lt;h4 id=&quot;toc-5&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;（1）插入数据&lt;/h4&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;insert&lt;/code&gt;&amp;nbsp;方法可以插入数据。以下是一个插入数据的示例代码：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;public&amp;nbsp;void&amp;nbsp;insertData(String&amp;nbsp;name,&amp;nbsp;int&amp;nbsp;age)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLiteDatabase&amp;nbsp;db&amp;nbsp;=&amp;nbsp;getWritableDatabase();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ContentValues&amp;nbsp;values&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ContentValues();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;values.put(&amp;quot;name&amp;quot;,&amp;nbsp;name);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;values.put(&amp;quot;age&amp;quot;,&amp;nbsp;age);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.insert(&amp;quot;user&amp;quot;,&amp;nbsp;null,&amp;nbsp;values);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.close();
}&lt;/pre&gt;&lt;h4 id=&quot;toc-6&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;（2）查询数据&lt;/h4&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;query&lt;/code&gt;&amp;nbsp;方法可以查询数据。以下是一个查询数据的示例代码：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;public&amp;nbsp;List&amp;lt;User&amp;gt;&amp;nbsp;queryData()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;User&amp;gt;&amp;nbsp;userList&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ArrayList&amp;lt;&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLiteDatabase&amp;nbsp;db&amp;nbsp;=&amp;nbsp;getReadableDatabase();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Cursor&amp;nbsp;cursor&amp;nbsp;=&amp;nbsp;db.query(&amp;quot;user&amp;quot;,&amp;nbsp;new&amp;nbsp;String[]{&amp;quot;id&amp;quot;,&amp;nbsp;&amp;quot;name&amp;quot;,&amp;nbsp;&amp;quot;age&amp;quot;},&amp;nbsp;null,&amp;nbsp;null,&amp;nbsp;null,&amp;nbsp;null,&amp;nbsp;null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while&amp;nbsp;(cursor.moveToNext())&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;id&amp;nbsp;=&amp;nbsp;cursor.getInt(0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;name&amp;nbsp;=&amp;nbsp;cursor.getString(1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age&amp;nbsp;=&amp;nbsp;cursor.getInt(2);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userList.add(new&amp;nbsp;User(id,&amp;nbsp;name,&amp;nbsp;age));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cursor.close();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.close();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userList;
}&lt;/pre&gt;&lt;h4 id=&quot;toc-7&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;（3）更新数据&lt;/h4&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;update&lt;/code&gt;&amp;nbsp;方法可以更新数据。以下是一个更新数据的示例代码：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;public&amp;nbsp;void&amp;nbsp;updateData(int&amp;nbsp;id,&amp;nbsp;String&amp;nbsp;name,&amp;nbsp;int&amp;nbsp;age)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLiteDatabase&amp;nbsp;db&amp;nbsp;=&amp;nbsp;getWritableDatabase();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ContentValues&amp;nbsp;values&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ContentValues();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;values.put(&amp;quot;name&amp;quot;,&amp;nbsp;name);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;values.put(&amp;quot;age&amp;quot;,&amp;nbsp;age);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.update(&amp;quot;user&amp;quot;,&amp;nbsp;values,&amp;nbsp;&amp;quot;id=?&amp;quot;,&amp;nbsp;new&amp;nbsp;String[]{String.valueOf(id)});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.close();
}&lt;/pre&gt;&lt;h4 id=&quot;toc-8&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;（4）删除数据&lt;/h4&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;delete&lt;/code&gt;&amp;nbsp;方法可以删除数据。以下是一个删除数据的示例代码：&lt;/p&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;public&amp;nbsp;void&amp;nbsp;deleteData(int&amp;nbsp;id)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLiteDatabase&amp;nbsp;db&amp;nbsp;=&amp;nbsp;getWritableDatabase();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.delete(&amp;quot;user&amp;quot;,&amp;nbsp;&amp;quot;id=?&amp;quot;,&amp;nbsp;new&amp;nbsp;String[]{String.valueOf(id)});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.close();
}&lt;/pre&gt;&lt;h2 id=&quot;toc-9&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、实战案例&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下是一个简单的 Android 应用，使用 SQLite 数据库存储用户信息。&lt;/p&gt;&lt;ol style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;创建一个名为&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;MainActivity&lt;/code&gt;&amp;nbsp;的 Activity，并在其布局文件&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;activity_main.xml&lt;/code&gt;&amp;nbsp;中添加一个按钮和一个文本视图。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;在&amp;nbsp;&lt;code style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; padding: 2px 4px; overflow-wrap: break-word; color: rgb(85, 85, 85); background: rgb(238, 238, 238); border-radius: 3px; font-size: 13px;&quot;&gt;MainActivity&lt;/code&gt;&amp;nbsp;中，编写以下代码：&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre style=&quot;font-family: consolas, Menlo, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, monospace; overflow: auto; margin-top: 20px; margin-bottom: 20px; padding: 10px; font-size: 13px; color: rgb(77, 77, 76); background-color: rgb(247, 247, 247); line-height: 1.6;&quot;&gt;public&amp;nbsp;class&amp;nbsp;MainActivity&amp;nbsp;extends&amp;nbsp;AppCompatActivity&amp;nbsp;{

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;SQLiteDatabase&amp;nbsp;db;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;protected&amp;nbsp;void&amp;nbsp;onCreate(Bundle&amp;nbsp;savedInstanceState)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;super.onCreate(savedInstanceState);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;setContentView(R.layout.activity_main);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyDatabaseHelper&amp;nbsp;dbHelper&amp;nbsp;=&amp;nbsp;new&amp;nbsp;MyDatabaseHelper(this);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db&amp;nbsp;=&amp;nbsp;dbHelper.getWritableDatabase();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Button&amp;nbsp;insertButton&amp;nbsp;=&amp;nbsp;findViewById(R.id.insert_button);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;insertButton.setOnClickListener(new&amp;nbsp;View.OnClickListener()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;onClick(View&amp;nbsp;v)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;insertData(&amp;quot;张三&amp;quot;,&amp;nbsp;20);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Toast.makeText(MainActivity.this,&amp;nbsp;&amp;quot;插入数据成功！&amp;quot;,&amp;nbsp;Toast.LENGTH_SHORT).show();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Button&amp;nbsp;queryButton&amp;nbsp;=&amp;nbsp;findViewById(R.id.query_button);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;queryButton.setOnClickListener(new&amp;nbsp;View.OnClickListener()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;onClick(View&amp;nbsp;v)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;User&amp;gt;&amp;nbsp;userList&amp;nbsp;=&amp;nbsp;queryData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StringBuilder&amp;nbsp;sb&amp;nbsp;=&amp;nbsp;new&amp;nbsp;StringBuilder();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(User&amp;nbsp;user&amp;nbsp;:&amp;nbsp;userList)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sb.append(&amp;quot;ID:&amp;nbsp;&amp;quot;).append(user.getId()).append(&amp;quot;,&amp;nbsp;&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.append(&amp;quot;姓名:&amp;nbsp;&amp;quot;).append(user.getName()).append(&amp;quot;,&amp;nbsp;&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.append(&amp;quot;年龄:&amp;nbsp;&amp;quot;).append(user.getAge()).append(&amp;quot;\n&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TextView&amp;nbsp;textView&amp;nbsp;=&amp;nbsp;findViewById(R.id.text_view);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;textView.setText(sb.toString());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;insertData(String&amp;nbsp;name,&amp;nbsp;int&amp;nbsp;age)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLiteDatabase&amp;nbsp;db&amp;nbsp;=&amp;nbsp;getWritableDatabase();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ContentValues&amp;nbsp;values&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ContentValues();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;values.put(&amp;quot;name&amp;quot;,&amp;nbsp;name);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;values.put(&amp;quot;age&amp;quot;,&amp;nbsp;age);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.insert(&amp;quot;user&amp;quot;,&amp;nbsp;null,&amp;nbsp;values);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.close();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;List&amp;lt;User&amp;gt;&amp;nbsp;queryData()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;User&amp;gt;&amp;nbsp;userList&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ArrayList&amp;lt;&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLiteDatabase&amp;nbsp;db&amp;nbsp;=&amp;nbsp;getReadableDatabase();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Cursor&amp;nbsp;cursor&amp;nbsp;=&amp;nbsp;db.query(&amp;quot;user&amp;quot;,&amp;nbsp;new&amp;nbsp;String[]{&amp;quot;id&amp;quot;,&amp;nbsp;&amp;quot;name&amp;quot;,&amp;nbsp;&amp;quot;age&amp;quot;},&amp;nbsp;null,&amp;nbsp;null,&amp;nbsp;null,&amp;nbsp;null,&amp;nbsp;null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while&amp;nbsp;(cursor.moveToNext())&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;id&amp;nbsp;=&amp;nbsp;cursor.getInt(0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String&amp;nbsp;name&amp;nbsp;=&amp;nbsp;cursor.getString(1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age&amp;nbsp;=&amp;nbsp;cursor.getInt(2);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;userList.add(new&amp;nbsp;User(id,&amp;nbsp;name,&amp;nbsp;age));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cursor.close();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db.close();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;userList;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;ol style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; padding-left: 30px; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;运行应用，点击按钮插入数据，再点击按钮查询数据，即可看到效果。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;toc-10&quot; style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;总结&lt;/h2&gt;&lt;p style=&quot;font-family: italic, Helvetica, Arial, &amp;quot;Heiti SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;; color: rgb(47, 51, 57); font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文介绍了 Android 中使用 SQLite 数据库的方法，并通过一个简单的实战案例展示了其应用。希望读者通过本文的学习，能够轻松上手 Android SQLite 数据库，并在实际项目中发挥其作用。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sun, 22 Mar 2026 15:07:31 +0800</pubDate></item></channel></rss>