cursor.execute('SQL commands')//创建表
cursor.execute('CREATE TABLE tablename')\
cursor.execute('CREATE TABLE tablename(attributes type)')//插入数据
cursor.execute('INSERT INTO tablename values(attribute`s value)')//更新表
cursor.execute('UPDATE tablename SET attribute = value')//select语句配合fetchall()方法获取数据
cursor.execute('SELECT * from tablename')//*指全部,可换成attribute,获得其对应的值
data = cursor.fetchall()//也可用where语句进行筛选
cursor.execute('SELECT name from tablename WHERE age > 20')
data = cursor.fetchall()//这里获得的就是数据库中table表中年龄大于20的所有人名//计算行数
cursor.execute('SELECT * from tablename').rowcount
data = cursor.fetchall()print(len(data))//即打印出全部数据的行数//同时可以计算删除多少行
cursor.execute('DELIETE from tablename').rowcount
//列出表名
cursor.execute('SELECT name from sqlite_master where type = "table"')print(cursor.fetchall)//删除表
cursor.execute('DROP table tablename')//建立和删除表时,应判断其是否存在
cursor.execute('CREATE table if not exists tablename')
cursor.execute('DROP table if exists tablename')//插入多行
cursor.execute('CREATE table if not exists projects(id integer, name text)')
data =[(1,"Ridesharing"),(2,"Water Purifying"),(3,"Forensics"),(4,"Botany")]
cursor.executemany("INSERT INTO projects VALUES(?, ?)", data)//以'?'做占位符