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)")


原文地址:https://www.cnblogs.com/marsggbo/p/6622918.html