NULL vs Default value in SQL Server database

Are there any consequences for using default values, such as empty rows, when inserting rows into the database. The problem is with the use of zeros, which they must check when using data in the application, while the default value can be processed much easier.

+3
source share
6 answers

The NULL value in the database must be reserved for "unknown" that does not match the empty one. Therefore, as long as the default values ​​you use reflect the nature of the underlying data (that is, they are not "unknown"), I would recommend using the default values.

. . -, :)

+5

. null - , . , . , , . , " ". varchar, , , ( , , , , .) null , , , , , , . . :

select count(myfield), myfield2 from mytable group by myfield2

, , .

+6

, , , .

, . . 0, - NULL. NULL , , 0 , - - .

NULL , FK.

+2

, , , SQL- , , , , .

0

. . , , ..

NULL ('') , COLUMN NULL COLUMN = ''. COLUMN = NULL , COLUMN NULL, NULL NULL, , IS NULL-.

, NULL , , NULL, NULL. NULL , , .

- , . , NULL . , , , .

0

, .

, ,

  • . "" , , / , ​​/.
  • used in some modules (web page / wind forms, etc.). For example, a quick registration form accepts only the desired identifier / username, email address and password.
  • if you are not too lazy to manually fill in the test data. I find that laziness of developers is that disks in most cases have an unnecessary DEFAULT column.
0
source

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


All Articles