想用代码增加一个字段...

小智老师 2002-12-04 04:21:18
想用代码增加一个字段
alter table clerk_GroupUser add Clerk_Id int NULL
如何在增加之前判断这个字段有没有存在呢?
用程序我会,我想通过SQL脚本实现。
...全文
36 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝天 2002-12-04
  • 打赏
  • 举报
回复
if not exists (select 1 from syscolumns where name ='Clerk_Id' and id =object_id ('clerk_GroupUser')

alter table clerk_GroupUser add Clerk_Id int NULL

CrazyFor 2002-12-04
  • 打赏
  • 举报
回复
if (
select count(*) from syscolumns where name='Clerk_id' and id=object_id('Clerk_GroupUser')
)>0
begin
print '已存在!'
End
Chiff 2002-12-04
  • 打赏
  • 举报
回复
select * from syscolumns where id = object_id(表名) and name = 字段名

34,594

社区成员

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

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