Creating a Macro in Teradata

Create macro< macro  name>(<params>)AS(SQL Queries);


Replacing a Macro in Teradata

Replace macro< macro  name>(<params>)AS(SQL Queries);


Droping  a Macro in Teradata

Drop macro< macro  name>


Viewing a Macro in Teradata

SHOW macro< macro  name>


Executing a Macro in Teradata

Exec < macro  name>(<params>) OR Execute< macro  name>>(<params>) CREATE macro mc – party2 (partyid1 integer)

As(Select* From party where party id =:party id1 or party name> :party income1;)

Exe mc- party2 (2,20000)

Interested in mastering Teradata Training? Enroll now for FREE demo on Teradata Training.

Using Macros to preserve integrity MACROS may be used for either of the following purpose: 2To insure data integrity that the data conforms to certain or value restrictions 2To insure referential integrity that the data being input as foreign keys have legal primary key values else where in the database Create a s macro which inserts a new party member row with the following restrictions 2Party must be over 21 years of age 2Party must be assigned a valid party code. 2Create macro new – party (pid integer, pname varchar(30),pcode integer, Hired data, birth date)

Learn more about Teradata Interview Questions in this blog post.

As(Roll back work ’Invalid Here’)

Where(:Hired- birth)/365<21;

Roll back work ’Invalid party code’

Where: pcode not in (Select party code from party where party code =: pacode);

Insert into party(Party id, party name, party code, j date)

Values(:pid: p name, :p code: hired););



  exe new party (19,’meer’, 40,’2010-08-06’,’2010-08-06’)



exe new  party(19,’meer’,40,’2010-08-06,’’1981-08-06’)

For Indepth knowledge on Teradata click on: