change column names in SQL views from Sentence case to Title Case

Category: sql server getstarted

Question

kvd123 on Wed, 27 Mar 2019 18:47:55


I have several views that have column names formatted to Sentence case due to wrong setting in the formatting file. How can I change those to Title Case for easy readability?  

Examples - change the following column names as described below:

[Linereversalnumber] to [LineReversalNumber]

[Linenumber] to [LineNumber]

Thanks.

Replies

Olaf Helper on Wed, 27 Mar 2019 19:00:23


Simply change the column names in the view, e.g. using column alias; so where is the problem?

kvd123 on Wed, 27 Mar 2019 19:36:18


I have hundreds of views, and don't want to keep typing alias names for each column in all the views. Is there some sort of formatting utility that I can use to change column names or create aliases, or simply use the column names from the tables involved which are still formatted in Title Case.

Thanks.

scott_morris-ga on Thu, 28 Mar 2019 01:29:31


"Several" or "hundreds"? If this is all due to an incorrect formatting file, can't you just rerun the process that created them after fixing the file? 

Dedmon Dai on Thu, 28 Mar 2019 09:02:36


Hi kvd123,

 

You can write a script to rename all column name in your views. The script will read all columns and rename all.

 

According to your description, you want to capitalize the first letter of each word in the column name, but there is no clear identifier to determine the letter that needs to be capitalized.

 

There is a similar problem here, but we can use underscores to locate letters that need to be capitalized:https://it.toolbox.com/question/how-can-i-change-a-table-column-from-lower-case-to-title-case-in-sql-server-2008-081911

 

Hope this could help you .

Best regards,

Dedmon Dai

kvd123 on Thu, 28 Mar 2019 12:03:22


There are no underscores in column names. The names are as in the example shown below:

[Linereversalnumber] to [LineReversalNumber]

[Linenumber] to [LineNumber]

I have fixed the formatting template, so it does not change column names anymore, but don't know how to undo (without manual change) the ones that were already done.

Thanks.

Dedmon Dai on Mon, 01 Apr 2019 07:45:26


You need to manually change the modified changes back.