이제 방금 기본 DML 항목 외부에서 저장 프로 시저 및 SQL 코드를 작성하는 방법을 배우기 시작했습니다. 최근에 나는 테이블 값 매개 변수를 발견했습니다. 나는 TVP를 만드는 스크립트를 발견했으나 제대로 작동하지만 두 가지가 이해가되지 않는다. 하나는 언제 사용합니까? TVP가 유익 할 때의 전형적인 현실 시나리오는 무엇입니까? 두번째, 다음 스크립트에서 begin
과 end
을 제거하면 어떻게됩니까? 그 키워드를 갖는 것과 그렇지 않은 것의 차이점은 무엇입니까? SQL 서버 2008 R2테이블 값 매개 변수의 프로덕션 용도
use [tempdb]
--this is the database table that will be populated
create table SampleTable
(
id int not null identity (1,1)
,SampleString varchar(50)
,SampleInt int null
)
go
--create the table data type
create type dbo.SampleDataType as table
(
SampleString varchar(50)
,SampleInt int
)
go
--the stored procedure takes the SampleDataType as an input parameter
create proc SampleProc
(
--accepts the TVP as the lone parameter
--make sure that the TVP is readonly
@Sample as dbo.SampleDataType readonly
)
as
begin
--we simply insert the values into the db table from the parameter
insert into SampleTable(SampleString,SampleInt)
select SampleString,SampleInt from @Sample
end
go
--this is the sample script to test that the sproc worked
declare @SampleData as dbo.SampleDataType
insert into @SampleData(SampleString,SampleInt) values ('one',1);
insert into @SampleData(SampleString,SampleInt) values ('two',2);
select * from @SampleData
행에서 여러 개의 'select'문 뒤에'go'를 추가하는 것과 비슷합니까? – wootscootinboogie
@wootscootinboogie - 아니요. 'GO'는 일괄 구분 기호이며 클라이언트 도구에서만 이해합니다. –
클라이언트 도구가 의미하는 바를 설명 할 수 있습니까? – wootscootinboogie