0

How to make a NULLABLE column to NOT NULL in SQL SERVER. I made a table with four columns:

My table:

id int null
fname varchar not null
last name not null
contact int null.

Now what i am required is to make id column to be not null.So please help me how we can make a null column to be a not null column.

2
  • Are all current ID values not null? Commented Aug 30, 2013 at 9:20
  • yes.The values in the column are not null. Commented Sep 2, 2013 at 6:34

3 Answers 3

1

Use the following statements to do it. Change the name of column id as required

UPDATE [Table] SET id=0 WHERE id IS NULL;
ALTER TABLE [Table] ALTER COLUMN id INTEGER NOT NULL;

Replace [Table] with the name of the table

Sign up to request clarification or add additional context in comments.

Comments

1

first Update id Column '0'(Zero) where NULL then right Click on table then select Design and uncheck Allow Nulls checkbox of your Column from sql table design.

Comments

0
ALTER TABLE tableName

ALTER COLUMN columnName nvarchar(200) [NULL|NOT NULL]

1 Comment

this won't change the id column at all. How does it answer your question?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.