Tom*_*Tom 4 python mysql-python
我创建了一个表“ table2”,并在运行代码时收到警告(表已存在)。我只想创建不存在的表。一些研究MySQL语法的网站在MySQL中提供了以下内容:如果不存在则创建表
我的代码:
cursor.execute('CREATE TABLE IF NOT EXISTS (2 INT)`table2`')
Run Code Online (Sandbox Code Playgroud)
提供以下警告:
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(2 INT)`table2`' at line 1")
Run Code Online (Sandbox Code Playgroud)
我有数据库版本数据库版本:5.1.54-1ubuntu4汤姆
mysql语法是
CREATE TABLE [IF NOT EXISTS] tbl_name
(create_definition,...)
[table_options]
[partition_options]
Run Code Online (Sandbox Code Playgroud)
使用以下...
cursor.execute('CREATE TABLE IF NOT EXISTS `table2` (`something` int(2))')
Run Code Online (Sandbox Code Playgroud)
结果:
__main__:1: Warning: Table 'table2' already exists
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13951 次 |
| 最近记录: |