如上代碼表示創建一個名為people的數據表。有時在程序中,如果people這個表已經存在,如果執行下面的語句就會報錯>>> create table if not exists people(name text,age int(2),gender char(1));
if not exists 的作用就是判斷要創建的數據表是否已經存在,若不存在則創建,否則跳過該語句。>>> create table people(name text,age int(2),gender char(1));
pymysql語法幾乎一毛一樣:
cursor.execute("create table if not exists movie(name text, star text, quote text, info text)")