Count unique / all values

SELECT COUNT(DISTINCT <FIELDNAME>), COUNT(ALL <FIELDNAME>) FROM <TABLE>;

Partially anonymize e-mail addresses

UPDATE <TABLE_NAME>
SET <EMAIL_FIELD>=
INSERT(
<EMAIL_FIELD>,
POSITION('@' IN <EMAIL_FIELD>),
100,
CONCAT(FLOOR(1 + (RAND() * 100)),'@hascode.com'))
WHERE
POSITION('@' IN <EMAIL_FIELD>)>0;

Find duplicate entries

SELECT COUNT(*), <FIELDNAME> FROM <TABLENAME>
GROUP BY <FIELDNAME>
HAVING COUNT(*)>1;

MySQL Fix Zero Dates for Data Imports

Error: ERROR 1067 (42000) at line 1234: Invalid default value for ‘datefield’

In newer MySQL Versions zero in date or zero dates are forbidden .. check this with:

SHOW VARIABLES LIKE 'sql_mode';

In the import script, remove these both values: NO_ZERO_IN_DATE,NO_ZERO_DATE

e.g. like this:

SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Oracle Multiple Levels of Subtotals

SELECT <FIELD>, <otherfield..>
FROM <TABLE>
GROUP BY ROLLUP(<FIELD>);

Postgres create roles

CREATE ROLE name;
DROP ROLE name;
SELECT rolname FROM pg_roles;
\du
GRANT name TO username

Postgres set user password

ALTER USER
ALTER USER root WITH password 'xxx';

Postgres change database

\cDBNAME