Check the SQL Server version

There are always some new features in the database server, which has SQL version checking requirements. For example: GRANT VIEW DATABASE PERFORMANCE STATE TO [user] can run, if your server at least SQL Server 2022.

In this case if you don’t want to see error in an older version , you have to check it:

 

 

DateTime calculator to UTC to Local Server time to a specific TimeZone

In SQL server you can get the local datetime UTC time . Convert it to different TimeZone:

 

Convert a local datetime or the server local time to different timezone:

Convert  UTC datetime or the server  UTC time to different timezone:

Continue reading “DateTime calculator to UTC to Local Server time to a specific TimeZone”

Add read rights to all existing and new user databases

 

The following script add read user rights for every user databases and  system model databases for the new databases to readeruser  login.

 

DBATools Get-DbaDatabase] Failure | The certificate chain was issued by an authority that is not trusted.

If  you get the error:

Get-DbaDatabase] Failure | The certificate chain was issued by an authority that is not trusted.

You can set in dbatools:

 

or

 

dbatools sql The certificate chain was issued by an authority that is not trusted.
dbatools sql The certificate chain was issued by an authority that is not trusted.

SQL Server using Active Directory Kerberos authentication on RedHat linux

This is an SSMS screenshot where a SQL user and two (windows) domain users connected to SQL Server:

SQL Server on Red Hat Linux using kerberos AD authentication
SQL Server on Red Hat Linux using kerberos AD authentication

some hint if you want to deploy it:
– at first you have to join the linux server to the Active Directory
sudo realm join SQLPLAYGROUND.COM -U ‘azureadmin’ -v
kinit and klist help you to check kerberos tickets
– you can use create -k /var/opt/mssql/secrets/mssql.keytab only in Ubuntu
– you have to use ktpass /princ MSSQLSvc/REDHATSQL2019.SQLPLAYGROUND.COM:1433@CONTOSO.COM /ptype KRB5_NT_PRINCIPAL /crypto aes256-sha1 /mapuser SQLPLAYGROUND\sqluser /out mssql.keytab -setpass -setupn /kvno /pass in Red-Hat linux

Index usage statistics

Do you have unused index? Do you have ineffective index? How many times was it used for select or update?
Is it used by scan , seeks or lookups?
Index usage statistics :

How to start a stored procedure when SQL server start?

You can start a stored procedure that is set to automatic execution runs every time an instance of SQL Server is started.

Is there any autostart stored procedure on your SQL Server?
You can query:

Replace a MS SQL Database in AlwaysOn AG with DBATools

There is a database in AG and you need to drop it and restore from backup (which is sometimes a transition from developer to prod )
You don’t need any prerequisite for cluster nodes and AG names.
The script find the instance in local windows server and find the db AG nodes and listener.
So finally you need the database name and the location of the backup folder which can be an Ola backup solution folder.

Setup.exe error with using ConfigurationFile.ini

SQL server setup error with using setup.exe /CONFIGURATIONFILE=D:\Install\ConfigurationFile.ini

Error message:
Error result: -2054422506
Result facility code: 1420
Result error code: 22

Please check the ini file:

Reason:
; Setup will not display any user interface.
QUIET=”True”
; Setup will display progress only, without any user interaction.
QUIETSIMPLE=”False”
; Parameter that controls the user interface behavior. Valid values are Normal for the full UI,AutoAdvance for a simplied UI, and EnableUIOnServerCore for bypassing Server Core setup GUI block.
UIMODE=”Normal”

Possible Solution :
QUIET=”False”