Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View "Table Schema" for View in Teradata without access to table?

Tags:

sql

teradata

Is there a similar command to:

SHOW VIEW DATABASE_NAME.VIEW_NAME;

That shows the actual schema (columnName, columnType) instead of the create statement used to build that View?

N.B. I cannot view the table itself, only the View.

like image 937
boethius Avatar asked Oct 19 '25 16:10

boethius


1 Answers

1.

Teradata SQL Assistant - List Columns

enter image description here

enter image description here

2.

Create a table based on the view results and then use show table.


create table my_table as 
(select * from some_view.some_table)
with no data
no primary index
;

show table my_table
;

3.

Following option 2

select          case when row_number () over (order by c.ColumnId) = 1 then ' ' else ',' end  

            ||  trim (c.ColumnName) 
            ||  ' '

            ||  case    c.columntype

                    when 'AT' then 'time'  
                    when 'BF' then 'byte'
                    when 'BO' then 'blob'
                    when 'BV' then 'varbyte'
                    when 'CF' then 'char'
                    when 'CO' then 'clob'
                    when 'CV' then 'varchar'
                    when 'D ' then 'decimal'
                    when 'DA' then 'date'
                    when 'DH' then 'interval day to hour'
                    when 'DM' then 'interval day to minute'
                    when 'DS' then 'interval day to second'
                    when 'DY' then 'interval day'
                    when 'F ' then 'float'
                    when 'HM' then 'interval hour to minute'
                    when 'HR' then 'interval hour'
                    when 'HS' then 'interval hour to second'
                    when 'I1' then 'byteint'
                    when 'I2' then 'smallint'
                    when 'I8' then 'bigint'
                    when 'I ' then 'int'
                    when 'MI' then 'interval minute'
                    when 'MO' then 'interval month'
                    when 'MS' then 'interval minute to second'
                    when 'N ' then 'number'
                    when 'PD' then 'period(date)'
                    when 'PS' then 'period(timestamp('
                    when 'PT' then 'period(time('
                    when 'SC' then 'interval second'
                    when 'SZ' then 'timestamp with time zone'
                    when 'TS' then 'timestamp'
                    when 'TZ' then 'time with time zone'
                    when 'YI' then 'interval year'
                    when 'YM' then 'interval year to month'                         

                end

            ||  case when c.columntype in ('BF','BV') then '(' || cast (cast (c.ColumnLength            as format '-(9)9') as varchar (10)) || ')'  else '' end
            ||  case when c.columntype in ('CF','CV') then '(' || cast (cast (c.ColumnLength            as format '-(9)9') as varchar (10)) || ') character set ' || case c.CharType when 1 then 'latin' when 2 then 'unicode' end   else '' end           
            ||  case when c.columntype in ('AT','TS') then '(' || cast (cast (c.DecimalFractionalDigits as format '9'    ) as varchar (1))  || ')'  else '' end
            ||  case when c.columntype in ('PS','PT') then '(' || cast (cast (c.DecimalFractionalDigits as format '9'    ) as varchar (1))  || '))' else '' end
            ||  case when c.columntype in ('D'      ) then '(' || cast (cast (c.DecimalTotalDigits      as format '-(9)9') as varchar (10)) || ',' || cast (cast (c.DecimalFractionalDigits   as format '9') as varchar (1)) || ')' else '' end           

            as columns_definitions  


from        dbc.columnsV c

where       c.databasename  =   'my_database'
        and c.tablename     =   'my_table'

order by    c.ColumnId   
;
like image 98
David דודו Markovitz Avatar answered Oct 21 '25 06:10

David דודו Markovitz