求助

ccnufeng 2011-10-27 05:40:40
向表中添加字段,前提是不知道该表是否存在

alter table tb add column int(4) not null if exists 'tb';

这样对吗?
...全文
108 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
q465897859 2011-10-28
  • 打赏
  • 举报
回复
if OBJECT_ID('表名')is not null 
pengxuan 2011-10-28
  • 打赏
  • 举报
回复

if object_id('tb','U') is not null
alter table tb add column int(4) not null
ccnufeng 2011-10-28
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 rfq 的回复:]
你还判断表中是否已经有这个字段了
有 提示
没有 添加
[/Quote]
添加的字段之前是不存在那张表的,其实就是出个补丁,要添加字段,要兼容考虑安装程序,要不然我就直接drop那张表,在create了。。
rfq 2011-10-28
  • 打赏
  • 举报
回复
你还判断表中是否已经有这个字段了
有 提示
没有 添加
ccnufeng 2011-10-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 fanzhouqi 的回复:]
引用 5 楼 ccnufeng 的回复:

怎么提示function object_id does not exist?
系统函数,你用的是sql server 不?
[/Quote]
Mysql不行吗?
ccnufeng 2011-10-28
  • 打赏
  • 举报
回复
用的是 mysql 啊
fanzhouqi 2011-10-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ccnufeng 的回复:]

怎么提示function object_id does not exist?
[/Quote]系统函数,你用的是sql server 不?
ccnufeng 2011-10-28
  • 打赏
  • 举报
回复
怎么提示function object_id does not exist?
--小F-- 2011-10-27
  • 打赏
  • 举报
回复
if object_id('tb') is not null
alter table tb add column int not null --不需要那个4
--小F-- 2011-10-27
  • 打赏
  • 举报
回复
if object_id('tb','u') is not null
alter table tb add column int not null --不需要那个4
gw6328 2011-10-27
  • 打赏
  • 举报
回复
if exists(select * from sys.tables where name='t') select '存在'
DataBox-MDX 2011-10-27
  • 打赏
  • 举报
回复

if object_id('tb','u') is not null
alter table tb add column int(4) not null

34,594

社区成员

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

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