Skip to content

Instantly share code, notes, and snippets.

@preethamhegdes
Last active July 9, 2017 09:40
Show Gist options
  • Save preethamhegdes/4afa9ede2ca1194f1d3a80064bc9d076 to your computer and use it in GitHub Desktop.
Save preethamhegdes/4afa9ede2ca1194f1d3a80064bc9d076 to your computer and use it in GitHub Desktop.
Database Connection validation query

Source : https://stackoverflow.com/questions/3668506/efficient-sql-test-query-or-validation-query-that-will-work-across-all-or-most

SELECT 1

- H2
- MySQL
- Microsoft SQL Server (according to NimChimpsky)
- PostgreSQL
- SQLite

SELECT 1 FROM DUAL

- Oracle

SELECT 1 FROM any_existing_table WHERE 1=0 or SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS

- HSQLDB (tested with version 1.8.0.10)

VALUES 1 or SELECT 1 FROM SYSIBM.SYSDUMMY1

- Apache Derby (via daiscog)

SELECT 1 FROM SYSIBM.SYSDUMMY1

- DB2

select count(*) from systables

- Informix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment