Execute SQL script from command line

后端 未结 4 1042
一向
一向 2020-12-23 09:02

I need to alter a database using a batch file, for a simple example, drop a table. I´m using local SQL Express (SQL Server 2008 R2) with user sa and its passwor

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 09:30

    Take a look at the sqlcmd utility. It allows you to execute SQL from the command line.

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

    It's all in there in the documentation, but the syntax should look something like this:

    sqlcmd -U myLogin -P myPassword -S MyServerName -d MyDatabaseName 
        -Q "DROP TABLE MyTable"
    

提交回复
热议问题