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).
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
Have you considered a computed column instead?. It's not exactly the same thing... but perhaps it is enough for you?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With