Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i make not allow column to allow null and Allow Null column to not allow null

Could any one help me to perform below task.

How can i make not allow column to allow null and Allow Null column to not allow null.

like image 694
Shine Avatar asked Sep 30 '11 08:09

Shine


1 Answers

Use ALTER TABLE table_name ALTER COLUMN column_name datatype [NOT] NULL

Example:

CREATE TABLE #Foo
(
X INT NULL,
Y INT NOT NULL
)

/*This is metadata only change and very quick*/
ALTER TABLE #Foo ALTER COLUMN Y INT  NULL

/*This requires all rows to be scanned to validate the data*/
ALTER TABLE #Foo ALTER COLUMN X INT NOT NULL
like image 115
Martin Smith Avatar answered Sep 30 '22 12:09

Martin Smith