Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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?
Posted
Updated 3-Aug-15 10:06am
v2
Comments
Sergey Alexandrovich Kryukov 3-Aug-15 18:35pm    
Why? This is unnatural constraint.
—SA

1 solution

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:

SQL
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:

SQL
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
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 3-Aug-15 18:35pm    
Inquirer did not mean column name at all.
—SA
Ben J. Boyle 3-Aug-15 18:49pm    
That's the only way I can read the question. Without having a schema to work with I jut used generic names for table and column. What's your interpretation? English is an odd language sometimes and maybe I misinterpreted it.

Odd request either way though!
Sergey Alexandrovich Kryukov 3-Aug-15 21:01pm    
Yes. Read "to store values in lower case only". It's certainly about data and not about metadata. It's very likely that the inquirer has some big misconceptions, but column names are still irrelevant to the request. I would prefer not answering.
—SA
Ben J. Boyle 4-Aug-15 10:26am    
My example wasn't referring to metadata, or at least that wasn't my intent - i just used Tablename and ColumnName because I didn't know the data domain the requester was working in. I've just added a working example based on a table with defined columns, tested on a SQL server database.
Sergey Alexandrovich Kryukov 4-Aug-15 10:55am    
You are not getting it. Column name is metadata, and the value of attribute is data.
The class structure taken as data is metadata, but the particular instance and data it carries is not.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900