How can I insert data that contains an underscore in a foreign key field? E.g. This works:
INSERT INTO [childTable] (1, 'ABC')
But this doesn't work:
INSERT INTO [childTable] (1, '_ABC')
as it gets this error:
"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_childTable_parentTable". The conflict occurred in database "X", table "parentTable", column 'SomeField'".
where we have two tables related by a foreign key:
CREATE TABLE parentTable (
Id int,
SomeField [char] (4)
)
CREATE TABLE childTable (
SomeField [char] (4)
)
ALTER TABLE childTable CONSTRAINT FK_childTable_parentTable
FOREIGN KEY SomeField
REFERENCES parentTable (SomeField)
and where the parentTable definitely contains a record with the '_ABC' data.
If I temporarily remove or disable the foreign key constraint, I can insert the records OK and restore the foreign key OK, but is there a way to escape the underscore or some other better solution?
Environment: SQL Server Management Studio against a Microsoft SQL Server 2008 R2 server and database with the collation order set to Latin1_General_BIN.