Problems displaying this newsletter? View online.
SQL Server Central
Featured Contents
Question of the Day
The Voice of the DBA
 

The Wild Developers of SQL Server like Wildcards

This editorial was originally published on Dec 17, 2018. It is being re-published as Steve is on holiday.

Why don't database developers like regular expressions?

  • Firstly, there are countless flavors of it, from PCRE, Vim, Java to POSIX ERE. Microsoft still have three distinct, basic flavors, in many varieties. You never can be quite sure how your favorite RegExes will work if you change your application, or work in two different versions of one application (as with SSMS).
  • Secondly, Regexes aren't intuitive. Even if you understand concepts such as 'greedy' 'possessive' and 'lazy' and you think you've wrestled with the complexities of matching line ends, you are confronted with a metacharacter syntax that may have made sense to the legendary mathematical geeks who devised it, such as Stephen Cole and Ken Thompson, but is hardly destined to appeal to the legendary, ordinary application developer on the legendary Clapham Omnibus.
  • Thirdly, when they are used as predicates in filters, such as WHERE clauses, it is very difficult to reduce the number of searches to the possible candidates. Unless the Regex makes a certainty of the start of the string, it is hopeless.

Instead, in SQL Server, we cling to the LIKE/PATINDEX wildcard convention. It is a Sybase invention, a sort of poor-man's RegEx, so Microsoft have never bothered to enhance the syntax. In a sense this is a joy. The LIKE wildcards that you write now will work in any version of SQL Server. However, they are so deficient in the basic anchors, quantifiers, character classes and alternators that any useful wildcards become very complicated even to look at, let alone understand. Frustratingly, Regexes are there in SQL Server, but out of reach, only for XQuery/XPath expressions.

With MySQL, MongoDB or PostgreSQL, Regular expressions are at the heart of searches, and they aren't causing the sort of performance problems that Microsoft engineers seem to conjure up in their fevered imagination. Microsoft can't really afford to dither any longer with facilitating better string pattern search. As I see it there are two options: either enhance the LIKE/PATINDEX wildcard conventions or provide a good Regex search that is compatible with .NET Core. I'd be happy with the former, just to allow easier constraints for complicated string-based datatypes, such as sort codes or postal codes. We must retain backward compatibility anyway, and it would be great to have something that prevents us having to learn two different conventions for pattern search.

Curiously, even PowerShell has a '-like' comparison operator. It is even more of a poor, shriveled thing than the SQL Server one. The documentation for it consists mostly of stern instructions to use the -match Regex instead. This seems a bit rich, coming from the company that popularized the wildcard convention for searching the filesystem. Come on, SQL Server team. Wildcards need to be improved!

Phil Factor

Phil Factor

Join the debate, and respond to today's editorial on the forums

 
 Featured Contents
SQLServerCentral Article

Pitfalls to avoid while feeding events into CrowdStrike

Pablo Echeverria from SQLServerCentral

Learn how you can integrate the SQL Server error logs into Crowdstrike for better analysis.

External Article

AI in SQL Server 2025: Embeddings

Additional Articles from SimpleTalk

One of the cornerstones of AI is a concept called embeddings. Virtually every AI model, whether for text, video, or audio, uses something related to embeddings. Starting with SQL Server 2025, this is a term you’ll be hearing a lot, as its potential for applications is enormous!

Blog Post

From the SQL Server Central Blogs - A Couple Quick GENERATE_SERIES Tests

Steve Jones - SSC Editor from The Voice of the DBA

I had someone reach out about generate_series() recently, saying they hadn’t realized this was a new feature in SQL Server 2022. They were wondering if it was better than...

Blog Post

From the SQL Server Central Blogs - How I passed the DP-700 Exam

Koen Verbeeck from Koen Verbeeck

I recently took and passed the DP-700 exam, which is required for the Microsoft Certified: Fabric Data Engineer Associate certification. It’s the second Fabric certification, and it focuses more...

Admin Azure SQL Solutions

Exam Ref DP-300 Administering Microsoft Azure SQL Solutions

Site Owners from SQLServerCentral

Directfrom Microsoft, this Exam Ref is the official study guide for the new MicrosoftDP-300 Administering Microsoft Azure SQL Solutions certification exam.

 

 Question of the Day

Today's question (by Steve Jones - SSC Editor):

 

Column Adds and Drops

I run this batch on SQL Server 2022. What happens?
ALTER TABLE dbo.Accounts
 ADD AccountAccessType INT
GO
ALTER TABLE dbo.Accounts
 DROP AccountAccessType
GO

Think you know the answer? Click here, and find out if you are right.

 

 

 Yesterday's Question of the Day (by Steve Jones - SSC Editor)

Multiple Sequences

In SQL Server 2022, I run this code:

CREATE SEQUENCE myseqtest START WITH 1 INCREMENT BY 1;
GO
CREATE TABLE NewMonthSales
  (SaleID    INT
  , SecondID int
 , saleyear  INT
 , salemonth TINYINT
 , currSales NUMERIC(10, 2));
GO
INSERT dbo.NewMonthSales
  (SaleID, SecondID, saleyear, salemonth, currSales)
SELECT
  NEXT VALUE FOR myseqtest
, NEXT VALUE FOR myseqtest
, ms.saleyear
, ms.salemonth
, ms.currMonthSales
FROM dbo.MonthSales AS ms;
GO
SELECT * FROM dbo.NewMonthSales AS nms

Assume the dbo.MonthSales table exists. If I run this, what happens?

Answer: The SaleID gets values 1, 2, 3 and the SecondID gets 1, 2, 3

Explanation: When the same sequence is called in the same query twice, the same value is returned. For multiple rows, the sequence behaves as expected. In this case, both columns get the same value in each row. Ref: NEXT VALUE FOR - https://learn.microsoft.com/en-us/sql/t-sql/functions/next-value-for-transact-sql?view=sql-server-ver16

Discuss this question and answer on the forums

 

 

 

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.


SQL Server 2017 - Development
Splitting Text based on certain phrases in string - I have a text string that contains something similar to below : [{"ChannelName":"LOT4 - Telephone","ChannelRecordId":"42c49edf-9aa1-ec11-b85f-00155d640f76","Removed":false},{"ChannelName":"LOT4 - Video","ChannelRecordId":"46c49edf-9aa1-ec11-b85f-00155d640f76","Removed":false}] I need to strip out into separate columns or create additional records for the guid after the text "ChannelRecordID":" and also the false at the end (which might say true). The number of iterations of the phrase ChannelRecordID […]
SQL Server 2016 - Administration
KB5046856 fails to install - Hello experts, The following SQL update is failing to install on some of our SQL Servers with the following error. Is anyone else seeing this? I've tried Googling the error but have not found a specific fix for this issue. Thanks for any help. -- webrunner Update: Installation Failure: Windows failed to install the following […]
Perfomance in views - Hello, I want to ask you about the following case that I live with a company in my country. They have a SQL server licensed with SQL enterprice ver 2016, where in the same instance about 25 databases coexist and in particular the main one and heart of all the systems, the Erp base. There […]
SQL Server 2016 - Development and T-SQL
Deadlocks after index rebuild - We rebuilt a bunch of indexes that had avg_fragmentation_in_percent>30. Now we have 1 job that is consistently getting deadlocks and I'm trying to find the root cause. Attached is the event data xml file from the deadlock event. Any help on which direction to start looking is greatly appreciated. We are using 2016 sp 2. […]
SSIS (Integration Services) - "External table is not in the expected format" - Good Afternoon. I have been manually running an SSIS package on an adhoc basis, which populates an Excel file from a SQL Server Table. There is no apparent issue with the package, but often I get the following error: "External table is not in the expected format" And it resolves when I Shut Down and Re-Start the […]
SQL Server 2019 - Administration
Multisubnet Cluster DBs not replicating - No AD on one subnet - Hi All, We have setup a 3 node SQL Server 2019 (CU30) multi subnet cluster with 2 nodes on production site and 1 node in disaster recovery (DR) site. The DR site does not have any AD/Domain and it is still under the same AD/Domain as production (Just different subnet but same AD - One […]
SQL Server 2019 - Development
how to output date of when a SP was created and last modification? - Hi everyone I have a query that gives me the list of all SP in my DB.  I would like to modify the query so it outputs two additional fields: 1. When was the SP created (call it CREATION_DATE)? 2. When was the SP last updated (call it LAST_UPDATE_DATE)? Is this possible?  If yes, how […]
Source to Target Mapping (Lineage) - Hi all, I work with an unusual warehouse and I was wondering if anyone else has this issue, we are looking to document source to target but with our set up it seems like it's going to be a manual process. We don't have a separate ETL tool that loads the data. Our warehouse is […]
where to find information about xE sqlserver.databases_bulk_copy_throughput - where to find information about xE sqlserver.databases_bulk_copy_throughput ? I'm searching for de description of all attributes ( e.g. "count" - is it number of B/KB/MB/GB or number of rows ? )
Analysis Services
How do I read XEL files in SSAS? - A colleague of mine has setup SSAS monitoring through Extended Events and these are writing to XEL files on the local server. Can anyone advise how I can read these on an SSAS server? I know how to do this in SQL Server but those commands don't work (or exist) in the SSAS query window. […]
SQLServerCentral.com Test Forum
New test Mar 2025 - Testing posting and replying
SQL Server 2022 - Administration
Service Principal Name (SPN) getting this error and then sqlserver restarting. -   HI All, Service Principal Name (SPN) getting this error and then sqlserver restarting. every time unable to find other thing in logs in event viewer and in sqlserver logs also , do we need to check with windows team to get a fix for this so that again and again this wont happens and […]
SQL Backup folder permission issue - Hi SQL experts, Having an issue on one of our SQL servers at work in which the SQL backup folder permissions are not right and the folder is inaccessible. I just noticed this problem when attempting to setup nightly maintenance plans. Even though I'm logged in with my domain admin account, I still don't have […]
DBCC Clone Database Failing on SQL 2022 - When running clone sql is changing one specific table to History table and its failing. Please suggest if there is any bug  
SQL Server 2022 - Development
Getting error in sql server 2022 - Hi folks We have migrated database from sql server 2014 std to sql server 2022 std. database get restored and old server is sql service is stopped. Now after few initial operation we are facing this error "Please create master key in the database or open master key in session" as checked on net restored […]
 

 

RSS FeedTwitter

This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -