SQlite3基本用法,使用sublime编辑器
来源:互联网 发布:软件运营部门 编辑:程序博客网 时间:2024/06/03 13:53
# coding:utf-8
import sqlite3
# 1.连接数据库,文件不存在自动创建新的数据库文件
connect=sqlite3.connect('database.db')
# 2.连接游标
cursor=connect.cursor()
# 3.向数据库database.db添加一张表,以及四个字段id,name,age,score
# create_student_table="CREATE TABLE Student(id INTEGER PRIMARY KEY,name TEXT,age INTEGER,score FLOAT)"
# cursor.execute(create_student_table)
# 4.往表中插入数据
# insert_sql="INSERT INTO Student(name,age,score)VALUES('李四','30',50)"
# cursor.execute(insert_sql)
# 5.更改表中的数据
update_sql="UPDATE Student SET name='%s',age='%d' WHERE id=1 "%('王五',100)
cursor.execute(update_sql)
# 6.查询表中所有的数据
select_sql="SELECT*FROM Student"
res=cursor.execute(select_sql)
for x in res:
print x
# 7.删除表中的数据
delete_sql="DELETE FROM Student WHERE id=2"
cursor.execute(delete_sql)
# 执行提交操作
connect.commit()
cursor.close()
connect.close()
import sqlite3
# 1.连接数据库,文件不存在自动创建新的数据库文件
connect=sqlite3.connect('database.db')
# 2.连接游标
cursor=connect.cursor()
# 3.向数据库database.db添加一张表,以及四个字段id,name,age,score
# create_student_table="CREATE TABLE Student(id INTEGER PRIMARY KEY,name TEXT,age INTEGER,score FLOAT)"
# cursor.execute(create_student_table)
# 4.往表中插入数据
# insert_sql="INSERT INTO Student(name,age,score)VALUES('李四','30',50)"
# cursor.execute(insert_sql)
# 5.更改表中的数据
update_sql="UPDATE Student SET name='%s',age='%d' WHERE id=1 "%('王五',100)
cursor.execute(update_sql)
# 6.查询表中所有的数据
select_sql="SELECT*FROM Student"
res=cursor.execute(select_sql)
for x in res:
print x
# 7.删除表中的数据
delete_sql="DELETE FROM Student WHERE id=2"
cursor.execute(delete_sql)
# 执行提交操作
connect.commit()
cursor.close()
connect.close()
阅读全文
0 0
- SQlite3基本用法,使用sublime编辑器
- sublime编辑器【快捷键】基本用法,sublime小技巧
- sqlite3的基本用法
- sqlite3基本用法
- sqlite3的基本用法
- 【Sublime编辑器】基本操作
- sqlite3的基本使用
- SQLite3的基本使用
- sqlite3数据库基本使用
- Linux SQLite3基本使用
- SQLite3的基本使用
- Sublime编辑器 使用笔记
- Sublime编辑器的使用
- sublime基本使用
- vim 编辑器基本用法
- MarkDown编辑器基本用法
- vim 编辑器基本用法
- markdown编辑器基本用法
- redis
- 相关系数评价标准的相关知识
- JAVA单链表反转
- this关键字的理解
- java的集合中的Set以及set的实现类HashSet和TreeSet
- SQlite3基本用法,使用sublime编辑器
- 咒语
- 4-1·NTP服务器配置搭建
- 2746:约瑟夫问题
- 设计思想学习—装饰者模式
- js关于setTimeout实现延时执行函数并进行传参
- 到底什么是集群&分布式
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists解决办法
- 2017-12-20php学习基础巩固第二天