Closed
Description
When using GetSchema("StructuredTypeMembers", ...) to get the schema for User-Defined-Table-Types, the type schema returned is alway "sys".
To reproduce:
use MyTemp
go
create schema MySchema;
go
create type [dbo].[PostalCodeList] as table ([postalCode] varchar(10));
go
create type [MySchema].[PostalCodeList] as table ([postalCode] varchar(10), [country] char(2));
go
using System.Data;
using Microsoft.Data.SqlClient;
using var connection = new SqlConnection("Data Source=(local);Initial Catalog=MyTemp;Integrated Security=True;Encrypt=false");
connection.Open();
var schema = connection.GetSchema("StructuredTypeMembers", new string[] { null, null, "PostalCodeList" });
foreach (DataRow row in schema.Rows)
{
Console.WriteLine(
string.Format("{0}: [{1}].[{2}].[{3}]",
row["Ordinal_Position"],
row["TYPE_SCHEMA"],
row["TYPE_NAME"],
row["MEMBER_NAME"]));
}
Output:
1: [sys].[PostalCodeList].[postalCode]
1: [sys].[PostalCodeList].[postalCode]
2: [sys].[PostalCodeList].[country]
Expected results:
1: [dbo].[PostalCodeList].[postalCode]
1: [MySchema].[PostalCodeList].[postalCode]
2: [MySchema].[PostalCodeList].[country]
Looking at the SQL statement executed behind the scenes in SQL Profiler, it is returning the schema name from sys.objects.schema_id
which always sys
. The correct schema name should be obtained from sys.table_types.schema_id
.
Metadata
Metadata
Assignees
Labels
No labels