You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何查询Teradata指定表的检查约束名称及表达式?

Retrieve Check Constraint Details for a Teradata Table

Got it, let's tackle this! You're right that DBC.ConstraintName only gives you the names of check constraints—you need to pair it with another system table to get the actual constraint logic.

The Solution: Join Two System Tables

Teradata stores the check constraint expressions in DBC.CheckConstraints. Here's a straightforward query that combines both tables to pull exactly what you need:

SELECT
  cn.ConstraintName AS constraint_name,
  cc.CheckText AS constraint_expression
FROM
  DBC.ConstraintName cn
INNER JOIN
  DBC.CheckConstraints cc
ON
  cn.ConstraintId = cc.ConstraintId
WHERE
  cn.DatabaseName = '<your_database_name>'
  AND cn.TableName = '<your_table_name>'
  AND cn.ConstraintType = 'C'; -- 'C' filters for check constraints only

Quick Breakdown:

  • Replace <your_database_name> and <your_table_name> with the full qualified parts of your target table (omit the database name if it's your default schema, but including it avoids ambiguity).
  • The ConstraintType = 'C' clause ensures you don't pull in other constraint types like primary keys or foreign keys.
  • You'll need SELECT privileges on both DBC.ConstraintName and DBC.CheckConstraints—if you don't have access, reach out to your Teradata admin for grants.

Example Output (Matching Your Sample Table)

For your table_with_check example, this query would return:

constraint_nameconstraint_expression
CHECK_CONSTRS_BYTEINT > 10

内容的提问来源于stack exchange,提问作者Denis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:36:27