26 July 2006

Dear Noob DB Programmer: Knock it Off

Tip #1: Don't name a anything "user" or "users". Those are reserved keywords in many RDBMS and application servers, so using them in your schema or code reduces transportability. Try "member" or "luser" or something.

Tip #2: Don't name a column "id". Again that's a reserved keyword for a lot of systems. See #3 below.

Tip #3: Make sure your column names are unique. The only time that the same column name should appear in more than one table is if it's a foreign key. Try prefixing your column names with the table name or a portion thereof. For example, the primary key in the "member" table could be named "memberID" or "memb_id" or even "m_id". This will make your schema much more friendly to other developers and DBAs by making the relationship between tables and columns clear at a glance (if you see "m_id" in the member table and "m_id" in the order table, it's pretty obvious how those tables are related, isn't it.)

Tip #4: Don't store dates as strings. When you do, you're basically pissing-away data or processor cycles or time or all three. All RDBMS have native date/time data types. Use them.

Tip #5: Don't store user passwords in clear text. Again, most RDBMS have bidirectional encryption built right in. Use it, and make sure you don't store the key in the database.

Thank you for your cooperation.

No comments: