Mysql Bit字段类型用来存储二进制的位值,Bit(M)代表可存储M位的二进制数据,M取值为区间为1-64。数据库Bit类型常用来存储Boolean类型的状态,也就是可以使用一个字段来存最多64个状态,如果你的系统状态够多或者将来可能会有扩展状态,那推荐使用这个类型进行处理,查询或更新某个状态时按位操作即可。
在本项目中,有一张亲友表,其中删除作为了一种bit类型,
insert语句为:
INSERT INTO `lanxi_core`.`relatives_relationship` (`customer_id`, `rel_customer_id`, `f_id`, `status`, `deleted`, `tenant_id`, `create_time`, `update_time`) VALUES ('1473108150702313472', '1560446207776071680', 3, 1, b'1', 2, '2022-11-08 15:32:00', '2022-12-05 09:41:09');
update语句
UPDATE `lanxi_core`.`relatives_relationship` SET `f_id` = 3, `status` = 1, `tenant_id` = 2, `create_time` = '2022-11-08 15:32:00', `update_time` = '2022-12-05 09:41:09' WHERE `customer_id` = '1473108150702313472' AND `rel_customer_id` = '1560446207776071680' AND `deleted` = b'1';
查询语句
SELECT * FROM `lanxi_core`.`relatives_relationship` WHERE `deleted` IN (b'1') LIMIT 0,1000;
删除语句
DELETE FROM `lanxi_core`.`relatives_relationship` WHERE `customer_id` = '1561887684033216512' AND `rel_customer_id` = '1559017565590265856' AND `f_id` IS NULL AND `status` = 1 AND `deleted` = b'0' AND `tenant_id` = 1 AND `create_time` = Cast('2022-12-05 14:13:07' AS Binary(19)) AND `update_time` = Cast('2022-12-05 14:13:07' AS Binary(19)) LIMIT 1