2020年8月30日 星期日

資料庫 連結 關閉 建立 新增 移除

 1.連結 關閉

import sqlite3
test=sqlite3.connect("mydb.db")
print("link database")
test.close()
print("database close")


2.建立資料表
import sqlite3
test=sqlite3.connect("mydb.db")
try:
    creTabList="CREATE TABLE 產品(編號 text,品名 text,單價 int)"             #要輸入mydb.db 的欄位
    test.execute(creTabList)  #執行
    test.commit()             #更新資料庫
    print("database table create ")
except Exception:
    print("it don's work")
test.close()

沒有留言:

張貼留言

二維陣列(2d array) matrix

import numpy as np fru_items=[["apple","banana","cherry","durian","eggplant","fig...