怎么写呀

解决方案 »

  1.   

    select   *   from   sysobjects   where   xtype   =   'PK'   and   parent_obj   in   (select   id   from   sysobjects   where   name=表名   and   xtype   =   'U')
      

  2.   

      
          if     exists(  
          select   d.name    
          from       syscolumns       a        
          join       sysobjects       b       on       a.id=b.id        
          join       syscomments       c       on       a.cdefault=c.id        
          join       sysobjects       d       on       c.id=d.id        
          where       b.name='表名'            
          and       (a.name='字段名')      
          )
      

  3.   

    1楼的是判断表里面是否存在约束
    如果约束是'FK_HR_SYS_I_REFERENCE_HR_SYS_S'的话 也可以   
    select   *  from   sysobjects   where   name='FK_HR_SYS_I_REFERENCE_HR_SYS_S'   
    假如能打出1表示存在
      

  4.   

    select   *   from   sysobjects   where   xtype   =   'PK'   
    and   parent_obj   in   (select   id   from   sysobjects   where   name=表名   and   xtype   =   'U')
      

  5.   

    if exists(select 1 from sysobjects where id=object_id('[dbo].[UserInfo_ForeignKey_FromSiteID]') and xtype='F')   
    ALTER TABLE [UserInfo] Drop CONSTRAINT UserInfo_ForeignKey_FromSiteID
    好像这样可以