6

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?
Result I want
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.

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
Jan
  • 63
  • 1
  • 5

2 Answers2

10

however your question isn't enough clear but you can get all of it with this this code

SELECT * FROM INFORMATION_SCHEMA.COLUMNS
Ari
  • 327
  • 2
  • 10
  • You can use INFORMATION_SCHEMA.TABLES if that's not obvious, note that the columns are different – Ryanman Oct 22 '20 at 18:36
4

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
  • 227
  • 1
  • 8
  • @Eric Do you have a better solution ? – Shahroz Shaikh Feb 27 '18 at 18:13
  • @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