SQL Used to Create a Macro - Teradata Vantage - Analytics Database

Database Introduction

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-11-21
dita:mapPath
gtm1628096154303.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
dsm1472253642401
lifecycle
latest
Product Category
Teradata Vantage™

To create a macro, use the CREATE MACRO statement.

For example, the following statement defines a macro for adding new employees to the Employee table and incrementing the EmpCount field in the Department table.

CREATE MACRO NewEmp (name VARCHAR(12),
                     number INTEGER NOT NULL,
                     dept INTEGER DEFAULT 100
                    )
AS (INSERT INTO Employee (Name,
                          EmpNo,
                          DeptNo
                         )
    VALUES (:name,
            :number,
            :dept
           )
    ;
    UPDATE Department
    SET EmpCount=EmpCount+1
    WHERE DeptNo=:dept
    ;
   )
;

This macro defines parameters for which you must provide values each time you run the macro. A leading colon (:) indicates a reference to a parameter within the macro.