dba_tableSqlList
Retrieve SQL queries executed against a Teradata table within a specified timeframe to analyze database activity and monitor table usage patterns.
Instructions
Get a list of SQL run against a table in the last number of days.
Arguments: table_name - table name no_days - number of days
Returns: ResponseType: formatted response with query results + metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | ||
| no_days | No |
Implementation Reference
- The core handler function implementing the 'dba_tableSqlList' tool. It executes a SQL query to retrieve recent queries against a specified table from Teradata's query log views (DBC.QryLogSqlV and DBC.QryLogV), formats the results using utility functions, and returns a structured response with metadata.def handle_dba_tableSqlList(conn: TeradataConnection, table_name: str, no_days: int | None = 7, *args, **kwargs): """ Get a list of SQL run against a table in the last number of days. Arguments: table_name - table name no_days - number of days Returns: ResponseType: formatted response with query results + metadata """ logger.debug(f"Tool: handle_dba_tableSqlList: Args: table_name: {table_name}, no_days: {no_days}") with conn.cursor() as cur: if table_name == "": logger.debug("No table name provided") else: logger.debug(f"Table name provided: {table_name}, returning SQL queries for this table.") rows = cur.execute(f"""SELECT t1.QueryID, t1.ProcID, t1.CollectTimeStamp, t1.SqlTextInfo, t2.UserName FROM DBC.QryLogSqlV t1 JOIN DBC.QryLogV t2 ON t1.QueryID = t2.QueryID WHERE t1.CollectTimeStamp >= CURRENT_TIMESTAMP - INTERVAL '{no_days}' DAY AND t1.SqlTextInfo LIKE '%{table_name}%' ORDER BY t1.CollectTimeStamp DESC;""") data = rows_to_json(cur.description, rows.fetchall()) metadata = { "tool_name": "dba_tableSqlList", "table_name": table_name, "no_days": no_days, "total_queries": len(data) } logger.debug(f"Tool: handle_dba_tableSqlList: metadata: {metadata}") return create_response(data, metadata)