用MS SQL 语句修改表中字段类型
生活随笔
收集整理的這篇文章主要介紹了
用MS SQL 语句修改表中字段类型
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
【問題】用SQL 語(yǔ)句判斷表中是否存在password字段,不存在則新增字段,若存在password字段,把字段的類型由int 類型改為text類型。
【實(shí)現(xiàn)方法】
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轉(zhuǎn)化為varchar
?? alter table tb_userinfo? alter column [password] text--再把varchar轉(zhuǎn)化為text
??? print 'Had upate Email Colums!'
? end
else
?begin
??? ALTER TABLE tb_userinfo ADD [password] int? NULL
??? print 'Had Add colums!'
?end
【實(shí)現(xiàn)方法】
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轉(zhuǎn)化為varchar
?? alter table tb_userinfo? alter column [password] text--再把varchar轉(zhuǎn)化為text
??? print 'Had upate Email Colums!'
? end
else
?begin
??? ALTER TABLE tb_userinfo ADD [password] int? NULL
??? print 'Had Add colums!'
?end
總結(jié)
以上是生活随笔為你收集整理的用MS SQL 语句修改表中字段类型的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DIV与Table布局在大型网站的可用性
- 下一篇: 菜鸟玩基金(四)——注意事项