I have a requirement where we need to modify a column's default value in database table. The table is already an existing table in database and currently the default value of the column is NULL.Now if add a new default value to this column, If I am correct it updates all the existing NULLs of the column to new DEfault value. Is there a way to not to do this but still set a new default value on column.I mean I do not want the existing NULLs to be updated and want them to remain as NULLs.
Any help on this is appreciated.Thanks
raviravi
Simply because at the time that the default values for the new record (item) are set, which is before the user enters any values for any of the columns in the new record, the EventDate column does not yet have a value and is undefined. Therefore, SharePoint cannot use the EventDate column to calculate default value of the Past Due Date column. Use a scalar hashing function in a computed column - non-deterministic? The column is added, but the hash value is exactly the same for each row. Level 16, State 1, Procedure ComputeChecksum, Line 5 Cannot use CHECKSUM(.) in a computed column, constraint, or default definition. It cannot be used directly in a function either.
4 Answers
Your belief about what will happen is not correct. Setting a default value for a column will not affect the existing data in the table.
I create a table with a column
col2
that has no default value
If I then alter the table to set a default value, nothing about the existing rows will change
Even if I subsequently change the default again, there will still be no change to the existing rows
Justin CaveJustin Cave
Pankaj KumarPankaj Kumar
Following Justin's example, the command below works in Postgres:
alter table foo alter column col2 set default 'bar';
amitamit
Prema AryaPrema Arya