【数据库】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
相关推荐
余衫马44 分钟前
CentOS7 离线安装 Postgresql 指南
数据库·postgresql
E___V___E1 小时前
MySQL数据库入门到大蛇尚硅谷宋红康老师笔记 高级篇 part 2
数据库·笔记·mysql
m0_748254882 小时前
mysql之如何获知版本
数据库·mysql
mikey棒棒棒2 小时前
Redis——优惠券秒杀问题(分布式id、一人多单超卖、乐悲锁、CAS、分布式锁、Redisson)
数据库·redis·lua·redisson·watchdog·cas·并发锁
水手胡巴3 小时前
oracle apex post接口
数据库·oracle
爱学习的小王!5 小时前
nvm安装、管理node多版本以及配置环境变量【保姆级教程】
经验分享·笔记·node.js·vue
陈志化5 小时前
JMeter----笔记
笔记·jmeter
HollowKnightZ5 小时前
论文阅读笔记:Gated CRF Loss for Weakly Supervised Semantic Image Segmentation
论文阅读·笔记
史迪仔01126 小时前
【SQL】SQL多表查询
数据库·sql
xzal126 小时前
青少年编程都有哪些比赛可以参加
笔记·青少年编程