Running a local SQL script file from a Windows command prompt to update a remote SQL Server database

I am working with an SQL file that will update data in a remote database. My SQL file is fine. Now you need to run this SQL file from the command line. Is there a way to run this SQL file from the command line or batch file?

I am using SQL Server 2012, and the SQL file is on my local machine.

Someone can help. Thanks in advance.

EDIT

I tried to connect using sqlcmdmy database connection

+4
source share
1 answer

, SQL . sqlcmd. sqlcmd. https://msdn.microsoft.com/en-us/library/ms162773.aspx

EDIT: . :

sqlcmd -e -x -r -b -W -U %user% -S %server% -d %db_name% -P %pass% -i %sqlfile% -r1

%server% serverIP\instancename

2: script :

    Set scriptfile=InsertDB.sql
    Set dbserver=
    set /p dbserver=Database Server :
    Set dbname=
    set /p dbname=Database Name :
    Set usrname=
    set /p usrname=Database Username : 
    Set passw=
    set /p passw=Database Password: 
    set scriptPath=%~dp0
    sqlcmd -e -x -r -b -s"| ", -W -U %usrname% -S %dbserver%  -d %dbname% -P %passw% -i "%scriptPath%%scriptfile%" -r1
    Pause&Exit
+4

Source: https://habr.com/ru/post/1628921/


All Articles