How to execute multiple scripts at once

Michael Mikhail 0 Reputation points
2023-03-15T15:18:54.4533333+00:00

How to execute multiple scripts at once.

If I have arround 10 scripts on my local folder, how can I execute them by one query on three database at once ?

SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-03-16T03:01:51.54+00:00

    Hi @Michael Mikhail

    You can try using sqlcmd.

    Here is a good post that you can learn about.

    https://www.mssqltips.com/sqlservertip/1543/using-sqlcmd-to-execute-multiple-sql-server-scripts/

    For the download of sqlcmd and the syntax rules, you can refer to this official document.

    https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility?redirectedfrom=MSDN&view=sql-server-ver16

    Best regards,

    Percy Tang


    If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".

    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.

    1 person found this answer helpful.
    0 comments No comments

  2. Olaf Helper 47,436 Reputation points
    2023-03-16T07:09:12.8766667+00:00

    Or you can switch SSMS into the SqlCmd mode, to use that scripting to execute SQL scripts stored in files.

    Edit SQLCMD Scripts with Query Editor

    0 comments No comments

Your answer

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