user3595072
user3595072

Reputation: 57

how to set column property NOT NULL in SQL Server

I need to set my column property to NOT NULL, but I'm not able to set the property it produces the below error..

MY Query:

ALTER TABLE CartReceBenif
ALTER COLUMN RecipientId int NOT NULL;

enter image description here


ERROR

Msg 515, Level 16, State 2, Line 1 Cannot insert the value NULL into column 'RecipientId', table 'test.dbo.CartReceBenif'; column does not allow nulls. UPDATE fails. The statement has been terminated.

Can any one suggest what is the mistake..

Upvotes: 0

Views: 1670

Answers (1)

JRavil
JRavil

Reputation: 48

Possible data present in this table and null values in this column. Try to update table, set values in this column to 1 for example before altering. Or just remove all data from the table before altering.

Upvotes: 3

Related Questions