问题
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
回答1:
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)
回答2:
According to Creating User-Defined Data Types:
If a user-defined data type is created in the model database, it exists in all new user-defined databases. However, if the data type is created in a user-defined database, the data type exists only in that user-defined database.
来源:https://stackoverflow.com/questions/9581749/user-defined-type-across-databases