why would you use WHERE 1=0 statement in SQL?

后端 未结 12 2080
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 00:48

I saw a query run in a log file on an application. and it contained a query like:

SELECT ID FROM CUST_ATTR49 WHERE 1=0

what is the use of s

12条回答
  •  囚心锁ツ
    2020-12-08 01:08

    This is very good in metadata fetching and makes thing generic. Many DBs have optimizer so they will not actually execute it but its still a valid SQL statement and should execute on all DBs. This will not fetch any result, but you know column names are valid, data types etc. If it does not execute you know something is wrong with DB(not up etc.) So many generic programs execute this dummy statement for testing and fetching metadata.

提交回复
热议问题