[英]Existing table in SQL Server causing 'There is already an object named '***' in the database' error
I'm trying to create a table in python using azure sql server, when i run this line of code below i get the following error:我正在尝试使用 azure sql server 在 python 中创建一个表,当我运行下面的这行代码时,出现以下错误:
'There is already an object named '***' in the database'.
'数据库中已经有一个名为'***'的对象'。
def del_final_trades(new_table_name, cl_table_name, cp_table_name):
cursor.execute('''SELECT * INTO {newt} FROM {cl_t} INNER JOIN {cp_t} ON
{cl_t}.[CL_Trade ID] = {cp_t}.[CP_Trade ID]'''.format(newt=new_table_name, cl_t=cl_table_name,
cp_t=cp_table_name))
The error is correct, the table does exist but how do I drop the table if its NOT NULL
and create a new one?错误是正确的,该表确实存在,但是如果它
NOT NULL
,我该如何删除该表并创建一个新表?
I understand the logic, I'm just struggling to put it into a working code, any help is appreciated!我理解逻辑,我只是在努力将其放入工作代码中,任何帮助表示赞赏!
您需要测试该表是否存在于 drop 命令中:
DROP TABLE IF EXISTS [Table name]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.