【数据库】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
相关推荐
周杰伦_Jay14 分钟前
【终端使用MySQL】MySQL 数据库核心操作全解析:从入门到性能优化
数据库·mysql·性能优化
刘一哥GIS17 分钟前
Windows环境搭建:PostGreSQL+PostGIS安装教程
数据库·python·arcgis·postgresql·postgis
云和数据.ChenGuang36 分钟前
uri: mongodb://jack:123456@localhost://27017 数据库访问其他的写法
数据库·mongodb·oracle
ManageEngineITSM1 小时前
IT 服务自动化的时代:让效率与体验共进
运维·数据库·人工智能·自动化·itsm·工单系统
SelectDB1 小时前
Apache Doris 内部数据裁剪与过滤机制的实现原理
数据库·数据分析·github
Derrick__11 小时前
Python访问数据库——使用SQLite
数据库·python·sqlite
Databend1 小时前
Databend 九月月报:自增列 AUTOINCREMENT 与行级安全
数据库
Cathy Bryant2 小时前
球极平面投影
经验分享·笔记·数学建模
-雷阵雨-2 小时前
MySQL——数据库入门指南
数据库·mysql
Larry_Yanan2 小时前
QML学习笔记(三十一)QML的Flow定位器
java·前端·javascript·笔记·qt·学习·ui