Default column value based on the value of a different column

sql, sql-server, sql-server-2005

Solution

if your ColumnB can only be 15 or zero, you can make it a computed column based on ColumnA. here is the code to add a new computed column:

ALTER TABLE YourTable ADD YourComputedColumn AS ColumnA*15
go

Problem

SQL Server 2005. I have a table with ColumnA bit, ColumnB int Can I add a default value to `ColumnB` so that `ColumnB` is 15 if `ColumnA` is 1 and `ColumnB` is 0 if `ColumnA` is 0? I know I could do this with a trigger but I my boss is prejudice against triggers (he needs trigger sensitivity training).

Original source