|
-
Feb 21st, 2007, 10:43 AM
#1
Thread Starter
Fanatic Member
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 
-
Feb 21st, 2007, 10:48 AM
#2
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.
-
Feb 21st, 2007, 12:26 PM
#3
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.
-
Feb 21st, 2007, 12:40 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|