sqlite3比较小众
本章主要通过Python Code表述如何增、查、改、删 sqlite3 DB

一.直接上代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-09-29 12:04:51
# @Author : call_me
# @Version : V1.0 import sqlite3
connect = sqlite3.connect('student.db')
cursor = connect.cursor()
try:
sql = '''create table student(
[id] integer PRIMARY KEY,
[name] varchar(50),
[sex] varchar(2),
[age] int
);
'''
cursor.execute(sql)
except Exception as e:
print("表已创建") # 插入数据
sql = '''insert into student (id,name,sex,age) VALUES (?,?,?,?)'''
data = (1,"张1","男","")
cursor.execute(sql,data)
data = (2,"张2","女","")
cursor.execute(sql,data)
data = (3,"张3","男","")
cursor.execute(sql,data)
data = (4,"张4","女","")
cursor.execute(sql,data) # 查数据
for select in cursor.execute("select * from student"):
print("名称:%s ,\t 年龄:%s " %(select[1],select[3])) # 删除数据
cursor.execute("delete from student") # 删除表
cursor.execute("drop table student") connect.commit()
connect.close()

Code

最新文章

  1. 原生JS编写的照片墙效果实例演示特效
  2. 【BZOJ-2879】美食节 最小费用最大流 + 动态建图
  3. pure css兼容IE
  4. python 装饰器(decorator)
  5. 利用AuthorizeAttribute属性简单避免 MVC 中的跨域攻击
  6. sql 将某一列的值拼接成字符串
  7. LeetCode解题报告:Binary Tree Postorder Traversal
  8. Performance of Transport Control Protocol over Dynamic Spectrum Access Links
  9. 2014百度之星第四题Labyrinth(DP)
  10. shell查找指定时间段内的文件
  11. tcp/ip 卷一 读书笔记(3)为什么既要有IP地址又要有MAC地址
  12. windows pe
  13. Exp2 后门原理与实践
  14. Java EE 导图
  15. xls文件导入数据库
  16. Linq 操作DataTable
  17. MyBatis-Configuration
  18. 微信获取地理位置转城市demo
  19. BZOJ3537 : [Usaco2014 Open]Code Breaking
  20. CentOS静默安装Oracle 11gR2(x64)

热门文章

  1. while循环小例
  2. 【[SCOI2015]小凸玩矩阵】
  3. eclipse 插件relo使用
  4. PEP8 常用规范
  5. scrollHeight, scrollTop, clientHeight
  6. cmd文件内容添加到文件内容命令
  7. ios中的三种弹框
  8. linux 设置自动关机和重启命令shutdown
  9. ORM初级实战简单的数据库交互
  10. Linux下 tar 命令详解