All Forums Database
prakash5801 8 posts Joined 02/10
25 May 2010
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.

Meem 24 posts Joined 05/07
25 May 2010

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

anamikap 3 posts Joined 01/13
31 Jan 2013

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

Qaisar Kiani 337 posts Joined 11/05
31 Jan 2013

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

Ranji 2 posts Joined 07/13
22 Jul 2013

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 

Ranji 2 posts Joined 07/13
22 Jul 2013

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

VBurmist 96 posts Joined 12/09
23 Jul 2013

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.

2aravinth 3 posts Joined 07/13
24 Jul 2013

 
select columnname from dbc.columns
where tablename='Table_Name'

You must sign in to leave a comment.