Cache Table에 자동 증가값을(Oracle Sequence와 유사) 주고 싶을 때 다음과 같이 해보자.
1. Table 생성
우선 해당 클래스를 다음과 같이 새로 만들고 자동증가값을 주고 싶은 MYPK 컬럼을 SqlComputed=true로 설정한다.
Class User.AutoT Extends %Persistent
{
Property MYPK As %Integer [ Calculated, SqlComputeCode = { set {MYPK}={ID}}, SqlComputed ];
Property NewProperty1 As %String;
}
2. 초기값 주기
3. Auto Increment 컬럼 액세스 하기
select MyPK, NewProperty1 from AutoT
결과는 아래와 같이 MYPK 값이 자동으로 증가하고 있음을 알 수 있다.
# |
MYPK |
NewProperty1 |
1 |
1 |
Hello |
2 |
2 |
Hello2 |
|