How to load a file into a field in SQL Server
If you need a large file imported into a table record, it is possible to do it with SQL rather than having to write a C# or equivalent program to do so. You can use it for a variety of different field types, for us, we're going to use XML.
Create table ExXML (Id int identity(1,1), FXML XML)
Insert into ExXML(FXML)
Select BulkColumn FROM Openrowset( Bulk 'C:\example.xml', Single_Blob) as FileXML
Select * from EXXml
Its that simple. If you want to experiment, you can download a sitemap from a site, save it as example.xml and it'll work. The file will need to be on the server machine otherwise it won't work. If not a server, a common network location.
Last Modified : June 2023