如下:myDB=sqlite3.connect("E:\\myDB.db")#连接数据库,若无则创建cur=myDB.cursor()#建表,若有则跳过try:cur.e...
如下:
myDB = sqlite3.connect("E:\\myDB.db") #连接数据库,若无则创建
cur = myDB.cursor()
#建表,若有则跳过
try:
cur.execute('''
create table MyTable(
Project_number text,
Year int,
ID text,
Abstract text,
Cost_money int,
Course_number text, #怎么将它的默认值设置为Null
Course_content text,
Pic_name text
)
''')
print("Create Success!")
except:
print('The table Financial exists!')
pass
sql = "insert into MyTable values(?,?,?,?,?,?,?,?)"
project_number = ‘C12345’
year = 2015
id = '04_25_AC1562'
abstract = u'出差费'
cost_money = 3000
cur.execute(sql,[project_number,year,id,abstract,money_cost,None,None,None])
因为我现在不确定后面的三项内容,所以想首先输入前5个,让没有输入的内容默认为空值,虽然用上面做法也可以,但是感觉有点麻烦,我想改成的样式为:
sql = "insert into MyTable values(?,?,?,?,?)"
...
cur.execute(sql,[project_number,year,id,abstract,money_cost])
也就是在创建表的时候希望后面的三项内容,即:
Course_number text, #怎么将它的默认值设置为Null
Course_content text,
Pic_name text
如果没有输入的话,则默认值为空。
这样做是否可行,如果行的话怎么改程序,求大神指点!