1

I need to save data into a MySQL column, let's assume the column name is "first_name". So how can I save the data in Uppercase by default?

Is there any way where I can set the column value to default to uppercase, so every time a data inserted from any script it will save in uppercase automatically.

Martin
  • 22,212
  • 11
  • 70
  • 132
Hemant
  • 11
  • 3
  • mysql is the database. Mysqli is an API to connect to a mysql database using php – Lelio Faieta May 02 '19 at 07:48
  • Please refer this link https://stackoverflow.com/questions/4263272/capitalize-first-letter-mysql – Siva May 02 '19 at 07:51
  • Hello @Siva, Thanx for the reply but I need to save it from the database only. Is there any way where I can set the column to default uppercase, so every time a data inserted from any script it will save in uppercase automatically – Hemant May 02 '19 at 07:57
  • What do yu mean by all that? Uppercase all inserted values on inserting? Why not do that in your application? – Nico Haase May 02 '19 at 08:04
  • Hello @Nico Haase, My concern is to make database column work as default to save data in uppercase whether it is saved in lowercase. – Hemant May 02 '19 at 08:14
  • Have you tried using https://stackoverflow.com/questions/12795021/mysql-automatic-conversion-on-lowercase? – Nico Haase May 02 '19 at 08:15
  • For example, we can set a column default value to anything, just like that can we set anything in the database that takes values in uppercase. – Hemant May 02 '19 at 08:15

1 Answers1

1

use UPPER() function in times of selection you dont need to push uppercase in db

select UPPER(first_name) from table_name

if you need intimes of insert then use same function intime of insert

 INSERT INTO table_name (first_name)
 VALUES (  upper( 'name_first' ) )

Though i prefer conversion in times of selection

Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
  • Hello @Zaynul, Thanx for the reply but I need to save it from the database only. Is there any way where I can set the column to default **uppercase**, so every time a data inserted from any script it will save in uppercase automatically. – Hemant May 02 '19 at 07:57