判断表里某个字段存在不存在

starstargao 2003-08-19 02:23:03
如果不存在就添加那个字段
...全文
461 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjb111 2003-08-19
  • 打赏
  • 举报
回复
if exists(select * from syscolumns where id=object_id('yourtable'))
print '存在'
else
begin
print '不存在'
alter table yourtable add colname 数据类型
end
愉快的登山者 2003-08-19
  • 打赏
  • 举报
回复
if not exists (select * from sysobjects A, syscolumns B where A.id = B.id and B.name = colname and A.name = tablename )
alter table tablename add colname char(10)


愉快的登山者


◢◣◢◣◢◣

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧