Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User defined TYPE across databases

I have a database that holds common functions that I use across multiple databases. One of these functions takes in a table as a parameter which is a user defined TYPE. I would like to know if there is a way to call this function from another database.

I tried to define the type in the other database like so:

DECLARE @bits as Common.dbo.Bits

However I received an error too many prefixes

I have tried adding the TYPE to each database, and then passing a table of that type to the function in the common database, but there I get an error of

Operand type clash: Bits is incompatible with Bits

like image 743
Bauer Avatar asked Mar 06 '12 10:03

Bauer


1 Answers

You can't. Even if you declare the type identically in two databases, they're not treated the same. And the DECLARE statement is only allowed a schema name and an object name, so there's no way to reference a type from another database.

See also this question for some possible work arounds (if you control both databases involved)

like image 76
Damien_The_Unbeliever Avatar answered Jan 01 '23 17:01

Damien_The_Unbeliever