Hints and tips on database

These are some helpful hints on various topics.

 

MSQQL count(columnt) doesn't support all data types

In MSSQL queries like

select count(col1) from table1

will fail if column type is uniqueidentifier, text, image, ntext. Those types are not supported also in aggregate functions and subqueries.


Oracle dual table or how to migrate Mysql tableless queries

If you are familiar with Mysql, you probably use sometimes tableless queries like this:
 
SELECT 12 * (1 + 10);
 
Well, if you're migrating to Oracle you'll be surprised to find that those queries are not allowed here. The solution? Use the dual table like this:
 
SELECT 12 * (1 + 10) from dual
 
Dual is special table that is automatically created. Its schema has only one column called dummy, and is populated with just one row with value 'X'. In short - this makes it very useful for our case.