【数据库】SQLite DB Browser有关图书商城的增删改查语句笔记

如下是为我数据库对应的表格

此次针对books单独修改

如下为我SQLite数据库中对应的前端视图和表格 很多都是重复的 这里我要使用SQLite语句逐个修改成不一样的图片 id 介绍等等信息


csharp 复制代码
```csharp
INSERT INTO "main"."books" ("id", "title", "description", "publisher", "author", "image", "price") VALUES (1, 'Science fiction', 'This is Science Friction type', 'aasdf', 'ASh', 'StarWar6.png', 23);
```这里举个例子比如第一行的insert sql语句就是这个 也可以用下边这个语句插入 
INSERT INTO books (id, title, description, publisher, author, image, price)  
    VALUES (?, ?, ?, ?, ?, ?, ?)  

然后举个例子比如现在我的前端视图为9个画像 我现在从后台的SQLlite中增加一个到第十个的语句

INSERT INTO books (id, title, description, publisher, author, image, price)

VALUES (10, 'Science fiction', 'This is Science Friction type', 'Starwar', 'star', 'StarWar2.png', 88);

可以看到我九个视图 那么id就是9 所以我这里的插入语句id 为10至于 description publisher author image price这些就是无所谓的 图片我换了一个好区分 试一下

csharp 复制代码
INSERT INTO books (id, title, description, publisher, author, image, price)  
VALUES (10, 'StarWar2', 'This is a science fiction book.', 'Star publisher', 'Star Author', 'StarWar2.png', 23.99);


这里一定要记得写入更改 不然首页视图不生效 可以看到新加入的

接下来我要逐一更改让他们变得不一样

csharp 复制代码
UPDATE books  
SET 
title = ' StarWar6 ',  
publisher = 'StarPublisher',
Author = 'StarPublisher',
image = 'StarWar6.png',
 price = 77.99  
WHERE id = 1;

UPDATE books

SET

title = ' Harry Potter and the Chamber of Secrets ',

description='This is Story Novel',

publisher = 'StarPublisher',

Author = 'StarPublisher',

image = 'Harry Potter and the Chamber of Secrets.png',

price = 33.99

WHERE id = 6;

这里我先修改第一个的

有关book和categories的id

这里我接下来要看关联的

如果您想要在book_categories表中增加一个新的行(也就是增加一个新的id),您需要使用INSERT语句,而不是UPDATE语句。UPDATE语句是用来修改已经存在的行的数据的。

如果您想要插入一个新的book_id和对应的category_id到book_categories表中,您可以使用类似下面的INSERT语句:

sql

增加category

csharp 复制代码
![INSERT INTO book_categories (book_id, category_id)  
VALUES (5, 3);](https://i-blog.csdnimg.cn/direct/1af946a0df9543bea9a9c630c7090246.png)

book_id = 5 然后categories类型是3

删除category

如果您只是想要删除某个特定书籍与特定类别的关系,而不是删除整个类别,您应该使用包含book_id和category_id的DELETE语句,如下所示:

sql

csharp 复制代码
DELETE FROM book_categories  
WHERE book_id = 5 AND category_id = 3;

把book_id=5的 category为3的删除

更改Category

更改对应小卡片下的category_id 这里我原来的是category3 我想改成category 1的 book_id是4

csharp 复制代码
UPDATE book_categories  
SET category_id = 1  
WHERE book_id = 4 AND category_id = 3;
复制代码
删除语句![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/f42dce70ebb5490fb62016c021a1b659.png)
-- 首先删除引用行  
DELETE FROM order_items  
WHERE order_id = 2;  
  
-- 然后删除主表中的行  
DELETE FROM orders  
WHERE id = 2;  
  
COMMIT;
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/be4658957d024fe3ac61a8e64a2f8162.png)
可以看到所有order _id 为2 的单子都没了
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/65e8cc7daf944daa8b2c40c0f336007c.png)
删除成功 有外键约束 要先把约束的外键的用sql语句删除 然后再删除orders
相关推荐
FungLeo3 小时前
成为全栈·基础补充·数据库迁移与事务:数据结构怎样安全演进
mysql·postgresql·sqlite·数据一致性·数据库事务·数据库迁移·成为全栈
Zan8 小时前
SQLite + SQLx 实战:为什么已经发布的数据库迁移文件,绝对不能再修改?
数据库·后端·面试
这个DBA有点耶9 小时前
数据同步的三个工程底线:DDL同步、断点续传、一致性校验——开源CDC的边界与KFS的路径
数据库·dba·代码规范
SelectDB10 小时前
列式存储为什么适合分析类负载?原理、限制与日志场景应用
数据库
数据库小学妹11 小时前
MySQL大字段治理:行溢出机制、覆盖索引与拆表
数据库·mysql·性能优化
一壶浊酒伴余生11 小时前
新概念英语第一册 · 句法笔记
笔记·英语学习·英语语法·新概念英语
爱吃奥利奥_wen11 小时前
SQL Server 基础语法详解:从建库建表到约束与增删改查
服务器·数据库·oracle
这个DBA有点耶12 小时前
MySQL 8.0不可见索引:删索引怕出事,不删又拖慢写入——中间态怎么用?
数据库·mysql·代码规范
测试界的小码农14 小时前
【图数据库实战进阶(01):从零认识 Neo4j,搭建第一个图数据库项目】
数据库·neo4j