打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
sqlite3 数据库操作指令

导入数据库

import sqlit3

连接数据库

conn = sqlite3.connent("test.db")

创建游标

cursor = connn.cursor()

创建表

sql = "create table login(id varchar(20) primary key, name varchar(30), password varchar(30))"cursor.execute(sql)

常用增删改查

# 查看表结构cur.execute("PRAGMA table_info(jobs)")# 表中增加字段cur.execute("alter table WeakManager add release_time text")# 重命名表alter table tema rename to team2;# 删除表中字段password(不支持删除列)alter table wx_userInfo drop column password;# 删除表cur.execute("drop table WeakManager")# 删除数据delete from wx_userInfo where id=3;# 添加数据insert into table_name(v1, v2) values (v1, v2);cur.execute("insert into people values (?, ?)", (who, age))cur.execute("select * from people where name=:who and age=:age",{"who": who, "age": age})-- 修改数据update wx_userInfo set name='bbb',nickName='bbb' where openID='xxxxxx';-- 在原有数据上增加数据update wx_userInfo set control_order=control_order||'on_off=0' where _id=40;-- 查询所以数据select * from wx_userInfo;-- 查询指定数量条数select * from wx_userInfo limit 3;-- 查询升序输出记录select * from wx_userInfo order by id asc;-- 查询降序输出记录select * from wx_userInfo order by id desc;-- 条件查询select * from wx_userInfo where id in('3');select * from wx_userInfo where id between 0 and 2;-- 查询指定字段记录数量统计select count(nickName) from wx_userInfo;select count(unionID) from wx_userInfo;-- 查询指定字段的数据(将指定字段可能重复的数据去掉,列出所有不同的数据)select distinct unionID from wx_userInfo;select distinct id from wx_userInfo;-- 查询最后一条数据,order by id desc 倒序,然后查找最后一条 limit 0,1select id, room_id,control_order,date_time from control_table order by id desc limit 0,1;

结束操作

# 1.提交事务conn.commit()# 2.关闭游标cursor.close()# 3.关闭连接conn.close()
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
sqlite数据库中正确的创建一个表格的方法
使用Python构建SQLite轻量级数据库
lua简单操作sqlite3
python 的sqlite3连接模块用法
android?sqlite?编程
【Android基础篇】SQLite数据库的增删改查基本操作
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服