Lowercase Limit - Sql Server

I’m not sure if this should be a limitation or not, but I want the “UserName” column of the table to ignore the value set when performing the insert or update, instead save the “DisplayUserName” value converted to lowercase. And if "DisplayUserName" is changed, "UserName" should also be updated to "DisplayUserName".

Thanks!

+3
source share
3 answers

A common way to do this is to use a trigger that fires when you insert and update.

http://msdn.microsoft.com/en-us/magazine/cc164047.aspx

The trigger code should look something like this:

CREATE TRIGGER updateDisplayName_trigger ON Users
FOR INSERT, UPDATE  
AS
IF UPDATE(UserName)
UPDATE Users SET DisplayUserName = Lower(UserName)

-, , =)

+1

, . - :

CREATE TABLE [dbo].[SampleTable](
    [ID] [int] IDENTITY(1, 1) NOT NULL,
    [DisplayUserName] [varchar](100) NOT NULL,
    [UserName]  AS (lower([DisplayUserName]))
) ON [PRIMARY]

, UserName, DisplayUserName.

+5

You will need to create a trigger to handle the update.

+1
source

Source: https://habr.com/ru/post/1704621/


All Articles