Every production application I have been involved with has made use of a database. As a programmer, you don’t have to be a DBA, but just as with software development you need to adhere to a core set of database best practices.
Some of these are controversial:
* Do not use SELECT * in your queries, explicitly write the required columns names in the select statement.
I think if you follow the database design guidelines and thus do not have tables with 50+ columns (usually), then using * is not always a problem
* Avoid leaking your database design details, such as primary keys.
Usually you have to use your primary keys to identify entities, and so you have to put them on your pages. Of course, you can use ciphers, but do you really need to?
SELECT * is evil. Just add a new column to a database and code all over the place starts breaking even if you don't need that new column. Select * is a shortcut for when you are handwriting temporary queries and should never be used in code. You will understand once the batch job that processes your paycheck fails for 3 weeks while people hunt down this little bit of poop.
Comments
Sergey Tyulkin replied ago:
Some of these are controversial:
* Do not use SELECT * in your queries, explicitly write the required columns names in the select statement.
I think if you follow the database design guidelines and thus do not have tables with 50+ columns (usually), then using * is not always a problem
* Avoid leaking your database design details, such as primary keys.
Usually you have to use your primary keys to identify entities, and so you have to put them on your pages. Of course, you can use ciphers, but do you really need to?
vidalsasoon replied ago:
I think "*" is more of a databinding problem than a performance problem.
amezick replied ago:
SELECT * is evil. Just add a new column to a database and code all over the place starts breaking even if you don't need that new column. Select * is a shortcut for when you are handwriting temporary queries and should never be used in code. You will understand once the batch job that processes your paycheck fails for 3 weeks while people hunt down this little bit of poop.
Gene Gotimer replied ago:
Some of these are bad advice. Since no rationale is given for most of them, the article is of little value.
senfo replied ago:
I'm nitpicking, but that was hard as crap to read. It would have been easier if a list (ordered or not; it doesn't matter) had been used.
Voters For This Link (16)
Voters Against This Link (3)