May 20, 2008 at 2:34 pm
Hi ,
I want to define default constraint for a column to force it to UPPER.
USE [GLP]
GO
ALTER TABLE [dbo].[col1] ADD CONSTRAINT [DF_col1_TypeCode] DEFAULT (N'UPPER(col1)') FOR [col1]. Its defined..
But when I tried ti insert into records..It not convertedto uppecase at all...Isn't it possible this way ?
May 21, 2008 at 12:01 am
Hi
USe this as example... Create a trigger.
CREATE TABLE Customers
(FirstName varchar(30),
MiddleName varchar(10),
LastName varchar(25),
City varchar(10),
Country varchar(2),
CONSTRAINT PK_CustomerName PRIMARY KEY (FirstName,LastName))
CREATE trigger country_upper
ON customers
FOR INSERT, UPDATE
AS
update c
set c.country = UPPER(c.country)
FROM customers c
INNER JOIN INSERTED INS
ON INS.firstname = C.firstname
and INS.lastname = c.lastname
go
Thanks
jaypee.s
May 21, 2008 at 12:27 am
veenagireesha (5/20/2008)
But when I tried ti insert into records..It not convertedto uppecase at all...Isn't it possible this way ?
A default just sets the value of the column if no value is specified in an insert statement. To modify values that are been inserted, you need a trigger
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply