큰 UDT
개발자는 UDT(사용자 정의 형식)를 통해 SQL Server 데이터베이스에 CLR(공용 언어 런타임) 개체를 저장하여 서버의 스칼라 형식 시스템을 확장할 수 있습니다. UDT는 단일 SQL Server 시스템 데이터 형식으로 구성된 일반적인 별칭 데이터 형식과 달리 여러 요소를 포함할 수 있으며 관련 동작이 있을 수 있습니다.
참고 항목
큰 UDT에 대한 지원이 향상된 SqlClient를 활용하려면 .NET Framework 3.5 SP1 이상을 설치해야 합니다.
이전에는 UDT의 최대 크기가 8KB로 제한되었습니다. SQL Server 2008에서 UserDefined 형식인 UDT에서는 이 제한이 제거되었습니다.
사용자 정의 형식에 대한 전체 설명서는 CLR 사용자 정의 형식을 참조하세요.
GetSchema를 사용하여 UDT 스키마 검색
SqlConnection의 GetSchema 메서드는 DataTable에서 데이터베이스 스키마 정보를 반환합니다. 자세한 내용은 SQL Server 스키마 컬렉션을 참조하세요.
UDT의 GetSchemaTable 열 값
GetSchemaTable의 SqlDataReader 메서드는 열 메타데이터를 설명하는 DataTable을 반환합니다. 다음 표에서는 SQL Server 2005와 SQL Server 2008 간의 큰 UDT 열 메타데이터 차이점에 대해 설명합니다.
SqlDataReader 열 | SQL Server 2005 | SQL Server 2008 이상 |
---|---|---|
ColumnSize |
상황에 따라 다름 | 상황에 따라 다름 |
NumericPrecision |
255 | 255 |
NumericScale |
255 | 255 |
DataType |
Byte[] |
UDT 인스턴스 |
ProviderSpecificDataType |
SqlTypes.SqlBinary |
UDT 인스턴스 |
ProviderType |
21 (SqlDbType.VarBinary ) |
29 (SqlDbType.Udt ) |
NonVersionedProviderType |
29 (SqlDbType.Udt ) |
29 (SqlDbType.Udt ) |
DataTypeName |
SqlDbType.VarBinary |
Database.SchemaName.TypeName과 같이 세 부분으로 지정된 이름 |
IsLong |
상황에 따라 다름 | 상황에 따라 다름 |
SqlDataReader 고려 사항
SQL Server 2008부터 SqlDataReader는 큰 UDT 값 검색을 지원하도록 확장되었습니다. SqlDataReader에서는 현재 사용하고 있는 SQL Server 버전뿐만 아니라 연결 문자열에 지정된 Type System Version
에 따라 큰 UDT를 다르게 처리합니다. 자세한 내용은 ConnectionString를 참조하세요.
다음 SqlDataReader 메서드는 Type System Version
이 SQL Server 2005로 설정된 경우 UDT 대신 SqlBinary를 반환합니다.
- GetProviderSpecificFieldType
- GetProviderSpecificValue
- GetProviderSpecificValues
- GetSqlValue
- GetSqlValues
다음 메서드는 Type System Version
이 SQL Server 2005로 설정된 경우 UDT 대신 Byte[]
배열을 반환합니다.
현재 버전의 ADO.NET에 대해서는 변환이 수행되지 않습니다.
SqlParameters 지정
다음 SqlParameter 속성은 큰 UDT로 작업할 수 있도록 확장되었습니다.
SqlParameter | 설명 |
---|---|
Value | 매개 변수의 값을 나타내는 개체를 가져오거나 설정합니다. 기본값은 null입니다. 이 속성은 SqlBinary , Byte[] 또는 관리 개체일 수 있습니다. |
SqlValue | 매개 변수의 값을 나타내는 개체를 가져오거나 설정합니다. 기본값은 null입니다. 이 속성은 SqlBinary , Byte[] 또는 관리 개체일 수 있습니다. |
Size | 확인할 매개 변수 값의 크기를 가져오거나 설정합니다. 기본값은 0입니다. 이 속성은 매개 변수 값의 크기를 나타내는 정수일 수 있습니다. 큰 UDT의 경우 UDT의 실제 크기이거나 -1(알 수 없는 경우)일 수 있습니다. |
데이터 검색 예제
다음 코드 조각에서는 큰 UDT 데이터를 검색하는 방법을 보여 줍니다. connectionString
변수는 SQL Server 데이터베이스에 대한 올바른 연결이 있다고 가정하고 commandString
변수는 기본 키 열이 가장 먼저 나열된 올바른 SELECT 문이 있다고 가정합니다.
using (SqlConnection connection = new SqlConnection(
connectionString, commandString))
{
connection.Open();
SqlCommand command = new SqlCommand(commandString);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
// Retrieve the value of the Primary Key column.
int id = reader.GetInt32(0);
// Retrieve the value of the UDT.
LargeUDT udt = (LargeUDT)reader[1];
// You can also use GetSqlValue and GetValue.
// LargeUDT udt = (LargeUDT)reader.GetSqlValue(1);
// LargeUDT udt = (LargeUDT)reader.GetValue(1);
Console.WriteLine(
"ID={0} LargeUDT={1}", id, udt);
}
reader.close
}
Using connection As New SqlConnection( _
connectionString, commandString)
connection.Open()
Dim command As New SqlCommand(commandString, connection)
Dim reader As SqlDataReader
reader = command.ExecuteReader
While reader.Read()
' Retrieve the value of the Primary Key column.
Dim id As Int32 = reader.GetInt32(0)
' Retrieve the value of the UDT.
Dim udt As LargeUDT = CType(reader(1), LargeUDT)
' You can also use GetSqlValue and GetValue.
' Dim udt As LargeUDT = CType(reader.GetSqlValue(1), LargeUDT)
' Dim udt As LargeUDT = CType(reader.GetValue(1), LargeUDT)
' Print values.
Console.WriteLine("ID={0} LargeUDT={1}", id, udt)
End While
reader.Close()
End Using