引用来自不同数据库的 table 变量
Referring to a table variable from a different database
使用数据库名称声明 table 变量会引发以下错误。
The type name 'dbname.dbo.TableType' contains more than the maximum
number of prefixes. The maximum is 1.
Declare @cutoffDtes as dbname.dbo.TableType
但是,当我执行以下操作时同样有效
use dbname
Declare @cutoffDtes as dbo.TableType
有没有办法将变量与数据库名称一起声明?
documentation 非常清楚(一旦您找到参考),用户定义的类型仅在单个数据库中可用:
Using UDTs Across Databases
UDTs are by definition scoped to a single database. Therefore, a UDT defined in one database cannot be used in a column definition in another database. In order to use UDTs in multiple databases, you must execute the CREATE ASSEMBLY
and CREATE TYPE
statements in each database on identical assemblies. Assemblies are considered identical if they have the same name, strong name, culture, version, permission set, and binary contents.
换句话说,您可以在其他数据库中重复定义,如果一切都相同,那么它们是兼容的。
使用数据库名称声明 table 变量会引发以下错误。
The type name 'dbname.dbo.TableType' contains more than the maximum number of prefixes. The maximum is 1.
Declare @cutoffDtes as dbname.dbo.TableType
但是,当我执行以下操作时同样有效
use dbname
Declare @cutoffDtes as dbo.TableType
有没有办法将变量与数据库名称一起声明?
documentation 非常清楚(一旦您找到参考),用户定义的类型仅在单个数据库中可用:
Using UDTs Across Databases
UDTs are by definition scoped to a single database. Therefore, a UDT defined in one database cannot be used in a column definition in another database. In order to use UDTs in multiple databases, you must execute the
CREATE ASSEMBLY
andCREATE TYPE
statements in each database on identical assemblies. Assemblies are considered identical if they have the same name, strong name, culture, version, permission set, and binary contents.
换句话说,您可以在其他数据库中重复定义,如果一切都相同,那么它们是兼容的。