April 6, 2011 at 3:29 pm
I have unique index on combination of 3 columns on a Table, Now I want to update one of the column in those 3 columns
Can you please help me out on this
Example: I have Unique index on columns A, B, C in Table
Now I want to update the Column B
Thnaks
Grace
April 6, 2011 at 3:45 pm
Update as in change the value? If so a straightforward UPDATE statement will work. If not, I'm confused as to what you're asking
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 8, 2011 at 9:08 am
Hi Grace,
It does not matter that your unique index is a combination of many columns,
you can update any of the columns as long as your update does not violate the uniqueness of the constraint.
For example:
CREATE TABLE UserTable
(
ColumnA varchar(10) NOT NULL,
ColumnB varchar(15) NOT NULL,
ColumnC varchar(10) NOT NULL,
ColumnD varchar(50) NULL
) ON [PRIMARY]
GO
ALTER TABLE UserTable ADD CONSTRAINT
PK_Table_1 PRIMARY KEY CLUSTERED
(
ColumnA,
ColumnB,
ColumnC
)
GO
insert into UserTable(ColumnA,ColumnB,ColumnC,ColumnD)
values ('ValueA','ValueB','ValueC','ValueD')
GO
insert into UserTable(ColumnA,ColumnB,ColumnC,ColumnD)
values ('ValueA1','ValueB1','ValueC1','ValueD1')
GO
insert into UserTable(ColumnA,ColumnB,ColumnC,ColumnD)
values ('ValueA2','ValueB2','ValueC2','ValueD2')
go
update UserTable
set ColumnB = 'NewValueB'
where ColumnD = 'ValueD2'
select * from UserTable
DbDefence - transparent database encryption and SQL protection
QUIGROUP- Need a Certified experienced DBA for a project or troubleshooting? Need help with programming, database recovery, performance tuning, ETL, SSRS or developing new databases? Contact us.. 1-786-273-9809
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply