sql if conditons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rvvvprasad
    New Member
    • Nov 2011
    • 2

    sql if conditons

    can any one explain what below code means

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ht_litigatio n_ht_mast]') and OBJECTPROPERTY( id, N'IsForeignKey' ) = 1)
    ALTER TABLE [dbo].[ht_litigation] DROP CONSTRAINT FK_ht_litigatio n_ht_mast
    GO

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ht_mutation_ Ht_mast]') and OBJECTPROPERTY( id, N'IsForeignKey' ) = 1)
    ALTER TABLE [dbo].[ht_mutation] DROP CONSTRAINT FK_ht_mutation_ Ht_mast
    GO

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Ht_tran_Ht_m ast]') and OBJECTPROPERTY( id, N'IsForeignKey' ) = 1)
    ALTER TABLE [dbo].[Ht_tran] DROP CONSTRAINT FK_Ht_tran_Ht_m ast
    GO

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Ht_mast]') and OBJECTPROPERTY( id, N'IsUserTable') = 1)
    drop table [dbo].[Ht_mast]
    GO
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    If there is a foreign key constraint on those first 3 tables, it drops the constraint. If the last table is a user table, it drops the table.

    Comment

    Working...