是否可以在 python 界面的帮助下为正在 sql 中创建的 table 提供用户输入名称?

Is it possible to give user input name to a table that is being created in sql with the help of python interface?

我正在尝试做一个项目,该项目涉及使用用户输入的名称创建新的 table,但它不起作用。希望给的信息足够了。

这是我试过的:

import mysql.connector as myc

db=myc.connect(host='localhost',database='xyz',user='root',passwd='root')
mc=db.cursor()

name=input("name=")` 

x=("CREATE TABLE %s (S_NO VARCHAR(100),CONSULTATION_REASON VARCHAR(100),CONSULTED_DOCTOR VARCHAR(100),
FEES VARCHAR(100))")` 

mc.execute(x,name)
db.commit

它给出了这个错误:

error:::mysql.connector.errors.ProgrammingError: 1064 (42000): 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 '%s (S_NO VARCHAR(100), CONSULTATION_REASON VARCHAR(100), CONSULTED_DOCTOR VARCHAR(' at line 1:::

如有任何答复,我将不胜感激。

试试这个

import mysql.connector as myc
db=myc.connect(host='localhost',database='xyz',user='root',passwd='root')
mc=db.cursor()
name=input("name=")
x=("CREATE TABLE "+name+" (S_NO VARCHAR(100),CONSULTATION_REASON 
VARCHAR(100),CONSULTED_DOCTOR VARCHAR(100), FEES VARCHAR(100))")
mc.execute(x,name)
db.commit