and int, char and varchar, binary, and varbinary are incompatible. Incompatible data types may make the optimizer unable to perform some optimizations that could otherwise have been performed. For example:SELECT name from employee WHERE Salary > 60000In this statement, such as the salary field is a money type, it is difficult for the optimizer to optimize it because 60000 is an integer number. We should convert an integer into a coin type when programming, rather than wait for a run-time conver
data is extracted in a specific order.2, avoid the use of incompatible data types. such as float and int, char and varchar, binary, andThe varbinary is incompatible. Incompatible data types may make it impossible for the optimizer to perform someOptimized operation of the row. For example:SELECT name from employee WHERE Salary > 60000In this statement, such as the salary field is money type, it is difficult for the optimizer to optimize it because 60000is an integer number. We should convert an
[email protected]You can force the query to use the index instead:Select ID from T with (index name) where [email protected]7. You should try to avoid expression operations on the fields in the WHERE clause, which will cause the engine to discard the full table scan using the index. Such as:SELECT * from T1 WHERE f1/2=100should read:SELECT * from T1 WHERE f1=100*2SELECT * from RECORD WHERE SUBSTRING (card_no,1,4) = ' 5378 'should read:SELECT * from R
and can only search the data in the table directly. Such as: The select ID from the Where Num in (three-to-three) value is not used in the Between: Select ID from t where num between 1 and 3 2. When judging whether true or false is, if with and OR OR: (when "Where Condition 1 and condition 2" exists, the database executes the statement to the right first) And try to put the fake to the right (one false is false) or try to put it to the right (one is true) 3. You should try to avoid expression o
. Such as:SELECT * from T1 WHERE f1/2=100should read:SELECT * from T1 WHERE f1=100*2SELECT * from RECORD WHERE SUBSTRING (card_no,1,4) = ' 5378 'should read:SELECT * from RECORD WHERE card_no like ' 5,378% 'SELECT Member_number, first_name, last_name from membersWHERE DATEDIFF (Yy,datofbirth,getdate ()) > 21should read:SELECT Member_number, first_name, last_name from membersWHERE dateOfBirth That is, any action on a column causes a table scan, which i
engine to discard the full table scan using the index. Such as:SELECT * from T1 WHERE f1/2=100should read:SELECT * from T1 WHERE f1=100*2SELECT * from RECORD WHERE SUBSTRING (card_no,1,4) = ' 5378 'should read:SELECT * from RECORD WHERE card_no like ' 5,378% 'SELECT Member_number, first_name, last_name from membersWHERE DATEDIFF (Yy,datofbirth,getdate ()) > 21should read:SELECT Member_number, first_name, last_name from membersWHERE dateOfBirth That i
protected]To force the query to use the index instead:Select ID from T with (index name) where [email protected]7. You should try to avoid expression operations on the field in the Where clause, which will cause the engine to discard the use of the indexFull table scan. Such as:SELECT * from T1 WHERE f1/2=100should read:SELECT * from T1 WHERE f1=100*2SELECT * from RECORD WHERE SUBSTRING (card_no,1,4) = ' 5378 'should read:SELECT * from RECORD WHERE c
engine to discard the full table scan using the index. Such as:SELECT * from T1 WHERE f1/2=100should read:SELECT * from T1 WHERE f1=100*2SELECT * from RECORD WHERE SUBSTRING (card_no,1,4) = ' 5378 'should read:SELECT * from RECORD WHERE card_no like ' 5,378% 'SELECT Member_number, first_name, last_name from membersWHERE DATEDIFF (Yy,datofbirth,getdate ()) > 21should read:SELECT Member_number, first_name, last_name from membersWHERE dateOfBirth That i
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.