이 쿼리의 답변은 here입니다. where 절에는 (1 = 1)이 있지만 실행 계획은 동일합니다 (SQL Express 2008R2).Where 절의 (1 = 1) 이유는 무엇입니까?
나는 옛날부터 유물이라고 생각하니? 코드에서 동적 SQL을 생성 할 때
SELECT
ind.name
,ind.index_id
,ic.index_column_id
,col.name
,ind.*
,ic.*
,col.*
FROM sys.indexes ind
INNER JOIN sys.index_columns ic
ON ind.object_id = ic.object_id and ind.index_id = ic.index_id
INNER JOIN sys.columns col
ON ic.object_id = col.object_id and ic.column_id = col.column_id
INNER JOIN sys.tables t
ON ind.object_id = t.object_id
WHERE (1=1)
AND ind.is_primary_key = 0
AND ind.is_unique = 0
AND ind.is_unique_constraint = 0
AND t.is_ms_shipped = 0
ORDER BY
t.name, ind.name, ind.index_id, ic.index_column_id
DUP : [왜 누군가가 WHERE 1 = 1을 사용하고을 SQL 절에 사용합니까?] (http://stackoverflow.com/questions/242822/why-would-someone-use-where-1-1-and) -conditions-in-a-sql-clause) –
(1 = 1)이 true 인 경우 where 문을 제거하고 어떤 결과가 나타나는지보십시오. – DragonZero
때로는 1 = 1 또는 1 = 2를 사용하여 원래 프로그래머가 논리를 개발할 수 있도록 항상 true 또는 false를 반환하는 작업을 수행합니다. 그런 다음 그들은 단순히 그곳에 남겨 두었습니다. –