小编use*_*441的帖子

在SQL中使用危险的IN子句

为什么SQL服务器会以这种方式运行.我在SQL 2005上运行它.

IN子句不验证子查询中的列名,而是根据外部查询中的表名验证它.这是一个获得的例子

Create table #table1(col1 int, col2 char(10), col3 char(15));

Create table #table2(col10 int, col11 char(10), col2 char(15));


insert into #table1(col1, col2, col3)
select 1, 'one', 'three'

insert into #table1(col1, col2, col3)
select 2, 'two', 'three'

insert into #table1(col1, col2, col3)
select 3, 'three', 'four'


insert into #table2(col10, col11, col2)
select 1, 'one', 'three'

insert into #table2(col10, col11, col2)
select 2, 'two', 'three'

insert into #table2(col10, col11, col2)
select 3, 'three', 'four'


select * from #table1
where col1 IN …
Run Code Online (Sandbox Code Playgroud)

sql sql-server sql-server-2005

3
推荐指数
2
解决办法
233
查看次数

标签 统计

sql ×1

sql-server ×1

sql-server-2005 ×1