Is it possible to add comments to the non-XML bcp/BULK INSERT format files?
This would be very helpful in scenarios where these files are treated as declarative code--because, well, code needs comments.
Haven't tried anything yet, because I'd just be throwing random chars with possible unforeseen after-effects.
A definitive "no" would be an acceptable answer.
I think the closest to a definitive negative answer is the fact that there is neither a single mention of comments in the documentation nor any examples. I guess there is a specification somewhere in the archives at Microsoft, but it doesn't seem to be available online.
The clearest definition of the non-xml format I've seen is this image (taken from Structure of Non-XML Format Files):

For me that is proof enough that comments are not a part of the format and the answer to your question is NO.
As pointed out in the comment by Katherine Elizabeth Lightsey using the newer XML-based format files might be a better, more flexible option, with the added bonus that the XML-format is pretty much self-describing.
Not allowing comments in the format file is only the 47th most miserable thing about bcp.
I needed this too, and as my workflow was already using a wrapper script, a small bit of PowerShell easily filters the documented format file into a temporary one that bcp would accept:
...
Get-Content $commentedformatfile |
Where-Object { -Not $_.StartsWith("#") } |
Set-Content "_temp.fmt"
...
bcp ... -f _temp.fmt ...
This simple mechanism only supports comments via a # character at the start of a line, but it was entirely suitable for me.
Note that bcp barfs on even a blank line so you still have to pay attention.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With