Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Tables, naming problem

Author  Topic 

BlasterOfMuppets
Starting Member

8 Posts

Posted - 2008-02-14 : 17:10:45
Is there a good way to name tables that are used as lookup tables? If you have a table for movies and you think that a movie can be in more than one genre. Then you will have tables like the following.

a table for movies, table 1
id name ...
1 Scarface

a table for the movie genres, table 2
id name ...
1 action
2 mafia

a table that links the genres to the movies, table 3
id table 1 id table 2 id
1 1 1
2 1 2

Table 1 is no problem. I name it movie.
Table 2 is the genres. I name it movie_genres.
Table 3 specifies the genres for a specific movie so I name it movie_genres. Duh, already taken.

This is just an example and perhaps not the best. What should I call my to genre tables?



jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-02-14 : 17:17:21
Unless a movie is going to be in more than one genre add gener_id to the movies table.
Else name your table movies_x_movie_genres IE a cross reference between the 2


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

BlasterOfMuppets
Starting Member

8 Posts

Posted - 2008-02-14 : 17:45:06
Thank you!

I believe it's a bit hard to read when I use it with joins but I can live with that.
Go to Top of Page

SusanthaB
Starting Member

14 Posts

Posted - 2008-02-15 : 00:25:45
For lookup tables use the suffix as Lkup. E.g. Movie_Lkup

Table 2 you can name as Genres, and 3rd table name as Movie_To_Gengres or Movie_Gengres


Susantha Bathige
Senior DBA, Sri Lanka
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-15 : 02:13:49
Also refer http://vyaskn.tripod.com/object_naming.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

BlasterOfMuppets
Starting Member

8 Posts

Posted - 2008-02-15 : 13:21:37
quote:
Originally posted by SusanthaB

For lookup tables use the suffix as Lkup. E.g. Movie_Lkup

Table 2 you can name as Genres, and 3rd table name as Movie_To_Gengres or Movie_Gengres


Susantha Bathige
Senior DBA, Sri Lanka



I need to think about the postfix.

If I name the table genre then I have problem if i add a music table. In programming you would solve it with namespaces or equilient. Can I do the same in SQL?
Go to Top of Page

BlasterOfMuppets
Starting Member

8 Posts

Posted - 2008-02-15 : 13:23:24
quote:
Originally posted by madhivanan

Also refer http://vyaskn.tripod.com/object_naming.htm

Madhivanan

Failing to plan is Planning to fail



I disagree with most of the naming suggestions in that reference.
Go to Top of Page
   

- Advertisement -