Issues with "There is already an object named 'xxx' in the database'

Posted by Hoser on Server Fault See other posts from Server Fault or by Hoser
Published on 2012-05-31T16:13:05Z Indexed on 2012/05/31 16:43 UTC
Read the original article Hit count: 184

Filed under:
|

I'm fairly new to SQL so this may be an easy mistake, but I haven't been able to find a solid solution anywhere else. Problem is whenever I try to use my temp table, it tells me it cannot be used because there is already an object with that name. I frequently try switching up the names, and sometimes it'll let me work with the table for a little while, but it never lasts for long. Am I dropping the table incorrectly? Also, I've had people suggest to just use a permanent table, but this database does not allow me to do that.

create table #RandomTableName(NameOfObject varchar(50), NameOfCounter varchar(50), SampledValue decimal)

select vPerformanceRule.ObjectName, vPerformanceRule.CounterName, Perf.vPerfRaw.SampleValue

into #RandomTableName

from vPerformanceRule, vPerformanceRuleInstance, Perf.vPerfRaw
where (ObjectName like 'Processor' AND CounterName like '% Processor Time')
OR(ObjectName like 'System' AND CounterName like 'Processor Queue Length')
OR(ObjectName like 'Memory' AND CounterName like 'Pages/Sec')
OR(ObjectName like 'Physical Disk' AND CounterName like 'Avg. Disk Queue Length')
OR(ObjectName like 'Physical Disk' AND CounterName like 'Avg. Disk sec/Read')
OR(ObjectName like 'Physical Disk' and CounterName like '% Disk Time')
OR(ObjectName like 'Logical Disk' and CounterName like '% Free Space' AND SampleValue > 70 AND SampleValue < 100)
order by ObjectName, SampleValue

drop table #RandomTableName

© Server Fault or respective owner

Related posts about sql

Related posts about temporary-tables