How to extract column names from a table using Teradata SQL

Database
Enthusiast

How to extract column names from a table using Teradata SQL

Could anyone please help me with the Teradata SQL query to "SELECT" all the column name from of a table created into a database which is created in the DBC from example database name: Demo and table name:Temp1.

I can see view defination under DBC to extract the teradata columnnames from the DBC database. However, Is there any standard SQL command that I can use to extract the columname from a table within teradata database.
Tags (1)
7 REPLIES
Enthusiast

Re: How to extract column names from a table using Teradata SQL

Try something like this...

SELECT ColumnName
FROM DBC.Columns
WHERE DatabaseName='Demo'
AND TableName='Temp1';

OR

SELECT FieldName
FROM DBC.TVFIELDS WHERE TABLEID =
(SELECT
TVMID
FROM DBC.TVM
WHERE TVMNAME = 'Temp1'
AND DATABASEID =
(SELECT DATABASEID FROM DBC.DBASE WHERE DATABASENAME = 'Demo'));

Hope this helps,

Regards
Meem

Re: How to extract column names from a table using Teradata SQL

Could you plz tell me how to create nickname for a database in teradata

Enthusiast

Re: How to extract column names from a table using Teradata SQL

You can create the alias names for the tables/views in SQL statement but not for the database...

Fan

Re: How to extract column names from a table using Teradata SQL

Hi All,

How to collect the columns if the table is having joins and added with that if two tables have same column name how could we differentiate which column came from which table.

Expecting early response

Regards,

Ranjith 

Fan

Re: How to extract column names from a table using Teradata SQL

In the above question (collect the columns) in the sense column names only(without data in the resultset)

Teradata Employee

Re: How to extract column names from a table using Teradata SQL

Hi,

_in a query_ you should give an alias to each table.   Then use alias to distinguish between different tables, even if two tables have the same column name, then <alias_name.column_name> will give you exactly what you want.

The use of dbc.columns refers to the table structure itself.   It does not refer to individual queries where one table can be used multiple times (with different aliases).

Regards,

Vlad.

Re: How to extract column names from a table using Teradata SQL

 

select columnname from dbc.columns

where tablename='Table_Name'