Welcome to MSSQL Forum!
MSSQL Forum - Discussions about Microsoft SQL Server

You are currently viewing our community forums as a guest user. Sign up or
Having an account grants you additional privileges, such as creating and participating in discussions.

Table conatins constraints

Discussion in 'Database Design and Database Objects' started by Venkateshwar Reddy, Feb 14, 2013.

  1. Venkateshwar Reddy

    Venkateshwar Reddy New Member

    I need help in inserting table records which contains primary and foreign key's.

    is there any way to update records with out droping constaints.
    tried in below ways:
    1. Exported data from Excel - failed to do getting error.
    2. Manually insterd using query - Failed.
  2. Peter Schmitz

    Peter Schmitz Administrator Staff Member

    It should not be an issue inserting foreign key IDs, unless of course the referenced ID does not exist.

    If the Primary key is an IDENTITY column, and you know for sure that the values you are inserting do not conflict with the existing values in the table (for instance because the records to be inserted have been deleted in the table), you can use SET IDENTITY INSERT:

    Code (TSQL):

    It's possible to temporarily disable a key by using the following:

    Code (TSQL):

    [SIZE=2][FONT=Courier New][COLOR=blue]ALTER[/COLOR] [COLOR=blue]INDEX[/COLOR] <myKey> [COLOR=blue]ON[/COLOR] [COLOR=maroon]<myTable>[/COLOR] [COLOR=blue]DISABLE[/COLOR]
    [COLOR=blue]GO[/COLOR] [/FONT][/SIZE]
    Turn it back on after you're done by using this:

    Code (TSQL):

    [SIZE=2][FONT=Courier New][COLOR=blue]ALTER[/COLOR] [COLOR=blue]INDEX[/COLOR] [COLOR=blue]ALL[/COLOR] [COLOR=blue]ON[/COLOR] [COLOR=maroon]<myTable>[/COLOR] [COLOR=maroon]rebuild[/COLOR] [/FONT][/SIZE]
    Keep in mind this might yield error messages in case of duplicate entry numbers.

    Hope this helps!

Share This Page