SQL Server 2005. I have a table with the ColumnA bit, ColumnB int
Can I add a default value to ColumnB, so it ColumnBis 15 if it ColumnAis 1 and ColumnB0 if it ColumnAis 0?
ColumnB
ColumnA
I know that I could do this with a trigger, but I, my boss, was biased towards the triggers (he needs to train the sensitivity to fire).
if your column B 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
- , , . - , . , /.
, - , ? , .
? ... , , ?
, , . , , , . , , ColumnB .
. , ( ) . , , , . , "" , . .
http://msdn.microsoft.com/en-us/library/ms191250.aspx
:
alter table yourTABLe add ColumnB as case when coalesce(ColumnA,0) = 15 then 0 else 1 end go
Source: https://habr.com/ru/post/1732913/More articles:Distributing sharepoint default.master? - sharepointWhy does the Moose role application with method modifiers not work in my code? - perlFor general cases, when one of them will work, which is better to use, a hash map or a hash table? - javaPassing utf-8 strings between php and javascript - javascriptHow to display dependency conflicts in 'mvn site' - maven-2C ++ - What libraries or command line programs will I need to create a program that takes an AVI file and burns it to a DVD? - c ++How can I make a rich web application in Perl? - user-interfaceThe class name for the unix-like permission object is javaHow to copy an object that is inherited from an im object trying to copy? - c #Is there any need to use WS2_32.dll instead of wsock32.dll when creating using MSVC9.0 - visual-c ++All Articles