mysql创建数据表时如何判断是否已经存在?

时间:2022-04-23
本文章向大家介绍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)")