Executing set of SQL queries using batch file?

前端 未结 4 914
生来不讨喜
生来不讨喜 2020-11-30 00:55

I am using a SQL Server database. I have these SQL queries:

Delete from TableA;
Delete from TableB;
Delete from TableC;
Delete from TableD;
Delete from Table         


        
4条回答
  •  旧时难觅i
    2020-11-30 01:22

    Use the SQLCMD utility.

    http://technet.microsoft.com/en-us/library/ms162773.aspx

    There is a connect statement that allows you to swing from database server A to server B in the same batch.

    :Connect server_name[\instance_name] [-l timeout] [-U user_name [-P password]] Connects to an instance of SQL Server. Also closes the current connection.

    On the other hand, if you are familiar with PowerShell, you can programmatic do the same.

    http://technet.microsoft.com/en-us/library/cc281954(v=sql.105).aspx

提交回复
热议问题