How to define a column that can automate capitalizing?

£可爱£侵袭症+ 提交于 2020-01-06 02:52:09

问题


So that when you insert 'abc',it'll be converted to 'ABC' automatically.

I'm using MySQL,is it possible?


回答1:


You could write an INSERT trigger that does this for you.

Something like:

CREATE TRIGGER Capitalize BEFORE INSERT ON MyTable
SET NEW.MyColumn = UPPER(NEW.MyColumn)



回答2:


What about using Upper function while executing query ? lets say You are using a SP to insert the values ... cast the value to upper case using UPPER function and then insert ?




回答3:


this really should be done before it is passed to the DB



来源:https://stackoverflow.com/questions/2056488/how-to-define-a-column-that-can-automate-capitalizing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!