thcricketfan
thcricketfan

Reputation: 80

Naming database table fields to designate relationships?

Lets say I have tables Student and Mentor

Does anyone use naming convention for relationship as below? I think this way is good to see the relationships quickly. Would anyone suggest a better way?

Student

StudentID
StudentName
Student2MentorID

Upvotes: 0

Views: 100

Answers (3)

user2072139
user2072139

Reputation: 61

It is better to use underscores... I suggest to simply use existing naming convention rules such as this one: http://www.oracle-base.com/articles/misc/naming-conventions.php

Upvotes: 0

Leonidas
Leonidas

Reputation: 21

I think: you can add prefix (3 letters) to table depending that module represents (scholar,sales,store)

module: scholar ->sc

table: scStudent ( IdStudent,nameStudent..)

table: scMentor(IdMentor,nameMentor...)

relationship

scMentorStudent (IdMentorStudent pk..)

You can use Microsoft's EF notation :
http://weblogs.asp.net/jamauss/pages/DatabaseNamingConventions.aspx

Upvotes: 1

nl2br
nl2br

Reputation: 21

To start from scratch, - you probably know this already - there are several ways to represent your database schema, I mean, by using diagrams, for example ER-diagrams that helps you (and your team) stay up to date with your database's design and thus making it simpler to understand.

Now, personally when it comes to implementation, I do use some kind of naming-convention. For example:

  • For large projects, I use double underscores to split between table categories, (ie. hr__personnel, hr__clocks, hr__timetable, vehicles__cars, vehicles__trips) and so on.

  • Now, having a relationship between two tables, I do Include both (or all) of the involved table names. (ie. hr__personnel_timetable, vehicles__cars_trips, etc)

  • Sometimes, (as we all know), we cannot follow strictly a standard, so in those cases I use my own criteria when choosing large relationships' names.

  • As a rule, I also name table attributes by a three-letter preffix. For example, in my table trips, my fields will be tri_id,tri_distance, tri_elapsed

  • Note also, that in the above item, I didn't include a Foreign Key. So here I go then. When it comes to FK's, It's easy for me (and my team) to realize that the field IS a FK. If we follow the previous example, I would like to know who drives in each trip (to make it easier, we assume that only one person drives one trip). So my table now is something like this: tri_id, per_id, tri_distance, tri_elapsed. Now you can easily realize that per_id is just a foreign field of the table. Just, another hint to help.

Just by following these simple steps, you will save hours, and probably some headaches too.

Hope this helps.

Upvotes: 1

Related Questions