Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

RE: FN-FORUM: Advanced Databases for Beginners

date posted 6th September 2006 16:48

Quoting Mark Bell [EMAIL REMOVED]

> Dave,
>
> Why is this so?
>
> Bad example:
>
> CREATE table book (
> book_id INTEGER,
> book_title VARCHAR(100),
> book_author_id INTEGER
> }
>
> Good example
>
> CREATE table book (
> id INTEGER,
> title VARCHAR(100),
> author INTEGER
> )
>
> I agree with the title and author tables, (book_title/ book_author, bad ba=
d
> 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 easie=
r
> to distinguish between.
>
> What's on the downside of naming an id field in this way?

Well, to be honest, not much. A lot of advice on naming conventions =20
comes down to choosing a set of rules that you like and sticking with =20
it. And if you prefer a primary key to be called {table}_id then I =20
don't really have any strong opinions against that.

Personally, I like the fact that every table will have a column with =20
the same name that is the primary key of that table. To me, that just =20
makes the database easier to use. And I think that when you are =20
joining multiple tables then you should be using explicit table names =20
(or aliases) for all the columns so the confusion would never arise. =20
For example:

SELECT book.title
FROM book
JOIN author
ON book.author =3D author.id
WHERE author.name =3D 'Someone'

In your case, the only clause that would change would be the ON clause =20
which would become:

ON book.author =3D author_id

which really isn't different enough to worry about in my opinion.

A lot of the slides aren't really trying to say "this is the only way =20
to do it" but rather "think about why you're doing this and ensure you =20
have a good reason". Of course that might not come over quite so =20
strongly when I'm not actually there giving the talk.

Dave...

--=20
Magnum Solutions Ltd
Open Source Consultancy, Development and Training
http://mag-sol.com/



Messages by Day
September 30th 2006
September 29th 2006
September 28th 2006
September 27th 2006
September 26th 2006
September 25th 2006
September 24th 2006
September 23rd 2006
September 22nd 2006
September 21st 2006
September 20th 2006
September 19th 2006
September 18th 2006
September 17th 2006
September 16th 2006
September 15th 2006
September 14th 2006
September 13th 2006
September 12th 2006
September 11th 2006
September 10th 2006
September 9th 2006
September 8th 2006
September 7th 2006
September 6th 2006
September 5th 2006
September 4th 2006
September 3rd 2006
September 2nd 2006
September 1st 2006


Messages by Month
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000