Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


update


update

Author
Message
foxjazzG
foxjazzG
SSC-Enthusiastic
SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)

Group: General Forum Members
Points: 159 Visits: 317
I ran the following select, and then the following update.
The select returns 43k records, the update returns 153k. Why isn't the update working as expected?

No update triggers on this table are enabled.

SELECT tblLevelToLevelRel.Active
FROM tblLevelToLevelRel INNER JOIN
TempDelete ON tblLevelToLevelRel.GenLevelToLevelRelID = TempDelete.genleveltolevelrelid



begin tran
update tblleveltolevelrel set active = 0, changeddate = getdate(), changedmachinename = @@servername
FROM tblLevelToLevelRel INNER JOIN
TempDelete ON tblLevelToLevelRel.GenLevelToLevelRelID = TempDelete.genleveltolevelrelid
Wesley Norton
Wesley Norton
SSC Veteran
SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)

Group: General Forum Members
Points: 273 Visits: 442
How many records are in each table? Are there any duplicates?
foxjazzG
foxjazzG
SSC-Enthusiastic
SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)

Group: General Forum Members
Points: 159 Visits: 317
TempDelete has 43k records.

distinct genleveltolevelrelid records
Wesley Norton
Wesley Norton
SSC Veteran
SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)

Group: General Forum Members
Points: 273 Visits: 442
What about tblLevelToLevelRel?
foxjazzG
foxjazzG
SSC-Enthusiastic
SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)

Group: General Forum Members
Points: 159 Visits: 317
the genleveltolevelrel id is a primary key on the tblleveltolevelrel table.
Wesley Norton
Wesley Norton
SSC Veteran
SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)

Group: General Forum Members
Points: 273 Visits: 442
How many records do you get when you run each of the following statements?

SELECT tblLevelToLevelRel.Active,changeddate,changedmachinename
FROM tblLevelToLevelRel INNER JOIN
TempDelete ON tblLevelToLevelRel.GenLevelToLevelRelID = TempDelete.genleveltolevelrelid





Select * from tblLevelToLevelRel



foxjazzG
foxjazzG
SSC-Enthusiastic
SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)

Group: General Forum Members
Points: 159 Visits: 317
first query 43k

second 153k
Wesley Norton
Wesley Norton
SSC Veteran
SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)

Group: General Forum Members
Points: 273 Visits: 442
Are each of these columns in the tblleveltolevelrel table?active,changeddate,changedmachinename
Or are they in the TempDelete table?
foxjazzG
foxjazzG
SSC-Enthusiastic
SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)

Group: General Forum Members
Points: 159 Visits: 317
CREATE TABLE [dbo].[tblLevelToLevelRel](
[GenLevelToLevelRelID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UpperLevelCloneID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LowerLevelCloneID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AllocPercent] [float] NOT NULL,
[Active] [bit] NULL,
[ChangedDate] [datetime] NULL,
[ChangedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ChangedType] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ChangedMachineName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]


the following query ran to update 153k records. I am having to do a database restore becaue of it.

Now when I look to run the following query, it wants to update 43k records. I haven't a clue why.

And I don't know if there is an answer to be honest.

begin tran
update tblleveltolevelrel set active = 0, changeddate = getdate(), changedmachinename = @@servername
FROM tblLevelToLevelRel INNER JOIN
TempDelete ON tblLevelToLevelRel.GenLevelToLevelRelID = TempDelete.genleveltolevelrelid
commit
Wesley Norton
Wesley Norton
SSC Veteran
SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)SSC Veteran (273 reputation)

Group: General Forum Members
Points: 273 Visits: 442
Hmm, so the problem is fixed then?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search