我需要添加一列IsDeleted
到表Major
中,默认值为:
在其他没有单词工程的单词中,majorname如'%Engineering%'
和false是真的
最佳答案
将其添加为computed column(也称为虚拟列)
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 |
+------------------------------------+-----------+