Question

I have a synonym created for this table ParaPITD.dbo.BM_00_PolicyMaster that points to ParaPITDYYYYMM.dbo.BM_00_PolicyMaster

There is no table yet - so it acts as a place holder.

I have a stored procedure that creates a temp table #BM_00_PolicyMaster and now I want to insert or select into the place holder where the synonym points to and create the table in ParaPITDYYYYMM.dbo.BM_00_PolicyMaster

If I run this:

select * 
into ParaPITD.dbo.BM_00_PolicyMaster
from #BM_00_PolicyMaster

it creates the table in ParaPITD.dbo.BM_00_PolicyMaster and ignores the synonym

If I run this:

INSERT INTO ParaPITD.dbo.BM_00_PolicyMaster
   SELECT * 
   FROM #BM_00_PolicyMaster 

it gives me an invalid object error acting like the table must exist before it will insert.

Appreciate any help - thanks

Was it helpful?

Solution

From the doc (http://technet.microsoft.com/en-us/library/ms187552.aspx):

You cannot reference a synonym in a DDL statement

And any statement that creates a table, including SELECT INTO counts as a DDL statement. (See here: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1085a84c-faac-4d26-8f35-c64d8b901034/insert-into-is-sentence-dml-or-ddl)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top