Results 1 to 4 of 4

Thread: Storing Database table names

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Storing Database table names

    I am in a situation where I have a database consisting of approx 35 tables. I have just changed a table name which meant I had to trawl through all the code and change all the instances in the SQL code. What would be the best way to store all the table names in one place so "IF" I have to change one again, I only have to do it the once.

    I was thinking some sort of enumerated type?

    Thanks
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Storing Database table names

    well I always name my SQL Tables with a tbl prefix (probably the old school programmer in me) but you may want to name your tables accordingly too. Maybe not a "tbl" prefix, but something that would tell you that its a table just by looking at the name.

    Then if you need to do something like this in your code, you can do a global find and replace, since if you name them accordingly, it won't conflict with any other name in your app.

    Another thought is that table design should generally be pretty well thought out. I have never changed a table name after an app was in production that used a database.

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Storing Database table names

    You can also make your code more generic by using variables in place of table names...
    For eaxample, you could declare a gobal variable:
    Private prodTable As String = "Products"
    Then write "Select * from " & prodTable instead of spelling out "Select * from Products"... So if a table name change occurs, you only have to change your code at 1 place.

  4. #4
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Storing Database table names

    I use custom attributes (see this article) to map my classes to my underlying database tables - then if a table or field name is changed you just change teh attribute.

    Given that my apps tend to have hundreds of tables this is a real timesaver - although it is quite advanced code.

Posting Permissions

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



Click Here to Expand Forum to Full Width