get number of columns sql table code example

Example 1: get columns number sql

#With SQL

SELECT count(*)
FROM information_schema.columns
WHERE table_name = 'Your_table_name';

Example 2: get number of columns sql

SELECT TABLE_NAME , count(COLUMN_NAME)
FROM information_schema.columns
GROUP BY TABLE_NAME;

-- Oracle (depending on schema grants):
SELECT count(*) FROM USER_TAB_COLS WHERE TABLE_NAME = 'my_table';
SELECT count(*) FROM ALL_TAB_COLS WHERE TABLE_NAME = 'my_table';
SELECT count(*) FROM DBA_TAB_COLS WHERE TABLE_NAME = 'my_table';

Tags:

Sql Example