Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Make it a field value as unique

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2009-01-19 : 03:21:14
Hi,
I've below table,
CREATE TABLE MsgDetails(
[TrnxNo] [numeric](18, 0) IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[HeaderNo] [numeric](18, 0) NOT NULL,
[Indicator] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_tfpxPay_RRMsgDet] PRIMARY KEY CLUSTERED
([RRMsg_TrnxNo] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

My design as follow
1. TrnxNo is a primary key

I need a help, how to using ALTER TABLE to make it my HeaderNo field is unique?

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-19 : 03:38:00
alter table MsgDetails add constraint constraintname unique (headerno)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-19 : 03:42:46
if you havent already created table, you can use this with create table also


CREATE TABLE MsgDetails(
[TrnxNo] [numeric](18, 0) IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[HeaderNo] [numeric](18, 0) NOT NULL,
[Indicator] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_tfpxPay_RRMsgDet] PRIMARY KEY CLUSTERED
([RRMsg_TrnxNo] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
CONSTRAINT [UQ_Header_No] UNIQUE
) ON [PRIMARY]

Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2009-01-19 : 03:47:50
tq very much.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-19 : 04:14:48
welcome
Go to Top of Page
   

- Advertisement -