I am fairly new to SQL Server and I am running the following command from inside my c# application:
DECLARE @SQLString nvarchar(4000);
SET @SQLString = N'BULK INSERT events FROM '+ QUOTENAME(@p0) +' WITH ( BATCHSIZE = 50000, CODEPAGE = ''65001'', FIELDTERMINATOR = ''|'', ROWTERMINATOR =''\n'' )'
EXECUTE sp_executesql @SQLString
With @p0 being the path to the .csv file.
Right now I am generating a sha1 HashCode as a BigInteger from a combination of 3 columns in my C# code and write it into the csv file into a new column (which is the primary key).
Now I saw it is possible to generate the sha1 hash inside the sql server. Is this possible while bulk inserting?
e.g. Bulk insert csv file. For each row take column X,Y,Z and generate sha1 hash. Convert it to BigInteger and insert it in column P?
EDIT: I am trying the answer from @Nick.McDermaid: But I can't seem to get it working:
CREATE TABLE [dbo].[test] (
[User] [nvarchar](185) NOT NULL,
[Stat] [nvarchar](25) NOT NULL,
[Name] [nvarchar](max) NOT NULL,
[HashByte] AS (convert(bigint, HASHBYTES('SHA1',CONVERT(nvarchar(max),[User]+[Stat]+[Name])))),
CONSTRAINT [PK_dbo.test] PRIMARY KEY ([HashByte]))
I get an Error for incorrect syntax.