Link to home
Start Free TrialLog in
Avatar of ckelsoe
ckelsoeFlag for United States of America

asked on

Global Rename / Shorten field names

I have some tables with very long field names. I would like to shorten them to be no longer than 60 chars in length. Is it possible to do this globally? Can the field names be changed in a system table that would reflect the actual table field name?
Avatar of Nightman
Nightman
Flag of Australia image

DON'T edit the system tables directly.

Furthermore, if you change field names you will end up breaking dependant objects (such as views, functions and stored procedures). I am afraid that you will have to do this one by one, carefully checking the dependancies.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ckelsoe

ASKER

Hi aneeshattingal

That works to a point. It is possible that the long field name would have the same name at 60 chars, so how could I put an incremental number at the end so that it would be  something like samefieldname1, samefieldname2, etc.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yogesh,
I think he is looking for something like this
for example he has tables say Tab1 and Tab2. Let us say both of these contains 5 fields each
TabA (a.....a, a....b ,Col, a....c etc) similar in tab2 also, now what he want is to rename such that

TabA(a....1, a....2,Col, a...3 )

This can be done with cursors  and with temptables / tablevariables

Avatar of Yogeshup
Yogeshup

I thought that is what my query does. What it does is that it searches the columns table for the same columns (first 60 chars only) within the same table and if found, it will add a number based on the order (ordinal_position, which I am assuming is unique for each column within a table). I think what it also might end up doing even if the column name is unique, it will still add a 1 to it. I think that might require a case. I dont think he needs to use cursors. Am I right?

Also, I am hoping that he does not have procedures using these tables else he might have to replace it manually, right?
Avatar of ckelsoe

ASKER

Thanks for the help.

There are no procedures, views, etc. so renaming the fields will not break anything. The number at the end of the field name can be any number so long as it is unique. I am traveling rignt now and do not have the ability to test Yogesh's example.
@Yogeshup ,
I am sorry Yogesh, actually I didn't see the 'ORDINAL_POSITION' Part, I also work out in the sameway , but as u have already posted i don't find any necessary to repost it again
:)