13 May 2018 · n-pacha ·       Add to Favorites   Report

Create Macro in Teradata

Macro is a set of SQL statements which are stored and executed by calling the Macro name. The definition of Macros is stored in Data Dictionary. Users only need EXEC privilege to execute the Macro. Users don't need separate privileges on the database objects used inside the Macro. 

  • Macro statements are executed as a single transaction. If one of the SQL statements in Macro fails, then all the statements are rolled back
  • Macros can accept parameters
  • Macros can contain DDL statements, but that should be the last statement in Macro

Syntax:

CREATE MACRO macroname(parameter1, parameter2,..) (

<sql statements>

);

Example:

CREATE MACRO Get_Emp_Salary(EmployeeNo INTEGER) AS (

SELECT * FROM Salary WHERE EmployeeNo = :EmployeeNo;

);

n-pacha

posted on 13 May 2018

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied