|
|
 |
Re: FN-FORUM: Advanced Databases for Beginners
date posted 6th September 2006 16:47
> I agree with the title and author tables, (book_title/ book_author, bad bad
> bad) but normally I use a specific id field - ie: 'book_id' or maybe 'bid'
> so if a select statement requires id's from multiple tables that are easier
> to distinguish between.
>
> What's on the downside of naming an id field in this way?
I would have thought the best goal to aim for would be consistency,
and to that end if you've named all of your primary keys "id" rather
than by some arbitrary contraction such as "bid" then it means you can
just get on with the idea of writing the SQL rather than having to
refer back to your table definition every 5 seconds so you can work
out what you called the field. You can easily distinguish between
id's by use of table aliases, which you probably should be using
anyway.
The idea of establishing a coding convention is for readibility and
consequently ease of use - I guess it's whatever works best for you,
however I'd agree that NOT prefixing every field name with the name of
the table is a good move. One place I worked at insisted that each
field name was prefixed by a character to indicate the datatype (e.g.
v_first_name, i_id), however the convention used for database fields
was different to the convention they used for within the scripting
code.
I forget what point I was trying to make there, but it's nice to
participate in a discussion, isn't it ?? :)
Jason
|
 |
|