删除SQL Server中的脚本工作很奇怪。根据逻辑删除的数据将被删除。 [英] Delete script in SQL server is working weird. The data that should not be deleted as per the logic is being deleted.

查看:84
本文介绍了删除SQL Server中的脚本工作很奇怪。根据逻辑删除的数据将被删除。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SP中有一个sql server删除脚本,如下所示:

-------------------------- --------------------------

 删除 
rvb
FROM
[dbo]。[ ' RVB temp tbl $'] rvb
JOIN [dbo]。[ ' 实际RVBReferenced BR $'] rvbBr ON
rvb.Rid = rvbBr.Rid
WHERE
NOT EXISTS
SELECT
1
FROM
[dbo]。[BR $] tmp
WHERE
tmp。[ED#] = rvbBr.id



------------------------------------------------ ------------

rvb表包含225 Rid(Id),rvbr表包含与Rid相关的Rid和sub id。 tmp表是包含所有子id的主表,这意味着rvbr中的每个子Id都在tmp表中。上面的删除脚本删除了rvb表中的Rid,其子Id(加入rvbr)不在tmp表中。但是,问题是,删除脚本正在删除tmp表中存在的3个子ID的Rid,这是一个奇怪的功能。



有人可以告诉我删除脚本有什么问题吗?



我有什么尝试过:



我在变量之前尝试过使用Rtrim和Ltrim,认为在使用的表数据中可能存在空间问题但没有用。 div class =h2_lin>解决方案

'] rvb
JOIN [dbo]。[' 实际RVBReferenced BR


'] rvbBr ON
rvb.Rid = rvbBr.Rid
WHERE
EXISTS
SELECT
1
FROM
[dbo]。[BR

tmp
WHERE
tmp。[ED#] = rvbBr.id



--------------------------------- ---------------------------

rvb表包含225个Rid(Id)和rvbr表包含Rid和sub id与Rid相关。 tmp表是包含所有子id的主表,这意味着rvbr中的每个子Id都在tmp表中。上面的删除脚本删除了rvb表中的Rid,其子Id(加入rvbr)不在tmp表中。但是,问题是,删除脚本正在删除tmp表中存在的3个子ID的Rid,这是一个奇怪的功能。



有人可以告诉我删除脚本有什么问题吗?



我有什么尝试过:



我在变量之前尝试过使用Rtrim和Ltrim,认为在使用的表数据中可能存在空间问题但没有用。 / BLOCKQUOTE>

I have a sql server delete script in a SP as below:
----------------------------------------------------

DELETE
      rvb
       FROM
           [dbo].['RVB temp tbl$']           rvb
           JOIN [dbo].['Actual RVBReferenced BR$'] rvbBr ON
           rvb.Rid = rvbBr.Rid
       WHERE
           NOT EXISTS (
               SELECT
                   1
               FROM
                   [dbo].[BR$] tmp
               WHERE
                  tmp.[ED#] = rvbBr.id
           )


------------------------------------------------------------
The rvb table contains 225 Rid's(Id's) and rvbr table contains Rid's and sub id's related to Rid. The tmp table is the master table that contains all the sub id's which means that every sub Id in rvbr will be in tmp table. The above delete script deletes the Rid's in rvb table whose sub Id's(joining rvbr) are not in tmp table. But, the issue is that, the delete script is deleting 3 Rid's of sub Id's that are present in tmp table which is a weird functioning.

Can someone please tell me what's wrong with the delete script?

What I have tried:

I have tried using Rtrim and Ltrim before the variables, thinking that there might be space issue in data of tables used but no use.

解决方案

'] rvb JOIN [dbo].['Actual RVBReferenced BR


'] rvbBr ON rvb.Rid = rvbBr.Rid WHERE NOT EXISTS ( SELECT 1 FROM [dbo].[BR


tmp WHERE tmp.[ED#] = rvbBr.id )


------------------------------------------------------------
The rvb table contains 225 Rid's(Id's) and rvbr table contains Rid's and sub id's related to Rid. The tmp table is the master table that contains all the sub id's which means that every sub Id in rvbr will be in tmp table. The above delete script deletes the Rid's in rvb table whose sub Id's(joining rvbr) are not in tmp table. But, the issue is that, the delete script is deleting 3 Rid's of sub Id's that are present in tmp table which is a weird functioning.

Can someone please tell me what's wrong with the delete script?

What I have tried:

I have tried using Rtrim and Ltrim before the variables, thinking that there might be space issue in data of tables used but no use.


这篇关于删除SQL Server中的脚本工作很奇怪。根据逻辑删除的数据将被删除。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆