SQL Server: ALTER with ADD new column
Use the WITH VALUES
clause
ALTER TABLE [dbo].[TruckTbl] ADD [TruckState] [bit] NULL DEFAULT 0 WITH VALUES;
Although I do agree with the other answer it seems odd that the column should be nullable at all if you are setting all existing rows to 0
and have a default for future inserts. Do you ever need to allow NULL
as a column value here?
ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}[WITH VALUES]
E.g
ALTER TABLE TempADD ID int NOT NULL DEFAULT(1)