Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server sp#U游标准备';选择。。。。。。。。其中0=1';-为何_Sql Server_Tsql_Sql Server 2008 R2_Cursor_Sql Server Profiler - Fatal编程技术网

Sql server sp#U游标准备';选择。。。。。。。。其中0=1';-为何

Sql server sp#U游标准备';选择。。。。。。。。其中0=1';-为何,sql-server,tsql,sql-server-2008-r2,cursor,sql-server-profiler,Sql Server,Tsql,Sql Server 2008 R2,Cursor,Sql Server Profiler,SQL Server Profiler显示,我们的ERP应用程序向DB Server发送了大量命令,如下所示: declare @p1 int set @p1=NULL declare @p5 int set @p5=16388 declare @p6 int set @p6=8196 exec sp_cursorprepare @p1 output,NULL,N'SELECT * FROM SomeTable WHERE 0 = 1',1,@p5 output,@p6 output selec

SQL Server Profiler显示,我们的ERP应用程序向DB Server发送了大量命令,如下所示:

declare @p1 int
set @p1=NULL
declare @p5 int
set @p5=16388
declare @p6 int
set @p6=8196
exec sp_cursorprepare @p1 output,NULL,N'SELECT * FROM SomeTable WHERE 0 = 1',1,@p5 output,@p6 output
select @p1, @p5, @p6
强调:

exec sp_cursorprepare
然后选择(…),其中0=1


这有什么意义吗?这是一种技巧吗?

当应用程序生成带有“WHERE 0=1”或“WHERE 1=1”的SQL语句时,它通常被用作占位符,这样应用程序就可以使用AND或or动态构建WHERE子句的其余部分,而不必弄清楚哪个条件是第一个条件,并且需要立即遵循“WHERE”


是的,这是一个让应用程序开发人员更容易构建动态WHERE子句的技巧。我自己也用过。

你的意思是1=0[或条件1][或条件2][或条件3]。是的,这是有道理的。我必须再次审查这些问题。谢谢,是的,我就是这个意思。开发人员不知道在运行时将生成哪些附加的OR条件,因此他/她以WHERE 1=0启动WHERE子句,告诉SQL“除非有返回true的附加条件,否则不要返回任何行。”