Three ways to get SQL table field structure

It should be easy to print the structure of your SQL tables – right? Not so fast. Try to search that topic and you will find a handful of relevant, but confusing links.

Here are 3 ways to get the table field structure that I found the most useful:

-01-  Use Alt+F1

Select schema and table name and press Alt+F1 in SSMS, for example highlight CRPDTA.F0101 and use Alt+F1.

-02- Get SQL table structure

Use this T-SQL Query to get table structure from SQL system tables:

One little twist here is that different field types store its size in different columns. This SQL command combines an important CHARACTER_OCTET_LENGTH and NUMERIC_PRECISION and NUMERIC_SCALE fields all in one column.

SELECT ORDINAL_POSITION   [Seq]
, COLUMN_NAME     [Field Name]
, DATA_TYPE     [Type]
, LTRIM(COALESCE(STR(CHARACTER_MAXIMUM_LENGTH)
  , STR(NUMERIC_PRECISION)+','+LTRIM(STR(
  NUMERIC_SCALE)) , ' ')) [Size]
, IS_NULLABLE     [Nullable]
, ISNULL(COLUMN_DEFAULT, ' ') [Def Val]
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'F4211'
ORDER BY ORDINAL_POSITION

Here is what the final result might look like:

Seq Field Name Type Size Nullable
1 SDKCOO nchar 5 NO
2 SDDOCO float NO
3 SDDCTO nchar 2 NO
4 SDLNID float NO
5 SDSFXO nchar 3 YES
6 SDMCU nchar 12 YES

-03- Get JDE EnterpriseOne table structure

If your table is from JDE EnterpriseOne, you might need to list field descriptions and actual decimal places for your numeric fields that are stored in Data Dictionary. In that case use SQL below:

SELECT ORDINAL_POSITION [Seq], COLUMN_NAME [Field Name]
, DATA_TYPE [SQL Type]
, LTRIM(COALESCE(STR(CHARACTER_MAXIMUM_LENGTH), STR(NUMERIC_PRECISION)+','+LTRIM(STR(NUMERIC_SCALE)), ' ')) [Size]
, IS_NULLABLE [Nullable], FRDSCR [Description], FRCLAS [Class], FRDTAT [Ty], FRDTAS [Size], FRDTAD [File Dec]
, FRCDEC [Display Dec], FRDVAL [Default Value], FROWER [Edit Rule], FROER1 [UDC SY], FROER2 [UDC RT]
FROM INFORMATION_SCHEMA.COLUMNS LEFT OUTER JOIN
JDE920.DD920.F9202 T02 ON SUBSTRING(COLUMN_NAME, 3, 10) = T02.FRDTAI AND FRLNGP = '' AND FRSYR = ''
LEFT OUTER JOIN JDE920.DD920.F9210 T10 ON SUBSTRING(COLUMN_NAME, 3, 10) = T10.FRDTAI
WHERE TABLE_NAME = 'F0911' ORDER BY ORDINAL_POSITION

You might see output similar to table below:

Seq Field Name Description Size File Dec Display Dec
1 GLKCO Document Company 5 0 0
2 GLDCT Document Type 2 0
3 GLDOC Document Number 8 0
4 GLDGJ G/L Date 6 0 0
5 GLJELN Journal Entry Line Number 7 1
6 GLEXTL Line Extension Code 2 0

Note: for SQL above to work you need SQL read access to JDE system database and DD files F9202 and F9210. To check where your DD is located use data browser and navigate Data Source Master table F98611.

[Note: last updated 2019-03-14 TH 13:05]

Beware of false prophets:

Few people think more than two or three times a year. I’ve made an international reputation for myself by thinking once or twice a week.”
Bernard Shaw

(Visited 506 times, 1 visits today)

1 Comment

  1. Hallo, PeterI usually use sql stnatmeet via sql analyzer or query.I think something missing in your sql stnatmeet, so I’m sure your stnatmeet won’t work.Your stnatmeet is:SET SUB_DMO = CONCAT(’11′, SUBSTRING(SUM_DMO,3))It should be:SET SUB_DMO = CONCAT(’11′, SUBSTRING(SUM_DMO,3,2))However you are also able to use below stnatmeet (use plus sign (+)):SET SUB_DMO = ’11′ + SUBSTRING(SUM_DMO,3,2)I try the stnatmeet, and it works.Printer Info recently posted..

Your question, correction or clarification Ваш вопрос, поправка или уточнение