This article focuses on the tips for executing sql. This method not only brings convenience in operation, but also ensures the security of data.
1: Query data (guaranteed query performance)
# First I want to explain one time
#SELECT * 和 SELECT t.id , t.name 的性能,结论:后者性能其实总体优于前者,不信可以自己去试验。
SELECT cus.uuid , cus.customerId FROM `customer` cus where 1=1 and cus.uuid='' -- and cus.customerId='' and cus.customerName='' or cus.authState='' -- or cus.createTime='';
This way You can write many query conditions, use the ones you need to open as needed, and comment out the ones you don't need. Multi-condition query is faster.
2: Insert/update/delete data (ensure data security)
When operating the database, data security is very important. It is okay to test the database, but it is even more important if you operate the official database. Be careful. The following is a little trick that can help you avoid problems with database SQL execution. Post the code directly: ##--(1):打开事务
START TRANSACTION
--(2):执行要操作数据库的sql ,insert ,update,delete等
update explain_download ex set ex.url = concat('https://www.baidu.com/handbook/',ex.fileName);
--(3):查询执行的sql结果是否正确
SELECT * FROM `explain_download` ed;
--(4):不正确的话,执行回滚
ROLLBACK;
--(5):正确 提交数据
commit;
: Each line above is executed one line at a time.
The above is the detailed introduction of mysql tips for operating sql. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!