2016-12-03 45 views

回答

3

因爲其添加爲computed column(AKA虛擬列)

alter table Major add IsDeleted as 
    cast (case when MajorName like '%Engineering%' then 1 else 0 end as bit) 

演示

create table Major (MajorName varchar (100)) 

alter table Major add IsDeleted as 
    cast (case when MajorName like '%Engineering%' then 1 else 0 end as bit) 

insert into Major (MajorName) values 
    ('This is the Engineering department'),('Hello world') 

select * from Major 

+------------------------------------+-----------+ 
| MajorName       | IsDeleted | 
+------------------------------------+-----------+ 
| This is the Engineering department | 1   | 
+------------------------------------+-----------+ 
| Hello world      | 0   | 
+------------------------------------+-----------+ 
+0

需要設置等於返回殼體值 –

+0

@AhmedHossamAlhansy數據類型等於位和缺省值,請檢查編輯答案 –

+0

它的工作正常,但數據類型字段變爲空字段 –

0

要添加列到表:

ALTER TABLE yourtable ADD IsDeleted bit ; 

要檢查MajorName並請將isDeleted集TO1或0使用Trigger

相關問題