python操作sqlite数据库_Python 操作SQLite数据库的示例

SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中。在很多嵌入式产品中使用了它,它占用资源非常的低,python 中默认继承了操作此款数据库的引擎 sqlite3 说是引擎不如说就是数据库的封装版,开发自用小程序的使用使用它真的大赞

简单操作SQLite数据库:创建 sqlite数据库是一个轻量级的数据库服务器,该模块默认集成在python中,开发小应用很不错.

import sqlite3

# 数据表的创建

conn = sqlite3.connect("data.db")

cursor = conn.cursor()

create = "create table persion(" \

"id int auto_increment primary key," \

"name char(20) not null," \

"age int not null," \

"msg text default null" \

")"

cursor.execute(create) # 执行创建表操作

简单操作SQLite数据库:简单的插入语句的使用

insert = "insert into persion(id,name,age,msg) values(1,'lyshark',1,'hello lyshark');"

cursor.execute(insert)

insert = "insert into persion(id,name,age,msg) values(2,'guest',2,'hello guest');"

cursor.execute(insert)

insert = "insert into persion(id,name,age,msg) values(3,'admin',3,'hello admin');"

cursor.execute(insert)

insert = "insert into persion(id,name,age,msg) values(4,'wang',4,'hello wang');"

cursor.execute(insert)

insert = "insert into persion(id,name,age,msg) values(5,'sqlite',5,'hello sql');"

cursor.execute(insert)

data = [(6, '王舞',

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值