다음을 통해 공유


CLR 매개 변수 데이터 매핑

적용 대상: SQL Server

다음 표에는 Microsoft SQL Server 데이터 형식, System.Data.SqlTypes 네임스페이스의 SQL Server에 대한 CLR(공용 언어 런타임)의 해당 형식 및 Microsoft .NET Framework의 네이티브 CLR이 나와 있습니다.

SQL Server 데이터 형식 형식(System.Data.SqlTypes 또는 Microsoft.SqlServer.Types) CLR 데이터 형식(.NET Framework)
bigint SqlInt64 Int64, Nullable<Int64>
binary SqlBytes, SqlBinary Byte[]
bit SqlBoolean Boolean, Nullable<Boolean>
char None None
cursor None None
date SqlDateTime DateTime, Nullable<DateTime>
날짜/시간 SqlDateTime DateTime, Nullable<DateTime>
datetime2 None DateTime, Nullable<DateTime>
DATETIMEOFFSET 없음 DateTimeOffset, Nullable<DateTimeOffset>
decimal SqlDecimal 10진수, Nullable<10진수>
float SqlDouble Double, Nullable<Double>
geography SqlGeography

SqlGeography는 SQL Server와 함께 설치되고 SQL Server 기능 팩에서 다운로드할 수 있는 Microsoft.SqlServer.Types.dll 정의됩니다.
None
geometry SqlGeometry

SqlGeometry는 SQL Server와 함께 설치되고 SQL Server 기능 팩에서 다운로드할 수 있는 Microsoft.SqlServer.Types.dll 정의됩니다.
None
hierarchyid SqlHierarchyId

SqlHierarchyId는 SQL Server와 함께 설치되고 SQL Server 기능 팩에서 다운로드할 수 있는 Microsoft.SqlServer.Types.dll 정의됩니다.
None
image None None
int SqlInt32 Int32, Nullable<Int32>
money SqlMoney 10진수, Nullable<10진수>
nchar SqlChars, SqlString String, Char[]
ntext None None
numeric SqlDecimal 10진수, Nullable<10진수>
nvarchar SqlChars, SqlString

SQLChars 는 데이터 전송 및 액세스와 더 잘 일치하며 SQLString 은 문자열 작업을 수행하기 위한 더 나은 일치 항목입니다.
String, Char[]
nvarchar(1), nchar(1) SqlChars, SqlString Char, String, Char[], Nullable<char>
real SqlSingle(SqlSingle범위는 실제보다 큽니다.) Single, Nullable<Single>
rowversion None Byte[]
smallint SqlInt16 Int16, Nullable<Int16>
smallmoney SqlMoney 10진수, Nullable<10진수>
sql_variant None Object
table None None
text None None
time None TimeSpan, Nullable<TimeSpan>
timestamp None None
tinyint SqlByte 바이트, Nullable<바이트>
uniqueidentifier SqlGuid Guid, Nullable<Guid>
UDT(사용자 정의 형식) None 동일한 어셈블리 또는 종속 어셈블리의 사용자 정의 형식에 바인딩된 동일한 클래스입니다.
varbinary SqlBytes, SqlBinary Byte[]
varbinary(1), binary(1) SqlBytes, SqlBinary byte, Byte[], Nullable<바이트>
varchar None None
xml SqlXml None

Out 매개 변수를 사용한 자동 데이터 형식 변환

CLR 메서드는 입력 매개 변수를 out 한정자(Microsoft Visual C#) 또는 Out()> ByRef(Microsoft Visual Basic)로 표시하여 호출 코드 또는 <프로그램에 정보를 반환할 수 있습니다. 입력 매개 변수가 System.Data.SqlTypes 네임스페이스의 CLR 데이터 형식이고 호출 프로그램이 해당하는 SQL Server 데이터 형식을 입력 매개 변수로 지정하는 경우 형식 변환은 CLR 메서드가 데이터 형식을 반환할 때 자동으로 발생합니다.

예를 들어 다음 CLR 저장 프로시저에는 Out(C#) 또는< Out()> ByRef(Visual Basic)로 표시된 SqlInt32 CLR 데이터 형식의 입력 매개 변수가 있습니다.

[Microsoft.SqlServer.Server.SqlProcedure]  
public static void PriceSum(out SqlInt32 value)  
{ ... }  
\<Microsoft.SqlServer.Server.SqlProcedure> _  
Public Shared Sub PriceSum( \<Out()> ByRef value As SqlInt32)  
...  
End Sub  

데이터베이스에서 어셈블리를 빌드하고 만든 후 저장 프로시저는 SQL Server에서 출력 매개 변수로 intSQL Server 데이터 형식을 지정하는 다음 Transact-SQL을 사용하여 만들어집니다.

CREATE PROCEDURE PriceSum (@sum int OUTPUT)  
AS EXTERNAL NAME TestStoredProc.StoredProcedures.PriceSum  

CLR 저장 프로시저가 호출되면 SqlInt32 데이터 형식이 자동으로 int 데이터 형식으로 변환되고 호출 프로그램에 반환됩니다.

그러나 출력 매개 변수를 통해 모든 CLR 데이터 형식을 해당 SQL Server 데이터 형식으로 자동으로 변환할 수 있는 것은 아닙니다. 다음 표에서는 이러한 예외를 보여 줍니다.

CLR 데이터 형식(SQL Server) SQL Server 데이터 형식
10진수 smallmoney
SqlMoney smallmoney
10진수 money
DateTime smalldatetime
SQLDateTime smalldatetime

변경 내용

업데이트된 내용
매핑 테이블에 SqlGeography, SqlGeometrySqlHierarchyId 형식이 추가되었습니다.

참고 항목

.NET Framework의 SQL Server 데이터 형식