Home > Database > Mysql Tutorial > SQL Server通过储存过程实现批量删除注意事项

SQL Server通过储存过程实现批量删除注意事项

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:58:08
Original
1168 people have browsed it

这里设定传过来的参数是拼接好的字符串,如:1,2,3,4,5 create procedure up_batchDeleteById ( @condition varchar(max) ) as delete from dt_name where id in(@condition) 以上的做法看似正确,实际会报错,具体原因是说id是int类型的,而@condition是字

 
这里设定传过来的参数是拼接好的字符串,如:1,2,3,4,5

create procedure up_batchDeleteById

(

    @condition varchar(max)

)

as

delete from dt_name where id in(@condition)

以上的做法看似正确,实际会报错,具体原因是说id是int类型的,而@condition是字符串类型,这样无法删除

正确做法:

create procedure up_batchDeleteById

(

    @condition varchar(max)

)

as

declare @sql varchar(max)

set @sql='delete from dt_name where id in (' + @condition + ')'

exec(@sql)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template