-->

How to deal with temp tables when compiling databa

2019-05-22 15:57发布

问题:

We just created a solution with multiple data projects. We inherited the system and want to do a database cleanup but when we compile some of the databases we get the error that table, id etc does not exist and it occures where temp tables are created in stored procedures.

Let's say a stored proc creates a temp table and at the end drops it the compiler complains and says that the table does not exist (in the database schema). How can we work around this? Any settings I can't find?

Thanks in advance.

回答1:

There is a bug filed in Microsoft Connect on this issue, and there is a workaround suggested: use table variables instead of temporary tables. So, use

declare @t table (ID int, Name nvarchar(100) )
insert into @t ...

instead of

create table #t (ID int, Name nvarchar(100) )
insert into #t ...
drop table #t