2

I am curious to run a SQL-query via a .Bat script to see the "current usage" of a database.

I currently run the query below via an ODBC connection in Teradata SQL Assistant. It gives me what I think is the current usage. But I would like to run from Command Line, via a Bat file instead.

/* Check Current Heavy Users Teradata SQL Assistant */
SELECT UserName
/*,AccountName */
,Sum (CPUTIME)
,Sum (DiskIO) / 1024 / 1024 AS DiskIO_MB
FROM DBC.AMPUsage
GROUP BY 1
ORDER BY 3 DESC

I want to be able to run the .Bat script to output the same result as the query would in SQL Assistant. This would give me a quick overview of the server capacity.

dady7749
  • 125
  • 3
  • 11
  • 4
    `bteq` is the command line interface for Teradata. Get that installed from their TTU install (generally how you install ODBC, but click the "bteq" checkbox) and then you can interact with Teradata from the command line. – JNevill Apr 16 '19 at 13:01

1 Answers1

1

The command line interface to Teradata (similar to sqlplus in Oracle) is bteq.

It can be installed as part of Teradata Tools and Utilities (TTU).

A typical way to run it in batch mode is:

bteq -c UTF8 < script.bteq

Where script.bteq looks like this:

.logon host_or_IP/login,password
.set MAXERROR 1
database db_name;
SELECT ...;
Nickolay
  • 31,095
  • 13
  • 107
  • 185