Do you prefix each field in a table with abbreviated table name?
Example:
Table: User
Fields:
user_id
user_name
user_password
Or d
if you do it you will end up writing queries like:
SELECT user.user_name, user.user_password, user.user_firstname ...
instead of
SELECT user.name, user.password, user.firstname
so IMO the answer to your question is quite clear.
We also don't use abbreviated table prefixes normally and I wouldn't advice it either.
There's however one situation where we do: reserve fields.
e.g. OH_Reserve_Field_Alpha3 in table ORDER_HEADER
Short background: Our database has 250+ tables and we put in most of them reserve columns to use them for future feature implementations. As you can imagine, without prefixing you would end up having 50 Reserve_Field_Alpha3's with totally different meaning but same name throughout your code. It's already hard as it's now, but without prefixes it would be worse.
For all the reasons given, I don't think this is a good idea. Besides, you don't prefix all the methods in your classes with the class names, do you? So why do it for database objects?
Personally, on the 'user' table, my column would just be 'id'.
But any foriegn key columns on different tables pointing to that column, I'd call the column 'user_id'.
so you might end up with something like this :
select *
from order
inner join user
on user.id=order.user_id
It's an awesome practise:
amount
means
(transactions
, incomes
) — unless
they are xac_amount
and
inc_amount
. Most query tools do
not output alias along with the
field name.x
as an alias for
transaction
, another one will use
tran
and so on.In fact, prefixes are just forced tables aliases, so you can easily see what field belongs to what table.
When I add the field "ordinal" to a table I like to add in a prefix so I don't have to alias ordinal fields from other tables in JOINS. It's handy for JOINS sometimes... not sure I have seen other benefits.
MediaWiki (the Wikipiedia software) uses that convention. Download the source. They limit themselves to a two character prefix.
I don't recommend the practice though. For most databases its not necessary.