Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a sql server database table whose is as below

SQL
CREATE TABLE UserNotifications
(
[Ref_NotificationType_ID] [int] NOT NULL, this is a foreign key column
[From_Employee_ID] [int] NOT NULL, this is a foreign key column
[To_Empoyee_ID] [int] NOT NULL, this is a foreign key column
[Ref_Identity_ID] [bigint] NOT NULL, this is a foreign key column
[Identity_Type] [smallint] NOT NULL,
[VersionNumber] [int] NOT NULL,
[Priority] [bit] NOT NULL,
[Created_DateTime] [datetime] NOT NULL,
[Created_By] [varchar](max) NOT NULL,
[Last_Updated_DateTime] [datetime] NULL,
[Last_Updated_By] [varchar](max) NULL,
[HasUserRead] [bit] NOT NULL,
[IsActive] [bit] NOT NULL,
[Flag] [bit] NOT NULL
)


How do i update a specific column in this above table without affecting other matching rows?

What I have tried:

I tried updating a record by using the created_datetime column
Posted
Updated 12-Mar-16 11:17am
Comments
RedDk 13-Mar-16 21:22pm    
By update do you mean insert records or delete records? If so, I would do an indexing of the table before the update, using IDENTITY (1,1), sort on that index, do your insert/delete then remove the index. That last operation isn't even really necessary.

One of the things I've always liked about SQL Server is that it is extremely easy to think outside of the box and do WHATEVER you feel like doing. Don't be discouraged by boneheads who say not to use this or never use that.

1 solution

You need a way to uniquely identify the row even if it is based on multiple columns

SQL
update UserNotifications set field=value where
Ref_NotificationType_ID = 1
and From_Employee_ID = 100
and To_Empoyee_ID = 200
and ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900