Query to get field name with datatype and size

Tor_Fey

Registered User.
Local time
Today, 19:51
Joined
Feb 8, 2013
Messages
121
Does anyone have a SQL query to retrieve field names with datatype and size from all tables within an access database?

I was hoping to use something like the below code... But, I want the SQL code to know the current database and tables without me having to specify them

SQL:
SELECT column_name as 'Column Name', data_type as 'Data Type',
character_maximum_length as 'Max Length'
FROM information_schema.columns
WHERE table_name = 'tblUsers'

In the following example, the code can be just cut and paste from one database to another without having to change anything, and this is what i would like to achieve with the new SQL code to query field names with data types and size.

SQL:
SELECT MSysObjects.name, MSysObjects.DateCreate, MSysObjects.DateUpdate
FROM MSysObjects
WHERE (((MSysObjects.name) Not Like '~*' And (MSysObjects.name) Not Like 'MSys*') AND ((MSysObjects.type) In (1,4,6)))
ORDER BY MSysObjects.DateUpdate DESC;

Your help is always appreciated

Kind regards
Tor Fey
 
Try something like
SQL:
SELECT T.Name                   AS TableName,
       Schema_name(T.schema_id) AS SchemaName,
       C.Name                   AS ColumnName,
       Ty.Name                  AS ColumnDataType,
       C.is_nullable            AS IsNullAble,
       C.is_identity            AS IsIdentity
FROM   sys.tables T
       INNER JOIN sys.columns C
               ON T.OBJECT_ID = C.OBJECT_ID
       INNER JOIN sys.types Ty
               ON C.system_type_id = Ty.system_type_id
WHERE  T.is_ms_shipped = 0
ORDER  BY T.name
 
This should not be in the sql server forum
 
Hi Minty;

I tried this code and get the following error:

SyntaxError.png


Kind Regards
Tor Fey
 
This should not be in the sql server forum
Hang on - I thought you wanted this for SQL server - your code is for SQL and you state
I was hoping to use something like the below code... But, I want the SQL code to know the current database and tables without me having to specify them

SQL:
SELECT column_name as 'Column Name', data_type as 'Data Type',
character_maximum_length as 'Max Length'
FROM information_schema.columns
WHERE table_name = 'tblUsers'

Although I missed the bit at the beginning that says
datatype and size from all tables within an access database?

In which case you need need to use the TableDefs Collection.

Try this https://www.devhut.net/2010/06/10/ms-access-vba-list-table-fields/

But loop through it.
 

Users who are viewing this thread

Back
Top Bottom