SQL 数据库中已经有一个名为“tbltable1”的对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1152811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:53:49  来源:igfitidea点击:

There is already an object named 'tbltable1' in the database

sqlsql-serversql-server-2005select-into

提问by Cerebrus

I am trying to insert data from one table to another with same structure,

我正在尝试将数据从一个表插入到另一个具有相同结构的表中,

select * into tbltable1 from tbltable1_Link

I am getting the following error message:

我收到以下错误消息:

There is already an object named 'tbltable1' in the database.

回答by Cerebrus

The SELECT INTOstatement creates a new table of the name you provide and populates it with the results of the SELECT statement.

SELECT INTO语句使用您提供的名称创建一个新表,并用 SELECT 语句的结果填充它。

I think you should be using INSERT INTOsince the table already exists. If your purpose is in fact to populate a temporary table, then you should provide a table name that does not already exist in the database.

我认为您应该使用,INSERT INTO因为该表已经存在。如果您的目的实际上是填充临时表,那么您应该提供数据库中尚不存在的表名。

See MSDNfor more information on this.

有关这方面的更多信息,请参阅MSDN

回答by Hooloovoo

If you are confident that tbltable1is not required, you can drop the table first.

如果您确信这tbltable1不是必需的,则可以先删除该表。

You may also want to consider using temporary tables...

您可能还需要考虑使用临时表...

Select * into ##MyTemporaryTable FROM tblTable1_Link 

You can then use the temporary table in this session. (Ending the session should drop the temporary table automatically, if I remember correctly. It's been a while since I've worked with SQL Server).

然后您可以在此会话中使用临时表。(如果我没记错的话,结束会话应该会自动删除临时表。自从我使用 SQL Server 以来已经有一段时间了)。