반응형
  1. /**********************************************************************************************
    -- Title : [2k5] 계산된 컬럼을 실제 저장하기(PERSISTED)
    -- Reference : sqlworld.pe.kr
    -- Key word : persisted computed_columns is_persisted
    **********************************************************************************************/
    -- 읽을 때 계산됨
    create table ttt
    ( a int not null
    , b int not null
    , c as a+b
    );
    go
     
    insert into ttt values (1,1);
    insert into ttt values (2,2);
    go
     
    select * from ttt;
    go
     
    select * from sys.computed_columns where is_persisted=0 ;
    go
     
    -- 쓸 때 계산되어 저장
    create table ttt2
    ( a int not null
    , b int not null
    , c as a+b persisted   --// 실제 저장 명령
    );
    go
     
    insert into ttt2 values (1,1);
    insert into ttt2 values (2,2);
    go
     
    select * from ttt2;
    go

반응형

+ Recent posts