mysql創建數據表時如何判斷是否已經存在?


>>> create table if not exists people(name text,age int(2),gender char(1));

如上代碼表示創建一個名為people的數據表。有時在程序中,如果people這個表已經存在,如果執行下面的語句就會報錯

>>> create table people(name text,age int(2),gender char(1));

if not exists 的作用就是判斷要創建的數據表是否已經存在,若不存在則創建,否則跳過該語句。


pymysql語法幾乎一毛一樣:

cursor.execute("create table if not exists movie(name text, star text, quote text, info text)")



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM