Search code examples
sql-servernode.jsnode-mssqlexceljs

Import CSV rows with 2000 records from node into SQL Server


I am using exceljs (https://www.npmjs.com/package/exceljs) node package to read excel file.

I am looking for fast import csv with 2000 records into SQL Server.

Table:

User [Id PK]
Role [UserId FK]
Unit [UserId FK]

Excel file:

UserName Role  Unit 
Jack      1    Unit1 

Solution

  • @Furqan, did you try executing BULK INSERT command to import CSV file contents into SQL Server database table

    Here is sample target table

    create table UploadTable (
        [User] varchar(100),
        [Role] varchar(100),
        Unit varchar(100)
    )
    

    After you create your table try following SQL command

    BULK INSERT UploadTable FROM 'c:\kodyaz\upload.csv'
    WITH
    (
    FIELDTERMINATOR = ',',
    ROWTERMINATOR = '0x0A'
    )