向表中添加字段,前提是不知道该表是否存在alter table tb add column int(4) not null if exists 'tb';这样对吗?

解决方案 »

  1.   


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

  2.   

    if exists(select * from sys.tables where name='t') select '存在'
      

  3.   

    if object_id('tb','u') is not null
    alter table tb add column int not null --不需要那个4
      

  4.   

    if object_id('tb') is not null
    alter table tb add column int not null --不需要那个4
      

  5.   

    怎么提示function object_id does not exist?
      

  6.   

    系统函数,你用的是sql server 不?
      

  7.   

    添加的字段之前是不存在那张表的,其实就是出个补丁,要添加字段,要兼容考虑安装程序,要不然我就直接drop那张表,在create了。。
      

  8.   


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

  9.   

    if OBJECT_ID('表名')is not null