Last active
August 17, 2023 12:59
-
-
Save Vladimir-Novick/7babd786e5537241a320b12eaf340ac3 to your computer and use it in GitHub Desktop.
Upload file to SQL server into varbynary(max) using SQL Server function OPENROWSET and BULK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE myTable(FileName nvarchar(60), | |
FileType nvarchar(60), Document varbinary(max)) | |
INSERT INTO myTable(FileName, FileType, Document) | |
SELECT 'ConnectionManager.pdb' AS FileName, | |
'.pdb' AS FileType, | |
* FROM OPENROWSET(BULK N'D:\TEST\BIN\ConnectionManager.pdb', SINGLE_BLOB) AS Document |
The VARBINARY(MAX) field allocates variable length data up to just under 2GB in size.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use DATALENGTH() function to determine the length of the column content:
select DATALENGTH(Document),Document from myTable where FileName='ConnectionManager.pdb'