Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

sql - Retrieving column and other metadata information in Teradata

I have a half dozen views in SQL Server that I need to replicate in Teradata, but I haven't been able to find the TD equivalent of the SQL metadata tables. I'd like to replicate the following functionality (which I assume is fairly self-explainatory):

select table_name, column_id ordinal_position, column_name,
   data_type, char_length char_max_length, 
   data_precision numeric_precision, data_scale numeric_scale
from user_tab_columns

select name as FUNCTION_NAME
from sys.objects
where type_desc='SQL_SCALAR_FUNCTION'

select TABLE_NAME as VIEW_NAME
from INFORMATION_SCHEMA.VIEWS

I'd also like to know if there are any usable Teradata references online; everything I run across seems to be advertising rather than practical information.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

All Teradata system tables are stored under DBC schema.

For columns, it is dbc.columns

select * from dbc.columns

For views, it is dbc.tables with a filter on a column something named table_type 'V' (where V stands for Views)

select * from dbc.tables

I am not sure about how to get all functions in Teradata. Whoever knows it, please edit this answer.

In Teradata DBC.Tables contains many of the objects that exist on the system. (e.g. Stored Procedures, UDF, Triggers, Macros, Views, Tables, Hash Index, Join Index, etc.) The column Table Kind is used to identify the type of object.

SELECT *
FROM DBC.TABLES
WHERE TABLEKIND = '<see below>'

A = Aggregate Function
B = Combined Aggregate Function and ordered analytical function
D = JAR
E = External Stored Procedure
F = Standard Function
G = Trigger
H = Instance or Constructor Method
I = Join Index
J = Journal
M = Macro
N = Hash Index
O = No Primary Index (Table)
P = Stored Procedure
Q = Queue Table
R = Table Function
S = Ordered Analytical Function
T = Table
U = User-defined data type
V = View
X = Authorization
Y = GLOP Set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...