SQL SMO Scripting Options broken in versions 2012-2016

Some notes about SSMS.

Here’s where the problem lies. If you are installing SQL 2012-2016 your Scripting Options may not work.

For SQL Server 2014 SSMS is included in the SQL install and SP.

The fix:

Even though you might only be installing SQL Server 2014 because SMO Options didn’t always work between versions 2012-2016 we need to install SQL Server 2017 SSMS 17.9.1.

e.g. What was broken was the SMO Scripting Option for
$Scripter.Options.NoFileGroup = $false
which is the default but even explicitly forcing it had no effect.

Simply adding SSMS 17.9.1 allowed correct scripting from the server.

https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017

SSMS 17.9.1 is the current General Availability (GA) version of SSMS
1) download Download SQL Server Management Studio 17.9.1

2) download Download SQL Server Management Studio 17.9.1 Upgrade Package (upgrades 17.x to 17.9.1)

Version Information
Release number: 17.9.1
Build number: 14.0.17289.0
Release date: November 21, 2018

PowerShell: Get list of registered SQL Servers

No reason to maintain more than one list of SQL Servers when you can query SSMS’s Registered Servers.


Import-Module SQLPS -DisableNameChecking 
$SQLInstanceProd = @()
            
$ServerGroup = 'PRODUCTION'
$SQLPath = "SQLSERVER:\sqlregistration\Database Engine Server Group\PROD*\" 
        
$SQLInstanceProd += @(get-childitem $SQLPath -Recurse).Name | ?{$_ -notmatch '\d\d\d\d'} | % {
    $MyPSObject = New-Object PSObject -Property @{ 
            SQLInstance  = $_ 
            ServerGroup  = $ServerGroup;
        }
    $MyPSObject
    }

$SQLInstanceProd

Putting that logic into Get-RegisteredServers I populate the following list in my Profile.

$AllServersList = (Get-RegisteredServers).SQLInstance
$AllComputersList = $AllServersList | %{  $_.split('\')[0] }
$SQLInstanceDev = $((Get-RegisteredServers) |Where-Object {$_.ServerGroup -match 'DEV'}).SQLInstance
$SQLInstanceTest = $((Get-RegisteredServers) |Where-Object {$_.ServerGroup -match 'TEST'}).SQLInstance
$SQLInstanceProd = $((Get-RegisteredServers) |Where-Object {$_.ServerGroup -match 'PROD'}).SQLInstance

SQL What is the second Monday of this month?

What is the second Monday of this month?

;WITH [cteDate]
AS
 (
 -- @first + 7 * (@nth - 1) + (7 + @dow - DATEPART(WEEKDAY, @first + 7 * (@nth - 1))) % 7 -- Get @nth @dow 2 = Monday for us. Formula from Steve Kass.
 SELECT
      DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) + 7 * (2 - 1)
      + (7 + 2 - DATEPART(WEEKDAY, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) + 7 * (2 - 1))) % 7 AS [SecondMonday])
SELECT
    [cteDate].[SecondMonday],
    DATENAME(WEEKDAY, [cteDate].[SecondMonday]) AS SearchWeekDay,
	DATEDIFF(DAY,GETDATE(),[cteDate].[SecondMonday]) AS DaysFromNow
FROM [cteDate]

What are all those old tempdb temp tables?

SQL Server caches the definitions of temp tables and table variables, to reduce the load on the system catalog in tempdb on busy systems which creates a lot of temp tables. Typically they have a name that starts with # and is followed by eight hex digits. –Erland Sommarskog

SQL Server Temporary Table Caching

This tip will describe the condition to allow caching of a SQL Server temporary table and a demonstration to benchmark the performance between a cached vs. non-cached temporary table.

Source: www.mssqltips.com/sqlservertip/4406/sql-server-temporary-table-caching/

 

 

Msg 11520, Level 16, State 1

Msg 11520, Level 16, State 1, Procedure sp_describe_first_result_set, Line 1
The metadata could not be determined because statement ‘EXECUTE master.dbo.xp_sqlagent_is_starting @retval OUTPUT’ in procedure ‘sp_is_sqlagent_starting’ invokes an extended stored procedure.

In SQL 2012 sp_help_job has changed. See this solution:

Workaround: SQL Server 2012 – OPENROWSET on sp_help_job throws “The metadata could not be determined”

Issue:In SQL 2012, stored procedures that call any other stored procedures or extended stored procedures that return result sets should specify WITH RESULT SETSSQL Agent’s stored procedure sp_help_job  – returns single resultset if no parameters are passed to stored procedure.  – returns 3 resultsets if job_id or job_name is specified. MSDN linkWhen RESULTSET is not described,…

Source: blogs.msdn.microsoft.com/sqlagent/2012/07/12/workaround-sql-server-2012-openrowset-on-sp_help_job-throws-the-metadata-could-not-be-determined/

SQL Backups reviewing LSNs

Here’s a nice page with some code which shows how to build a database test case sample where you can run your own tests.

How do I map a differential/transaction log backup to its full backup without using MSDB?

If you have multiple full, differential and transaction log backups, there are chances you may end up facing the error below during the restore process. “This differential backup cannot be restored because the database has not been restored to the correct earlier state”   You know that any differential/T-log  backup is mapped to particular full…

Source: blogs.msdn.microsoft.com/sqlserverfaq/2013/05/22/how-do-i-map-a-differentialtransaction-log-backup-to-its-full-backup-without-using-msdb/

I like this site’s simple list of rules which shows the FULL backup and where the CheckpointLSN and FirstLSN could be found in the DIFF and LOG backups.

Considering SQL Server Log Sequence Numbers for Backups

Take a look at this blog and understand SQL Server log sequence numbers for backups and know why LSN is important while restoring the database

Source: www.sqlmvp.org/sql-server-log-sequence-numbers-for-backups/

This page has nice graphics following the LSNs.

Understanding SQL Server Log Sequence Numbers for Backups

This tip describes SQL Server Log Sequence Numbers (LSNs) and how the sequence numbers link full, differential and transaction log backups. We will look at sample backups and how these LSN values can be read from the backup files to determine the restore

Source: www.mssqltips.com/sqlservertip/3209/understanding-sql-server-log-sequence-numbers-for-backups/

SQL Lessons: PowerShell basics

Part of my series pointing to valuable instruction on the web.

This one demonstrates the following functions by Chad Miller.

  • invoke-sqlcmd2
  • Write-DataTable
  • Out-DataTable
  • Add-SqlTable

Use PowerShell to Collect Server Data and Write to SQL

Learn about Windows PowerShell

Source: blogs.technet.microsoft.com/heyscriptingguy/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql/

SQL Lessons: SQL Server Configuration Manger

Part of my series pointing to valuable instruction on the web.

What Every Accidental DBA Needs to Know Now: SQL Server Configuration Manger

The SQL Server Configuration Manager is an critical but often overlooked application for proper SQL Server instance management and, well, “configuration”. In Tim Ford’s continuing series aimed at the Accidental Database Administrator he takes time to explain the basics of this tool, its use, and its features.

Source: m.sqlmag.com/database-security/what-every-accidental-dba-needs-know-now-sql-server-configuration-manger