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
| begin try | |
| print 'restore database [PoorDB]' | |
| restore database [PoorDB] | |
| from disk = N'E:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\PoorDB.bak' | |
| with replace, recovery; | |
| print 'alter database PoorDB set online with rollback immediate;' | |
| alter database PoorDB set online with rollback immediate; |
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
| -- originally written in help on Stack Overflow | |
| -- Credit to Matthew Haugen http://goo.gl/0SJYiq | |
| USE master | |
| GO | |
| DECLARE @kill varchar(8000) = ''; | |
| SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), spid) + ';' | |
| FROM master..sysprocesses | |
| WHERE dbid = db_id('MyDB') |
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
| set deadlock_priority high | |
| alter database PoorDB set offline with rollback immediate; | |
| alter database PoorDB set multi_user with rollback immediate; |
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
| /******************************************************* | |
| Check all constraints in db, FK, and check. | |
| Run through each one and log if error occurs | |
| ------------------------- history ------------------------- | |
| 2015-08-06 sqlbarbarian @ 13:27:21; adapted from the original basic info provided by [brentozar spblitz info](http://www.brentozar.com/blitz/foreign-key-trusted/) Thanks Brent! | |
| *******************************************************/ | |
| set noexec off; -- remove when ready to run | |
| set nocount on; |
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
| /******************************************************* | |
| review your connection details to see your default language | |
| *******************************************************/ | |
| select | |
| LanguageId = @@langid | |
| ,LanguageName = @@language | |
| /******************************************************* | |
| Localization for *NEW* users created would use this | |
| configuration option |
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
| /******************************************************* | |
| Using column alias with quotes returns results as an attribute | |
| *******************************************************/ | |
| select | |
| main.TABLE_NAME as '@TableName' | |
| from | |
| INFORMATION_SCHEMA.COLUMNS main | |
| where | |
| (objectproperty(object_id(TABLE_NAME), 'IsView') = 1 | |
| or objectproperty(object_id(TABLE_NAME), 'IsTable') = 1) |
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
| use master; | |
| select | |
| case | |
| when d.mirroring_state != 0 then 'print ''Turning mirroring off on ' + s.name + '''' + CHAR(10) + CHAR(13) | |
| + 'alter database ' + QUOTENAME(s.name) + ' set single-user with rollback immediate;' + CHAR(10) + CHAR(13) | |
| + 'alter database ' + QUOTENAME(s.name) + ' set partner off;' + CHAR(10) + CHAR(13) | |
| else '' | |
| end | |
| + 'GO' + CHAR(10) + CHAR(13) | |
| + 'print ''dropping ' + QUOTENAME(s.name) + '''' + CHAR(10) + CHAR(13) |
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
| if object_id('tempdb..#temp', 'U') is not null | |
| begin | |
| print 'Dropped #temp per existed' | |
| drop table #temp; | |
| end | |
| select | |
| sqid_sort = row_number() over (partition by t.object_id order by t.name) | |
| ,table_name = t.name | |
| ,fk_name = FK.name |
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
| public static string ConvertDataTableToString(DataTable dataTable) | |
| { | |
| var output = new StringBuilder(); | |
| var columnsWidths = new int[dataTable.Columns.Count]; | |
| // Get column widths | |
| foreach (DataRow row in dataTable.Rows) | |
| { | |
| for(int i = 0; i < dataTable.Columns.Count; i++) |
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
| tf workspace -new %JOB_NAME%;%user% -noprompt -server:http://%host%:8080/tfs/%project% -login:%user%,%password% | |
| tf workfold -map $/Release/MilestoneX.X . -workspace:%JOB_NAME% -server:http://%host%:8080/tfs/%project% -login:%user%,%password% | |
| tf get . -version:L%TFS_LABEL% -recursive -noprompt -login:%user%,%password% | |
| tf workfold -unmap . -workspace:%JOB_NAME% -login:%user%,%password% | |
| tf workspace -delete %JOB_NAME%;%user% -noprompt -server:http://%host%:8080/tfs/%project% -login:%user%,%password% |