I found this posted on an Internet forum:
You could find out you're one of those new fangled web applications developers who don't actually know much about databases and don't see anything wrong with
SELECT * FROM `tbl_开发者_JAVA百科products` ORDER BY `product_times_bought` DESC LIMIT 0, 500
I'm new to databases, and this looks like a valid query to me. Yet some guy was saying that there is something wrong with using such queries in practice. I don't know why: efficiency? robustness? What could be wrong with this query?
Dont see any syntax error, but its the * which is considered bad practice. The issue with that is, you have no control on which columns the database returns, plus it returns all of them (wasted bandwitdh). It could have other issues like breaking the order it the table is recreated and if a column you need is not there, you wont catch that error in the select query itself, plus reading it doesnt tell you which columns you actually need (mostly you dont need all the columns).So, you should ask the specific columns you need instead of a generic *.
Guys, any other bad practices or recommendations?
精彩评论