When I design a temporary table as follows, the manager growls at the name #Temp and marks it with red highlight.
当我按如下方式设计一个临时表时,管理器以#Temp的名称咆哮并用红色突出显示它。
drop table #Temp
select * into #Temp
from Donkeys
When I hover over the highlight, the reason is - as expected - that the name isn't recognized.
当我将鼠标悬停在突出显示上时,原因是 - 正如预期的那样 - 无法识别该名称。
Cannot drop the table '#Temp', because it does not exist or you do not have permissions.
无法删除表'#Temp',因为它不存在或您没有权限。
Now, I'm not a SQL developer - I come from C# and I'm spoiled by intellisense, Resharper and what not, so I dislike when something is highlighted (even although it works). I installed Management Studio 11.x just to get the intellisense working and I want to get my money worth, if possible.
现在,我不是一个SQL开发人员 - 我来自C#而且我被intellisense,Resharper和什么不被宠坏了,所以我不喜欢什么时候突出显示(尽管它有效)。我安装了Management Studio 11.x只是为了让intellisense正常工作,如果可能的话,我希望得到我的钱。
The question is - can I do something about the highlight (purely visually, because the functionality is - as pointed out earlier - as it's supposed to)?
问题是 - 我可以对突出显示做些什么(纯粹在视觉上,因为功能是 - 如前所述 - 正如它应该的那样)?
Please note that the question is not about why it happens or if it's a problem. I do understand perfectly well why and I'm declaring it to be a problem (yeah, I admit it's not the biggest issue but it's big enough for me to actually invest time asking). Also, I'm human (i.e. lazy-ish) so a simple solution will do. :)
请注意,问题不在于它为何会发生或者是否有问题。我完全理解为什么和我宣布它是一个问题(是的,我承认这不是最大的问题,但它足以让我真正投入时间来询问)。而且,我是人(即懒惰),所以一个简单的解决方案就可以了。 :)
3 个解决方案
#1
1
It can be achieved by the combination ctrlshiftR.
它可以通过组合ctrlshiftR来实现。
You are receiving this issue because #temp does not exist yet. You either need to check for it's existence like so:
您收到此问题是因为#temp尚不存在。您需要检查它的存在,如下所示:
if OBJECT_ID('tempdb..#temp') is not null
begin
drop table #temp
end
select * into #Temp
from Donkeys
or you can just drop the table after you've used it:
或者你可以在使用它之后放下桌子:
select * into #Temp
from Donkeys
Drop table #Temp
#2
2
use like this way :-
像这样使用: -
If Object_Id('tempdb.dbo.#Temp') Is Not Null Drop Table #Temp;
select * into #Temp
from Donkeys
#3
1
You need to check if the table exists before trying to drop it of course. Otherwise the IDE will keep on giving you red lines.
在尝试删除表之前,您需要检查表是否存在。否则IDE将继续为您提供红线。
if exists(select 1 from tempdb.sys.tables where object_id = object_id('tempdb..#Temp'))
drop table #Temp
select * into #Temp
from Donkeys
It will also be better to rerun your script without having to select individual steps.
最好在不必选择单个步骤的情况下重新运行脚本。
#1
1
It can be achieved by the combination ctrlshiftR.
它可以通过组合ctrlshiftR来实现。
You are receiving this issue because #temp does not exist yet. You either need to check for it's existence like so:
您收到此问题是因为#temp尚不存在。您需要检查它的存在,如下所示:
if OBJECT_ID('tempdb..#temp') is not null
begin
drop table #temp
end
select * into #Temp
from Donkeys
or you can just drop the table after you've used it:
或者你可以在使用它之后放下桌子:
select * into #Temp
from Donkeys
Drop table #Temp
#2
2
use like this way :-
像这样使用: -
If Object_Id('tempdb.dbo.#Temp') Is Not Null Drop Table #Temp;
select * into #Temp
from Donkeys
#3
1
You need to check if the table exists before trying to drop it of course. Otherwise the IDE will keep on giving you red lines.
在尝试删除表之前,您需要检查表是否存在。否则IDE将继续为您提供红线。
if exists(select 1 from tempdb.sys.tables where object_id = object_id('tempdb..#Temp'))
drop table #Temp
select * into #Temp
from Donkeys
It will also be better to rerun your script without having to select individual steps.
最好在不必选择单个步骤的情况下重新运行脚本。