【问题】用SQL 语句判断表中是否存在password字段,不存在则新增字段,若存在password字段,把字段的类型由int 类型改为text类型。

【实现方法】
if exists( select name from syscolumns  where  id=object_id('tb_userinfo') and name='password')  
  begin    
   alter table tb_userinfo  alter column [password] varchar(50)--先把int转化为varchar
   alter table tb_userinfo  alter column [password] text--再把varchar转化为text
    print 'Had upate Email Colums!'
  end
else
 begin
    ALTER TABLE tb_userinfo ADD [password] int  NULL
    print 'Had Add colums!'
 end

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2021-07-24
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-21
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案