Reputation: 65
I want to create a foreign key between two database. Happens that the tables have data, so when I'm making the foreign relational there's giving me error.
I found the error happen when your tables have data. So how to not verify existing data?
ALTER TABLE [contrato_sigob].[relacion_institucion_categoria]
ADD CONSTRAINT CHECK_CATEGORIA
CHECK([dbo].[func_CHECK_CATEGORIA](id_categoria)=1);
The error says:
The ALTER TABLE statement conflicted with the CHECK constraint "CHECK_CATEGORIA". The conflict occurred in database "SIGOB_Contraloria", table "contrato_sigob.relacion_institucion_categoria", column 'id_categoria'.
Upvotes: 3
Views: 4024
Reputation: 31785
So how to not verify existing data?
You can create a constraint that will not check your existing records by adding WITH NOCHECK:
ALTER TABLE TABLE_NAME WITH NOCHECK
ADD CONSTRAINT ...
Upvotes: 6