如何在设计时设置列的区分大小写? [英] How to set the case sensitivity of a column in design time?

查看:81
本文介绍了如何在设计时设置列的区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Sql Server Management Studio,在创建/修改表时,我想指定其中一个列,以仅以小写形式存储值。它可以通过设计师或其他方式完成吗?

解决方案

您可能需要使用触发器将文本更改为小写,因为没有在列上指明您希望值存储在较低位置的方式:



  CREATE   TRIGGER  TriggerName  ON  TableName 
FOR INSERT 更新
AS
IF 更新(ColumnName)
UPDATE TableName SET ColumnName = Lower(ColumnName)





为了澄清,使用更真实的表名和列名示例:



  ALTER   TRIGGER  trg_lowercaseEmployeeId  ON 员工
FOR INSERT 更新
AS
IF 更新(employeeId)
BEGIN
更新 e SET e.employeeID = Lower(e.employeeID)
FROM 员工e INNER JOIN 插入i ON (i.ID = e.ID)
END


With Sql Server Management Studio, while creating/modifying a table I want to specify one of its columns to store values in lower case only. Can it be done through the designer or by some other means?

解决方案

You're probably going to need to use a trigger to change the text to lowercase as there's no way to indicate on a column that you want values stored in lower:

CREATE TRIGGER TriggerName ON TableName
FOR INSERT, UPDATE
AS
IF UPDATE(ColumnName)
UPDATE TableName SET ColumnName = Lower(ColumnName)



To clarify, using a more real world example for table and column names:

ALTER TRIGGER trg_lowercaseEmployeeId ON Employee
FOR INSERT, UPDATE
AS
IF UPDATE(employeeId)
BEGIN
	UPDATE e SET e.employeeID=Lower(e.employeeID)
	FROM Employee e  INNER JOIN inserted i ON (i.ID=e.ID)
END


这篇关于如何在设计时设置列的区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆