建立資料庫表

2021-09-29 08:56:05 字數 577 閱讀 3501

#!/usr/bin/python3

import pymysql

# 開啟資料庫連線

db = pymysql.connect(

"localhost"

,"root"

,"123456"

,"test"

)# 使用 cursor() 方法建立乙個游標物件 cursor

cursor = db.cursor(

)# 使用 execute() 方法執行 sql,如果表存在則刪除

cursor.execute(

"drop table if exists employee"

)# 使用預處理語句建立表

sql =

"create table employee ( first_name char(20) not null,last_name char(20),age int, *** char(1),income float )"

cursor.execute(sql)

# 關閉資料庫連線

db.close(

)

資料庫建立表

use jy go1 建立reader讀者表create table reader reader id varchar 8 not null primary key,第一種主鍵約束方式 reader name nvarchar 50 not null,姓名 reader char 2 not nul...

資料庫表建立

慣例 我是溫浩然 建立資料庫表的時候,要充分考慮表與表之間的關係,否則,會一直改。最近在做乙個網路論壇的專案,最開始的時候,沒有充分考慮論壇版塊,與版主之間的關係,所以,在版塊表中,加入乙個版主id的字段,在使用者表中,角色字段,設定了乙個版主。但是後來考慮,版主,是一種許可權,而不是乙個角色。角色...

建立資料庫表

建表語法格式 create table if notexists 表名 欄位名 列型別 屬性 索引 注釋 欄位名 列型別 屬性 索引 注釋 欄位名 列型別 屬性 索引 注釋 表型別 字符集設定 注釋 例項 目標 建立乙個school資料庫 建立學生表 列,字段 使用sql建立 學號int,登陸密碼v...