1
我需要一列IsDeleted
添加到表Major
用默認值將是: 真當MajorName像'%Engineering%'
和虛假的人,其不有一句話工程添加表列在SQL Server數據庫中,使默認值與案件
我需要一列IsDeleted
添加到表Major
用默認值將是: 真當MajorName像'%Engineering%'
和虛假的人,其不有一句話工程添加表列在SQL Server數據庫中,使默認值與案件
因爲其添加爲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 |
+------------------------------------+-----------+
要添加列到表:
ALTER TABLE yourtable ADD IsDeleted bit ;
要檢查MajorName並請將isDeleted集TO1或0使用Trigger
需要設置等於返回殼體值 –
@AhmedHossamAlhansy數據類型等於位和缺省值,請檢查編輯答案 –
它的工作正常,但數據類型字段變爲空字段 –