sqlcmd breaks input INSERT string

Jan Vávra 231 Reputation points
2021-01-28T07:27:58.143+00:00

I have a 4 GB import file with INSERT statements, after importing 2004699 records the sqlcmd fails with a message
Incorrect syntax near '5'.

If I add the -e option I can see that sqlcmd stopped reading until the end of insert statement.

INSERT ...shorthened ... , CAST(N'2013-10-15T11:46:34.620' AS DateTime), N'', 0, 2, 554803, NULL)
INSERT ... shorthened ... , CAST(N'2013-10-15T11:46:34.620' AS DateTime), N'', 0, 2, 5

In the import file each insert stament is physically on 2 lines.
I've tried once sqlcmd and Sql Server 2014, on another computer sqlcmd and Sql Server 2016 and aslo the latest sqlcmd C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\SQLCMD.EXE and Sql Server 2016.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,734 questions
{count} votes

Accepted answer
  1. AmeliaGu-MSFT 13,961 Reputation points Microsoft Vendor
    2021-01-29T08:07:57.86+00:00

    Hi JanVavra,

    It seems there is a 2GB file size limit using sqlcmd. Please refer to this feedback.
    To insert large data, could you please use BULK INSERT statement or BCP utility?
    Or you can break the script file into multiple files, and then use sqlcmd to run them continuously as Viorel mentioned.
    Please refer to bcp Utility and BULK INSERT which might help.
    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jan Vávra 231 Reputation points
    2021-01-29T08:39:50.33+00:00

    Well, we've got the data from the customer so I cannot use bcp.
    I've not found an utility that splits file per rows, Linux split command doesn't work properly with UTF-16LE. I've written my custom split in php ;-)

    Definitely this is a MS bug.
    Thanks.