I want a list of table names and columns within that table (see below).
Is there a SQL query that would allow me to do this within a schema?
I know I can look at the GUI interface to look at the table names and columns but there are too many to look at manually.
Asked
Active
Viewed 1.0k times
7

Jan
- 73
- 1
- 1
- 5
-
1This can be done, but the query is different for each SQL product. Which one are you using? – Larry Lustig Feb 27 '18 at 16:59
-
I am using SQuirreL SQL Client snapshot. I am not sure if that's the SQL product you mean. – Jan Feb 27 '18 at 17:03
-
No, it will depend on what the underlying SQL engine is (SQL Server, DB2, SQLite, etc). Unless Squirrel contains a database agnostic way to report this information. – Larry Lustig Feb 27 '18 at 17:06
-
Which [DBMS](https://en.wikipedia.org/wiki/DBMS) product are you using? Postgres? Oracle? – Feb 27 '18 at 21:26
2 Answers
11
however your question isn't enough clear but you can get all of it with this this code
SELECT * FROM INFORMATION_SCHEMA.COLUMNS

Ari
- 337
- 2
- 11
-
You can use INFORMATION_SCHEMA.TABLES if that's not obvious, note that the columns are different – Ryanman Oct 22 '20 at 18:36
5
Using OBJECT CATALOG VIEWS:
SELECT T.name AS Table_Name ,
C.name AS Column_Name ,
P.name AS Data_Type ,
P.max_length AS Size ,
CAST(P.precision AS VARCHAR) + '/' + CAST(P.scale AS VARCHAR) AS Precision_Scale
FROM sys.objects AS T
JOIN sys.columns AS C ON T.object_id = C.object_id
JOIN sys.types AS P ON C.system_type_id = P.system_type_id
WHERE T.type_desc = 'USER_TABLE';
Using INFORMATION SCHEMA VIEWS
SELECT TABLE_SCHEMA ,
TABLE_NAME ,
COLUMN_NAME ,
ORDINAL_POSITION ,
COLUMN_DEFAULT ,
DATA_TYPE ,
CHARACTER_MAXIMUM_LENGTH ,
NUMERIC_PRECISION ,
NUMERIC_PRECISION_RADIX ,
NUMERIC_SCALE ,
DATETIME_PRECISION
FROM INFORMATION_SCHEMA.COLUMNS;
Taken from this answer: Getting list of tables, and fields in each, in a database

David Breen
- 247
- 1
- 8
-
-
@ShahrozShaikh I don't use squirrel, so I don't have a solution. But the point is don't post a query that won't work as an answer because it's useless to the OP. OP can't use it. – Eric Feb 27 '18 at 18:17