我正在尝试运行SQL查询以删除表中ID为163到265的行
我试图这样做以减少行数
DELETE FROM `table` WHERE id IN (264, 265)
但是,一次要删除100行时,是否有类似于上述方法的查询,我也试图使用这种查询,但执行失败
DELETE FROM `table` WHERE id IN (SELECT * FROM table WHERE id = )
请告诉我查询以执行上述操作...
我正在尝试运行SQL查询以删除表中ID为163到265的行
我试图这样做以减少行数
DELETE FROM `table` WHERE id IN (264, 265)
但是,一次要删除100行时,是否有类似于上述方法的查询,我也试图使用这种查询,但执行失败
DELETE FROM `table` WHERE id IN (SELECT * FROM table WHERE id = )
请告诉我查询以执行上述操作...
Answers:
如果需要基于列表删除,可以使用IN
:
DELETE FROM your_table
WHERE id IN (value1, value2, ...);
如果您需要根据查询结果删除,也可以使用IN
:
DELETE FROM your_table
WHERE id IN (select aColumn from ...);
(请注意,子查询只能返回一列)
如果您需要基于一系列值删除,请使用BETWEEN
或使用不等式:
DELETE FROM your_table
WHERE id BETWEEN bottom_value AND top_value;
要么
DELETE FROM your_table
WHERE id >= a_value AND id <= another_value;
Delete Id from table where Id in (select id from table)
delete
声明的正确语法
CREATE PROC [dbo].[sp_DELETE_MULTI_ROW]
@CODE XML
,@ERRFLAG CHAR(1) = '0' OUTPUT
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
DELETE tb_SampleTest
WHERE
CODE IN(
SELECT Item.value('.', 'VARCHAR(20)')
FROM @CODE.nodes('RecordList/ID') AS x(Item)
)
IF @@ROWCOUNT = 0
SET @ERRFLAG = 200
SET NOCOUNT OFF
获取字符串值删除
<RecordList>
<ID>1</ID>
<ID>2</ID>
</RecordList>