2011-11-09 5 views
1

나는 두 개의 테이블을 가지고있다.고유 한 sqlsever 데이터 형식을 만드는 방법?

table test1 
{ 
id int identity(1,1), 
name char(40) primary key 
} 

table test2 
{ 
id int primary, 
_test1 int 
} 

나는 _test1이 Tbl test1 (id)의 외래 키 였으면 좋겠다. 하지만 그건 오류가 있습니다. 내가 할 수있는 id int test1 unique?

답변

1

test1

create table test1 
(
    id int identity unique, 
    name char(40) primary key 
) 

create table test2 
(
    id int primary key, 
    _test1 int references test1(id) 
) 
idunique constraint 추가
관련 문제