How to Start and Stop database ?

  • I need to restart a database through SQL statement.

    What is the SQL statement which I can use for this purpose. I am planning to execute this in SQL Query Analyzer.

    Thanks

    Krishna:

  • What exactly do you mean by restart a database? Do you mean to kill all current connections to leave it "clean"? Detach a database and reattach it? Set the database offline and then online again? Or to restart an entire instance?

    What are you looking to accomplish?



    Shamless self promotion - read my blog http://sirsql.net

  • I was trying to schedule for a restore of my database. Before that I am stopping connections to the database from Web server. When I am executing the SQL for Restore, it is failing due to the database connections are not refreshed. when I restarted the database manually and Restored it is working. So, I need SQL statement for Restarting the database through query.

    I hope you have understood my requirement.

    Thanks,

    Krishna

  • I was trying to schedule for a restore of my database. Before that I am stopping connections to the database from Web server. When I am executing the SQL for Restore, it is failing due to the database connections are not refreshed. when I restarted the database manually and Restored it is working. So, I need SQL statement for Restarting the database through query.

    I hope you have understood my requirement.

    Thanks,

    Krishna

  • Rather than restarting you would be better served by setting the database into single user mode before attempting the restore and then resetting it back to multi user mode afterwards...

    --Before the restore

    USE master

    GO

    ALTER DATABASE

    SET SINGLE_USER

    --After the restore

    USE master

    GO

    ALTER DATABASE

    SET MULTI_USER



    Shamless self promotion - read my blog http://sirsql.net

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply