Welcome to Sign in | Help
in Search

disable/enable foreign keys constraints

Last post 03-25-2009, 5:58 PM by rsocol. 2 replies.
Sort Posts: Previous Next
  •  03-25-2009, 5:09 PM 6957

    disable/enable foreign keys constraints

    salut.
    incerc sa copiez datele de pe o baza pe alta si nu stiu in ce ordine trebuie copiate tabelele. de aceea caut o metoda pentru a dezactiva foreign key-urile temporar, pentru cat inserez datele in tabela. aveti vreo idee cum se face?
  •  03-25-2009, 5:18 PM 6958 in reply to 6957

    Re: disable/enable foreign keys constraints

    Se poate face cu un cursor (folosind numele tabelelor) sau daca este vorba de SQL Server 2000 folosind urmatorul cod:
    exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'

    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  03-25-2009, 5:58 PM 6959 in reply to 6958

    Re: disable/enable foreign keys constraints

    Nu uita ca atunci când termini să-i dai:

    exec sp_MSforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL' 

    Clauza WITH CHECK este utilă pentru a face constraint-urile să fie din nou "trusted".

    Răzvan

View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems