Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a data type (table) defined in another database in SQL2k8?

I have a Table Type defined in a database. It is used as a table-valued parameter in a stored procedure. I would like to call this procedure from another database, and in order to pass the parameter, I need to reference this defined type.

But when I do DECLARE @table dbOtherDatabase.dbo.TypeName , it tells me that The type name 'dbOtherDatabase.dbo.TypeName' contains more than the maximum number of prefixes. The maximum is 1.

How could I reference this table type?

like image 321
Victor Rodrigues Avatar asked May 20 '10 18:05

Victor Rodrigues


People also ask

How do you call a table from a different database?

To access the data from table which exists in different databases hosted in same SQL Server instance, you need to provide full qualify name for table such as table name including database name, and schema (database_name. schema_name. table_name) as shown below.

How do you pass a table datatype to a procedure in SQL Server?

Create a user-defined table type that corresponds to the table that you want to populate. Pass the user-defined table to the stored procedure as a parameter. Inside the stored procedure, select the data from the passed parameter and insert it into the table that you want to populate.


1 Answers

Cross-database user-defined types seems to work only for CLR-based types. See this forum and MSDN (plus comments).

like image 142
devio Avatar answered Oct 04 '22 13:10

devio