Missing Object Error from Profiler to Insert Newly Create Table


When you insert rows immediately after the table creation, you may find there is an exception report for missing object if you dig into Profiler to view it. It is working fine from front end but you still see this error report. This behavior is caused by “deferred name resolution” and you will see this behavior with stored procedure as well.

Here is the code that generates this exception:

  

create table #temp (id int) 
insert into #temp (id) values (1)
 

 

You can avoid this error report by using different batch for your creation and insert.

  

create table #temp (id int) 

Go

insert into #temp (id) values (1)

Go

 

 

Or use global temp table

 

  

 

create table ##temp (id int)

insert into ##temp (id) values (1)

 

 

Or do nothing and keep coding.

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/773b0265-1547-4d8a-9e43-b6a5ab8f33bd/getting-invalid-object-name-by-creating-a-temp-table-and-inserting-rows-right-away?forum=transactsql
 

 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s