2

I've created a table column called RateValue with initially allowing NULL value but I want to make it NOT NULL. I used SQL Server 2008 R2

I tried the following but it does not work

ALTER TABLE dbo.AAElement
ALTER COLUMN RateValue NVARCHAR(50) NOT NULL
MaxiWheat
  • 6,133
  • 6
  • 47
  • 76
Supermode
  • 924
  • 3
  • 32
  • 53

1 Answers1

4

The most likely problem is pre-existing NULL values.

Get rid of the NULL values first, then alter:

UPDATE AAElement 
SET RateValue = ''
WHERE RateValue IS NULL
GO
ALTER TABLE dbo.AAElement
ALTER COLUMN RateValue NVARCHAR(50) NOT NULL

Otherwise the constraint is violated as it's being created.

Hart CO
  • 34,064
  • 6
  • 48
  • 63