Teradata: Common Queries

Get all tables in a database

            SELECT  TableName
            FROM    DBC.TablesV
            WHERE   TableKind = 'T'
            and     DatabaseName = ?
            ORDER BY    TableName;            

Get all Views in a database

SELECT  TableName
            FROM    DBC.TablesV
            WHERE   TableKind = 'V'
            and     DatabaseName = ?
            ORDER BY    TableName;            

Get # of rows in a table

SELECT  count(*) FROM    database.table

Get Column Info (information about columns) in a table

SELECT *        FROM dbc.ColumnsV WHERE databasename = ? AND tablename = ?";        

Get Table Size (size of table)

select sum(currentperm) from dbc.tablesize where tablename=? and databasename=?";

Get Teradata Version

SELECT * FROM dbc.dbcinfo;

Connect using default mechanism

Below I am using bteq.

.logon <server>/<user>

Connect using LDAP

.logmech LDAP
.logdata
.logon <server>/<user>

List all databases

SELECT DatabaseName, OwnerName FROM DBC. DATABASESV WHERE DBKind = 'D';
This entry was posted in Computers, programming, Software. Bookmark the permalink.

Leave a comment