Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql - Rename all tables and columns to lower case?

I recently transferred a database from a windows box to a linux box. The tables are mixed between lower and upper case names. I need a way to rename all tables and columns to lowercase. Is that possible?

I see in this SO answer it's possible for tables, but have not found anything that deals with column names.

like image 802
jyoseph Avatar asked Feb 23 '11 21:02

jyoseph


People also ask

How do I change to lowercase in MySQL?

The LOWER() function converts a string to lower-case. Note: The LCASE() function is equal to the LOWER() function.

How do you change a column name in lowercase in SQL?

Use the SQL LOWER() function if you want to convert a string column to lowercase. This function takes only one argument: the column whose values you want to lowercase.

Are column names case sensitive MySQL?

Column, index, stored routine, and event names are not case-sensitive on any platform, nor are column aliases. However, names of logfile groups are case-sensitive.


1 Answers

You can try to do exact same thing with Information_Schema.Columns table

EDIT: Something like

SELECT CONCAT('ALTER TABLE ', TABLE_NAME, ' CHANGE `', COLUMN_NAME, '` `',
LOWER(COLUMN_NAME), '` ', COLUMN_TYPE, ';')
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{your schema name}'
like image 100
user194076 Avatar answered Sep 24 '22 15:09

user194076