Skip to content

Instantly share code, notes, and snippets.

@matrixcloud
Created January 10, 2020 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matrixcloud/78158b991d4c0948fc6947c2df1dd73a to your computer and use it in GitHub Desktop.
Save matrixcloud/78158b991d4c0948fc6947c2df1dd73a to your computer and use it in GitHub Desktop.
Check if table eexists
-- sql server
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'TheSchema' AND TABLE_NAME = 'TheTable'
-- postgresql
SELECT EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_schema = 'schema_name'
AND table_name = 'table_name'
);
-- oracle
select count(*)
from all_objects
where object_type in ('TABLE','VIEW')
and object_name = 'your_table_name';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment