Table conatins constraints

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.

Peter Schmitz

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:


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

[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]

Turn it back on after you're done by using this:

[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!