Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Posts
    70

    Unanswered: Just a quick naming convention question

    I just had a quick general DB question but see no "general" forum so might as well post in the forum of the system I am using at the moment MySQL.

    When naming fields, is it better to name them [TABLE_NAME]_[ATTRIBUTE] or just [ATTRIBUTE].


    E.g. TABLE = Student. Should the name field be simply "Name" or would it be equally as good or better as "Student_Name"?


    I would imagine that "Student_Name" would be clearer in queries but do not know if this is bad practice?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    theres almost as many naming conventions as there are bacteria in the human intestine.
    |generally I'd suggest find one that works locvally and stick to it.

    whether that used CamelCase or underscores_to_separate words.
    use obvious abbreviations (bear in mind soem SQL db's restrict the number of significant characters. table and column names shoudl be immediately obvious to the reader (not just the developer who made 'em up

    some SQL shops prefer all lower case (avoids problems migrating table design from db to db as some are case sensitive, some aren't)

    generally its good practice to avoid repeating the table name within the column defintions of that table, but good practice if the column is a foreign key

    generally give table names the plural of waht they hold. so for student data use table: students
    eg
    table: students
    id
    forename
    lastname
    known_as

    table Student_Subjects
    student_id
    course_id


    why?
    no syntactical reason just it looks ugly

    Code:
    select students.student_id, students.students_forename, students.students_lastname from students
    to my mind looks fugly.. its over fussy
    compared to
    Code:
    select students.id, students.forename, students.lastname from students
    when you join tables its even worse
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •