DEFAULT Function Examples | Teradata Vantage - Example: Inserting the Default Value under Certain Conditions - Analytics Database - Teradata Vantage

SQL Functions, Expressions, and Predicates

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-01-12
dita:mapPath
obm1628111499646.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
kby1472250656485
lifecycle
latest
Product Category
Teradata Vantageā„¢

Consider the following Employee table definition:

   CREATE TABLE Employee
      (Emp_ID      INTEGER
      ,Last_Name   VARCHAR(30)
      ,First_Name  VARCHAR(30)
      ,Dept_No     INTEGER DEFAULT 99
   );

The following statement uses DEFAULT to insert the default value of the Dept_No column when the supplied value is negative.

   USING (id INTEGER, n1 VARCHAR(30), n2 VARCHAR(30), dept INTEGER)
   INSERT INTO Employee VALUES
      (:id
      ,:n1
      ,:n2
      ,CASE WHEN (:dept < 0) THEN DEFAULT(Dept_No) ELSE :dept END
   );