简体   繁体   中英

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:

'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?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM