Alter NVARCHAR column from NULL to NOT NULL in sql server
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
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.
链接地址: http://www.djcxy.com/p/76278.html上一篇: SQL。 更改要求重新创建表