Created
April 29, 2014 02:43
-
-
Save sankars/11389547 to your computer and use it in GitHub Desktop.
SQL Server administrative tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- From http://dba.stackexchange.com/questions/6031/how-do-you-kick-users-out-of-a-sql-server-2008-database | |
| -- hit Ctrl+Shift+M in SSMS to fill in the template parameter | |
| USE master; | |
| GO | |
| ALTER DATABASE N'<Database Name, sysname,>' | |
| SET SINGLE_USER | |
| WITH ROLLBACK IMMEDIATE; | |
| GO | |
| ALTER DATABASE N'<Database Name, sysname,>' | |
| SET READ_ONLY; | |
| GO | |
| ALTER DATABASE N'<Database Name, sysname,>' | |
| SET MULTI_USER; | |
| GO | |
| USE master; -- get out of dbname myself | |
| GO | |
| -- kick all other users out: | |
| ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; | |
| GO | |
| -- prevent sessions from re-establishing connection: | |
| ALTER DATABASE [dbname] SET OFFLINE; | |
| -- do the work | |
| ALTER DATABASE [dbname] SET ONLINE; | |
| ALTER DATABASE [dbname] SET MULTI_USER; | |
| -- Network details aobout the server | |
| -- http://stackoverflow.com/questions/142142/sql-query-to-get-servers-ip-address | |
| SELECT | |
| CONNECTIONPROPERTY('net_transport') AS net_transport, | |
| CONNECTIONPROPERTY('protocol_type') AS protocol_type, | |
| CONNECTIONPROPERTY('auth_scheme') AS auth_scheme, | |
| CONNECTIONPROPERTY('local_net_address') AS local_net_address, | |
| CONNECTIONPROPERTY('local_tcp_port') AS local_tcp_port, | |
| CONNECTIONPROPERTY('client_net_address') AS client_net_address | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment