define unique keys
am 17.10.2007 22:41:28 von TJM
I have a primary key (column name is emp_id) in employee table. Also,
I would like to make a combination of other two columns is unique.
(combination of officecode field and claimno field must be unique).
how can I implement this uniquess in ms sql 2000? thank you.
Re: define unique keys
am 17.10.2007 23:34:14 von Hugo Kornelis
On 17 Oct 2007 13:41:28 -0700, TGEAR wrote:
>I have a primary key (column name is emp_id) in employee table. Also,
>I would like to make a combination of other two columns is unique.
>(combination of officecode field and claimno field must be unique).
>how can I implement this uniquess in ms sql 2000? thank you.
Hi TGEAR,
CREATE TABLE Demo
(PrimaryKeyColumn int NOT NULL
,HalfOfOtherKeyColumn int NOT NULL
,OtherHalfOfOtherKey int NOT NULL
,SomeOhterKeyForFun int NOT NULL
,CONSTRAINT pk_Demo PRIMARY KEY (PrimaryKeyColumn)
,CONSTRAINT uq_Demo UNIQUE (HalfOfOtherKeyColumn, OtherHalfOfOtherKey)
);
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Re: define unique keys
am 17.10.2007 23:47:58 von Ed Murphy
TGEAR wrote:
> I have a primary key (column name is emp_id) in employee table. Also,
> I would like to make a combination of other two columns is unique.
> (combination of officecode field and claimno field must be unique).
> how can I implement this uniquess in ms sql 2000? thank you.
alter table employee
add constraint officecode_claimno
unique (officecode, claimno)