简体   繁体   English

SQL Server 中的现有表导致“数据库中已经存在名为‘***’的对象”错误

[英]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.

相关问题 使用 Python 将 Csv 文件写入 SQL Server 数据库中的现有表 - Writing Csv file to already existing table in SQL Server database using Python SQLAlchemy将表添加到现有数据库 - SQLAlchemy Add A Table To An Already Existing Database 我正在尝试将 alembic 与 fastapi 和 postgres sql 一起使用,但它给了我一个错误,即 No module named 'database but it exists in the project - I ma trying to use alembic with fastapi and postgres sql but it gives me error that No module named 'database but it existing in the project 如何将 Pandas 数据框插入到数据库中已经存在的表中? - How to insert a pandas dataframe to an already existing table in a database? 使用to_sql将数据附加到pandas中已存在的表中 - append the data to already existing table in pandas using to_sql 将数据帧上载到sql server中的现有表 - uploading dataframe to an existing table in sql server 使用Django访问SQL Server表中的现有数据 - Accessing Existing Data in a SQL Server Table with Django 将多个csv文件插入到现有的mysql表中时出错 - Error in insertion of multiple csv files into already existing mysql table Python SQL Server - 从现有表中的值创建表 - Python SQL Server - Create Table from Values from an existing Table 在 Python 中扩展一个已经存在的对象 - Extend an already existing object in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM