MySQL CHAR() vs T-SQL CHAR(): What’s the Difference?

There are many functions that are included in both MySQL and SQL Server. However, just because both DBMSs share functions of the same name, doesn’t mean that those functions work exactly the same way.

Take CHAR() for example. Both MySQL and SQL Server include this function. Well technically, for SQL Server it’s actually a T-SQL function, but that’s beside the point. The point is that the MySQL CHAR() function provides more functionality than the T-SQL/SQL Server CHAR() function.

In particular, the MySQL version accepts multiple integers, whereas, the T-SQL version only accepts a single integer. The MySQL version also accepts a USING clause that allows you to specify which character set to use (the T-SQL version doesn’t have this clause).

Below are some examples of these differences.

Continue reading

3 Ways to Detect if a String Matches a Regular Expression in MySQL

MySQL has a number of functions and operators that allow us to perform operations using regular expressions (regex). This article presents two operators and one function that enable us to find out if a string matches a regular expression specified by a given pattern.

These regex functions and operators are:

These are all basically equivalent, as the operators (the second two) are both synonyms of the function (the first one). In any case, you can see examples of all three in action below.

Continue reading

How the MATCH() Function Works in MySQL

In MySQL, the MATCH() function performs a full-text search. It accepts a comma separated list of table columns to be searched.

The table/s must have a FULLTEXT index before you can do a full-text search against them (although boolean queries against a MyISAM search index can work — albeit slowly — even without a FULLTEXT index).

You can create a FULLTEXT index when creating the table (using the CREATE TABLE statement), or you can use the ALTER TABLE statement or the CREATE INDEX statement if the table already exists.

By default, the search is case-insensitive. To perform a case-sensitive search, use a case-sensitive or binary collation for the indexed columns.

Continue reading