34,588
社区成员
发帖
与我相关
我的任务
分享
create table stuSex(id tinyint,stuSex nvarchar(1))
insert stuSex select 1,'男'
insert stuSex select 0,'女'
select ...,b.stuSex,... from stuInfo a inner join stuSex b on a.stuSex=b.id
begin transaction
alter table stuinfo alter column stuSex char(2)
go
update stuinfo set sex=case stuSex when '1' then '男' when '0' then '女' end
go
alter table stuinfo add constraint ct_sex check(stuSex in('男' ,'女'))
go
if @@error<>0
rollback
else
commit