How to restart sql server 2012 by using SQL

0wi1tuuw  于 2023-11-16  发布在  SQL Server
关注(0)|答案(4)|浏览(115)

Is there any way to restart, start or stop sql server 2012 by executing SQL statement? thanks.

gojuced7

gojuced71#

Actually you can't do this from the SQL statement, but you can perform this with the powershell/cmd

powershell -command "Restart-Service MSSQLSERVER -Force"
km0tfn4u

km0tfn4u2#

You can use xp_cmdshell system procedure to call any command line to stop; however, you definitely can't start it because how will you execute a command using T-SQL while you are not connected (service is stopped)?

8yoxcaq7

8yoxcaq73#

using the command line or powershell .

net start MSSQL$instancename

net stop MSSQL$instance

using SSMS

SHUTDOWN -->wait and shutdown

SHUTDOWN WITH NOWAIT --> dont wait and shutdown

Don't think there is a straight way you can startup in T-SQL, you probably have to do something like this.

z9smfwbn

z9smfwbn4#

You can't directly start or stop SQL Server itself using SQL statements, you can perform tasks related to database management, such as starting, stopping, and restarting individual databases within SQL Server using SQL statements.

相关问题