Tuesday, October 23, 2012

Teradata Questions - SQL Queries


Number of nodes in a system

select count(distinct(nodeid)) from dbc.resusagescpu

To find database size

select sum(currentPerm) from DBC.diskspace where databasename='mydb'

To find table size

select sum(currentperm) from DBC.tablesize where databasename='mydb' and tablename='mytable'

To find version of terdata

select * from dbc.dbcinfo

To find CPU time consumed

select username,accountname,sum(CPUTIME) from dbc.ampusage where username='xyz' group by 1,2

To find the space used by each table in MB's in a database

select tablename,sum(currentperm)/1024/1024 MB
from DBC.AllSpace
where databasename='mydb'
group by 1

To identify skewness

SELECT
   DatabaseName,
   TableName,
   SUM(CurrentPerm) AS CurrentPerm ,
   SUM(PeakPerm) AS PeakPerm,
   (100 - (AVG(CurrentPerm)/MAX(CurrentPerm)*100)) AS SkewFactor
  FROM DBC.TableSize
 WHERE databasename =  database
   AND TableName IN ('SALES' , 'CUSTOMERS')
 GROUP BY 1,2
 ORDER BY SkewFactor DESC;

No comments:

Post a Comment