How can I prevent a column from allowing null and allowing a column from Null to not allow null

Can someone help me complete the below task.

How can I prevent a column from allowing null and allowing a column from Null to not allow null.

+6
source share
1 answer

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 
+8
source

Source: https://habr.com/ru/post/898357/


All Articles