Does sqlcmd have block insertion?

JORYSNIEL MATA NUÑEZ 0 Reputation points
2025-10-22T14:48:38.8733333+00:00

First of all, Hello everyone! The problem is i started using sql server on other operative system than windows. I have followed almost all of the article in the documentation.

  1. Installed docker
  2. Installed sql cmd
  3. Installed the image
  4. Ran the commands as explained in the documentation. Everything is fine except for the unavailability of block insertion of pasted code in the interactive sqlcmd.

I do not exactly if this is possible or not, but the fact is: I could not find a way to make that happen.

Therefore, this "Draft" was made to ask How can i paste blocks of code in iteractive sqlcmd and if it is not possible, then i suggest that there should exist one.

SQL Server Integration Services
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 127.4K Reputation points MVP Volunteer Moderator
    2025-10-22T21:03:30.1566667+00:00

    I put a random script of almost 400 lines on the clipboard, then I started SQLCMD. At the 1> prompt, I pasted in my block, and it seemed to work. I tested both with the old classic SQLCMD and the newer go-SQLCMD. This was on Windows; it seems from your post that you are on a different operating system. Maybe it is the OS that prevents pasting the way you want it? Or am I misunderstanding what you are trying to do.

    In any case, if I would like to run a longer piece of code from SQLCMD, I would rather use the -i option to read it from a file. Or, if I have already started SQLCMD, I would use the :r command.

    0 comments No comments

  2. Akhil Gajavelly 645 Reputation points Microsoft External Staff Moderator
    2025-10-23T09:11:17.0633333+00:00

    Hi @JORYSNIEL MATA NUÑEZ,

    The behavior you’re seeing is mostly due to differences between operating systems. Here’s a breakdown.

    1. Direct block paste at the 1> prompt On Windows, pasting a large block often works fine in sqlcmd. On Linux/macOS, terminal handling can prevent large block pastes from working correctly, which is why you’re seeing this issue. So this method may not be reliable on your OS.
    2. Recommended approach (works on any OS)

    Using a script file with -i: sqlcmd -S <server> -U <user> -P <password> -i script.sql This will execute all commands in script.sql reliably.

    Using :r in interactive mode: Start sqlcmd and at the prompt, run:

    :r /path/to/script.sql

    This includes and runs the script file within the interactive session.

    Thanks,
    Akhil.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.