devxlogo

SQL

Introducing the APPROX_COUNT_DISTINCT SQL Function

The APPROX_COUNT_DISTINCT?SQL Function became available with SQL Server 2019 Community Technical Preview (CTP) 2.0. APPROX_COUNT_DISTINCT?returns the approximate number of unique non-null values in a group. This example returns the approximate

Auto Start the SQL Server Agent Service

You can ensure that your SQl Server Agent always restarts when the SQL Server restarts by using sp_Configure and xp_cmdshell, as shown underneath: 1. Enabe ‘xp_cmdshell’ — Allow advanced options

Using ENUM in MySQL Columns

ENUMs are very powerful definitions and they help attain data validation when the values are pre-defined. With this you can avoid application-level validation or the same can be extracted from

Reverse Strings in SQL

You can reverse strings in SQL by executing a query similar to this one. This query makes use of the REVERSE SQL function. SELECT FirstName, REVERSE(FirstName) AS Reverse FROM Employees

Generating Random Numbers in SQL

You can generate a Random number in SQL with the following command: SELECT RAND() Random_Number This returns the following value 0.713666525097956

Obtaining ASCII Values from Characters in SQL

With the ASCII function you can return a certain character’s ASCII value, as shown in the following example: SELECT ASCII(‘A’) AS A, ASCII(‘B’) AS B, ASCII(‘a’) AS a, ASCII(‘b’) AS

Using the HASHBYTES Function in SQL

The HASHBYTES?function returns the MD2, MD4, MD5, SHA, SHA1, or SHA2 hash of a string. The next example returns a SHA1 hash value of it the string that was input.

Find Tables with an XML Column

You can find tables with an XML column in the following way: SELECT [table] = s.name + N’.’ + t.name FROM sys.tables AS t INNER JOIN sys.schemas AS s ON