Skip to content

Show me the wait stats

'Using wait stats to identify pressure points on your SQL Server is a common method for troubleshooting. Unfortunately , it is very easy to jump to conclusions about problems on the basis of the highest wait stats.

My general approach is to use wait stats , but letting them guide me to extra analysis. There could be all sorts of reasons why a wait stat or a combination of wait stats appear .

The more you use wait stats , you develop methods for troubleshooting. Interpreting the initial findings will help you start to ask the right question.

These are some of the wait stats available categorised. This is where the waits are appearing, but there could be multiple reasons for their occurrence.'...

http://www.sqlserver-dba.com/2016/05/show-me-the-wait-stats.html

Unable to create login AlwaysOn availability group secondary replica

'One of my clients reported a usual behavior of the AlwaysOn availability group. He informed me that he is trying to add a login on the secondary replica in the AlwaysOn AG environment but it is failing with below error:

Msg 3906, Level 16, State 1, Line 3
Failed to update database “SCCMDB” because the database is read-only.

As a normal troubleshooting, I asked to do it from SQL Server Management Studio and got below error.'...

https://blog.sqlauthority.com/2016/12/10/sql-server-unable-create-login-alwayson-availability-group-secondary-replica/

SQL Error – The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine. (System.Data)

'I was trying to export a SQL table to Excel and I got below error:

TITLE: SQL Server Import and Export Wizard
——————————
The operation could not be completed.
——————————
The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine. (System.Data)
——————————'...

https://sqlwithmanoj.com/2016/12/24/sql-error-the-microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine-system-data/

Microsoft Command Line Utilities 13.1 for SQL Server

'The SQLCMD utility allows users to connect to, send Transact-SQL batches from, and output rowset information from SQL Server instances. The bcp utility bulk copies data between an instance of Microsoft SQL Server and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into data files.
The new SQLCMD supports Azure AD authentication for SQL DB and DW as well as Always Encrypted features (see SQLCMD Utility Details ).

Version: 13.1
 
File Name:
Command Line Utilities MSI files\amd64\MsSqlCmdLnUtils.msi
Command Line Utilities MSI files\x86\MsSqlCmdLnUtils.msi

Logon failed for login due to trigger execution

'While trying to connect SQL Server using SQL Server Management Studio Object Explorer, I got the following error message "Logon failed for login 'sqluser' due to trigger execution.".

When I see the error message occured during connect to SQL Server 2008 R2 database, I realized that the cause of the sql exception is the SQL Server logon trigger which I created recently for SQL Server login audit purposes.

logon failed for login sqlserveruser due to trigger execution

Since database administrators and t-sql developers are first introduced with logon triggers in SQL Server 2005, I guess sharing how to troubleshoot with logon triggers in SQL Server will be useful for many. This logon trigger sample case is experienced in SQL Server 2008 R2, but the steps for the solution of "Logon failed for login due to trigger execution" error is same in SQL Server 2005, SQL Server 2008 and in SQL Server 2011.'

http://www.kodyaz.com/articles/sql-server-logon-trigger-logon-failed-for-login-due-to-trigger-execution.aspx

Solution:

sqlcmd –S <InstanceName> -d master –A
 
1> SELECT * FROM master.sys.server_triggers
2> GO
 
Take the evil trigger name…
 
3> DISABLE TRIGGER <EVIL_TRIGGER_NAME> ON ALL SERVER
4> GO

Regular Expressions in SQL Server

'Databases store text, and the best way to manipulate text is to use a regular expression ('regex'). Using regular expressions in SQL queries has been possible in many database engines for decades.

Now you can use regular expressions in SQL Server queries, too. I've created an open-source project, sql-server-regex, that lets you run regular expressions in T-SQL queries using scalar and table-valued functions.'...

http://devnambi.com/2016/sql-server-regex/

Altering an Existing Table to Support Temporal Data

'If you are looking for a way to track the history of all the data changes to a table then SQL Server 2016 has you covered with the new temporal table support. With Temporal tables SQL Server is able to store all the older data records into in a history table while keeping the current records in the original table.  In this article I will explore using the temporal table feature of SQL Server 2016 to create a history table for an existing SQL Server table.'...

http://www.databasejournal.com/features/mssql/altering-an-existing-table-to-support-temporal-data.html

Find and Remove Duplicate Rows from a SQL Server Table

'According to database design best practices, a SQL Server table should not contain duplicate rows. During the database design process primary keys should be created to eliminate duplicate rows. However, sometimes we need to work with databases where these rules are not followed or exceptions are possible (when these rules are bypassed knowingly). For example, when a staging table is used and data is loaded from different sources where duplicate rows are possible. When the loading process completes, table should be cleaned or clean data should be loaded to a permanent table, so after that duplicates are no longer needed. Therefore an issue concerning the removal of duplicates from the loading table arises. In this tip let's examine some ways to solve data de-duplication needs.'...

https://www.mssqltips.com/sqlservertip/4486/find-and-remove-duplicate-rows-from-a-sql-server-table/

Extracting string after and before a Character/Pattern

'Usually we see lof of codes flying around for this extraction.Most of them difficult to remember.

An easy way is to get hold of the basics.

Function used : SUBSTRING,CHARINDEX

Substring syntax : SUBSTRING(string to search, position to start, length of characters to be extracted)

CHARINDEX (character to search, string to search) returns the position of the character in the string.

If we want to extract before the character you would put the charindex as the number of characters and start position as 0 in the substring function'...

http://www.sqlservercentral.com/scripts/SQL/133967/