Use What Works: Prefixing Database Tables With 'tbl'
21–30 of 47 posts
Re: Use What Works: Prefixing Database Tables With 'tbl'
#22I remember debating with our datawarehouse designer whether our tables should be singularly-named or plural. Also if the primary key should be TablenameID or just ID.
In the end it doesn't matter. The only thing that materially impacts productivity is maintaining consistent conventions. Take it from someone currently working on a database with three different object prefix styles, key naming and data access methods (ORM, stored procedures and argh dynamic SQL).
Re: Use What Works: Prefixing Database Tables With 'tbl'
#23adjHungarian nounNotation verbHurts detThe nounReadability prepOf possYour nounCode.
Re: Use What Works: Prefixing Database Tables With 'tbl'
#24Earlier quoted context omitted.
So you're recommending writing a stored procedure for this? SELECT COUNT(*) FROM tblposts
Yes. Or alternately, creating a set of views to alias the base tables, and only allowing direct access to the views. Either way gets you some degree of surface area management. Procedures have some added benefit--it's a lot easier to inspect the flow of data when everything is routed through procedure calls. It's a lot easier to put that flow in context when you have a procedure name as a label, provided that your pr…
This approach only makes sense in one of two situations:
1. Ivory Tower DBAs run your company and tell developers "no" at every turn. (sad)
2. Your engineering team makes changing queries hard because they can't hire any developers who know anything about your underlying database platform internals. (also sad)
Re: Use What Works: Prefixing Database Tables With 'tbl'
#25Re: Use What Works: Prefixing Database Tables With 'tbl'
#26adjHungarian nounNotation verbHurts detThe nounReadability prepOf possYour nounCode.
Re: Use What Works: Prefixing Database Tables With 'tbl'
#27Seeing a big MySQL schema where all the tables look like "tblUsers", "tblAccounts", etc. typically lights up the amateur lights for me - because pretty much when I see that, only about 58% of the tables will actually be named that way. Another 32% will be the other way, "accountsTable", "profileTable"; 10% will not have prefixes or suffixes; about 60% of the tables will be named with a plural name (i.e. "users") and…
Re: Use What Works: Prefixing Database Tables With 'tbl'
#28So for a table 'user' you would have: user_id, user_name, user_password, etc. Some tables would have ridiculous long column names.
So what is this good for? First off, joins. If you had a 'post' table and a foreign key back to user_id, the naming scheme was: post_userid. So a join would be: "select from post inner join user on user_id = post_userid". There is no need to alias either table. Also, if both tables have the same field, say both have a 'note' field, it is clear which note you are accessing and there are no ambiguous issues (since one table is post_note and the other is user_note).
Re: Use What Works: Prefixing Database Tables With 'tbl'
#29Earlier quoted context omitted.
Yes. Or alternately, creating a set of views to alias the base tables, and only allowing direct access to the views. Either way gets you some degree of surface area management. Procedures have some added benefit--it's a lot easier to inspect the flow of data when everything is routed through procedure calls. It's a lot easier to put that flow in context when you have a procedure name as a label, provided that your pr…
Coupling queries to the database (stored procedures) instead of to the code that uses them (inlined queries) seems like a recipe for deployment headaches. Especially if you're deploying new code (with new queries) every 2-4 days without downtime. This approach only makes sense in one of two situations: 1. Ivory Tower DBAs run your company and tell developers "no" at every turn. (sad) 2. Your engineering team makes ch…