If exists(select * from dbo.sysobjects where name='xxxx' and type='D')
    ALTER TABLE xxxxxx
         DROP CONSTRAINT DF_xxxxxxxALTER TABLE [dbo].[xxxxx] WITH NOCHECK ADD 
CONSTRAINT [DF_xxxxxx] DEFAULT (xxxxx) FOR [xxxxx]

解决方案 »

  1.   


    if exists (select * from sysdepends where depid=object_id('AA') and id=object_id('BB'))
    begin
    alter table AA drop constraint BB
    alter table dbo.AA add constraint CC 约束条件
    end
      

  2.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
    ALTER TABLE [dbo].[AA] DROP CONSTRAINT BBALTER TABLE [dbo].[AA] ADD  CONSTRAINT [CC] FOREIGN KEY