数据库常用语句
注意事项:
批量插入数据时,原子操作,如果一个数据的key 重复了,会导致所有数据插入失败,
https://blog.csdn.net/weixin_55972781/article/details/118399532
https://juejin.cn/post/7043299133360177189
创建表
CREATE TABLE table1 ( materialId TEXT, resourceType TEXT, localPath TEXT, remoteUrl TEXT, status INTEGER, fileHash TEXT, fileVersion Integer, fileSize Integer, PRIMARY KEY(materialId, resourceType), constraint foreign_key foreign key(materialId) references material_basic(materialInfoId) );
插入数据:
INSERT INTO table1(materialId,resourceType,localPath,remoteUrl,status,fileHash,fileVersion,fileSize) VALUES('0x10001','source1','','',2,'',1,0)
INSERT INTO table1(materialId,resourceType,localPath,remoteUrl,status,fileHash,fileVersion,fileSize) VALUES ('0x10001','source2','','',2,'',1,0), ('0x10001','source3','','',2,'',1,0), ('0x10002','source1','','',2,'',1,0), ('0x10002','source2','','',2,'',1,0), ('0x10002','source3','','',2,'',1,0)
第二次如果带着第一次的数据在一起插入,会全部插入失败