Search code examples
sql-server-2005default-valuecalculated-columnsnon-nullable

How to make computed column not nullable?


So far I've been using ISNULL(dbo.fn_GetPrice(ItemId), 0) to make it not nullable (rather call it default-valued, but whatever).

Is this the right way?


Solution

  • Yes, that is the right way to do it. By using the isnull function you are creating an expression that must return a value, no matter what. This is evaluated by SQL Server to be a computed column that is not null.