Constrain Primary Key Single – The WHERE clause in this query also references the primary key of the EMPLOYEES table. The not equals (<>) constraint cannot be used to optimize the search. Notice that the result is the same as the Optimize Primary Key query but the cost is greater. The plan step will use the test to limit the number of rows included in the result. Using <> or the CONTAINS operator ( [ ) in a query will constrain the search. DEMO_SP_CON STRAIN _PK SET SHOW_PLAN = YES SELECT NAME FROM EMPLOYEES WHERE EMP_SSN <> '200-00-0000' PLAN Query #1 Plan #2 Estimated cost=8 result=4 Step #1 Get table EMPLOYEES Use <> on EMP_SSN to limit search
Constrain Primary Key – Single The WHERE clause in this query also references the primary key of the EMPLOYEES table. The not equals (<>) constraint cannot be used to optimize the search. Notice that the result is the same as the Optimize Primary Key query but the cost is greater. The plan step will use the test to limit the number of rows included in the result. Using <> or the CONTAINS operator ( [ ) in a query will constrain the search. DEMO_SP_CON STRAIN _PK SET SHOW_PLAN = YES SELECT NAME FROM EMPLOYEES WHERE EMP_SSN <> '200-00-0000' PLAN Query #1 Plan #2 Estimated cost=8 result=4 Step #1 Get table EMPLOYEES Use <> on EMP_SSN to limit search
_new_sql_reference.docx