{"id":27337,"date":"2022-02-22T12:45:05","date_gmt":"2022-02-22T12:45:05","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=27337"},"modified":"2022-12-23T06:48:52","modified_gmt":"2022-12-23T06:48:52","slug":"teradata-objects","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/teradata-objects\/","title":{"rendered":"What is Teradata Objects? A Tutorials &#038; Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"teradata-objects\">Teradata Objects<\/h2>\n\n\n\n<p>Below are the list of objects contains in Teradata database or User:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Tables<\/strong>\u2013rows and columns of data<\/li><li><strong>Views<\/strong>\u2013predefined subsets of existing tables<\/li><li><strong>Macros<\/strong>\u2013predefined, stored SQL statements<\/li><li><strong>Triggers<\/strong>\u2013SQL statements associated with a table<\/li><li><strong>Stored Procedures<\/strong>\u2013program stored within Teradata<\/li><li><strong>User-Defined Function<\/strong>\u2013function (C program) to provide additional SQL functionality<\/li><li><strong>Join and Hash Indexes <\/strong>\u2013separate index structures stored as objects within a database<\/li><li><strong>Permanent Journals<\/strong>\u2013table used to store before and\/or after images for recovery<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"834\" height=\"681\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-59.png\" alt=\"\" class=\"wp-image-27338\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-59.png 834w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-59-300x245.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-59-768x627.png 768w\" sizes=\"auto, (max-width: 834px) 100vw, 834px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"important-note\"><strong>Important Note:<\/strong> <\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Objects which require permanent spaces are:- <strong>Tables , Triggers, Stored Procedures, User-Defined Function, Join and Hash Indexes &amp; Permanent Journals<\/strong><\/li><li> Objects which not require permanent spaces are:- <strong>Macros<\/strong> &amp; <strong>Views<\/strong><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Join and Hash Indexes <\/strong> and <strong>Permanent Journals<\/strong> &#8211; These aren&#8217;t directly accessed by users (these will be explained in details in another blog)<\/li><li>These objects are created, maintained, and deleted using <strong>SQL<\/strong>.<\/li><li>Object definitions are stored in the <strong>DD\/D<\/strong>.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-data-dictionary-directory-dd-d\">What is The Data Dictionary Directory (DD\/D)<\/h2>\n\n\n\n<p>(It will be explained in details in another topic)<\/p>\n\n\n\n<p>All Objects definitions are stored in the <strong>DD\/D<\/strong>. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"the-dd-d\">The DD\/D<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>is an integrated set of system tables<\/li><li>contains definitions of and information about all objects in the system<\/li><li>is entirely maintained by the Teradata Database<\/li><li>is \u201cdata about the data\u201d or \u201cmetadata\u201d<\/li><li>is distributed across all AMPs like all tables<\/li><li>is normally accessed via Teradata supplied views<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"examples-of-dd-d-views\">Examples of DD\/D views:<\/h4>\n\n\n\n<p>DBC.TablesV- information about objects (e.g., tables) in a database\/user<br>DBC.UsersV- information about all users<br>DBC.AllRightsV- information about access rights<br>DBC.AllSpaceV- information about space utilization <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"teradata-objects-in-details\">Teradata Objects in Details:<\/h2>\n\n\n\n<p>Below are the four important Teradata objects explained in details:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-tables\">1. Tables <\/h2>\n\n\n\n<p>It contains rows and columns<\/p>\n\n\n\n<p>To create and store the table structure definition in the DD\/D, you can execute the CREATE TABLE DDL statement<\/p>\n\n\n\n<p>examples:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"325\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-60.png\" alt=\"\" class=\"wp-image-27343\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-60.png 719w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-60-300x136.png 300w\" sizes=\"auto, (max-width: 719px) 100vw, 719px\" \/><\/figure>\n\n\n\n<p>Above definition is stored in DD\/D<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-views\">2. Views<\/h2>\n\n\n\n<p>Views are pre-defined filters of existing tables consisting of specified columns and\/or rows from the table(s).<\/p>\n\n\n\n<p>A single table view:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>is a subset of an underlying table<\/li><li>allows users to read and update a subset of the underlying table<\/li><li>has no data of its own<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"539\" height=\"321\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-61.png\" alt=\"\" class=\"wp-image-27345\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-61.png 539w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-61-300x179.png 300w\" sizes=\"auto, (max-width: 539px) 100vw, 539px\" \/><\/figure>\n\n\n\n<p>A multi-table:<\/p>\n\n\n\n<p>A multi-table view allows users to access data from multiple tables as if it were in a single table.<br>Multi-table views (i.e., join views) are used for reading only, not updating.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"792\" height=\"432\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-62.png\" alt=\"\" class=\"wp-image-27346\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-62.png 792w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-62-300x164.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/image-62-768x419.png 768w\" sizes=\"auto, (max-width: 792px) 100vw, 792px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-macros\">3. Macros<\/h2>\n\n\n\n<p>A MACRO is a predefined set of SQL statements which is logically stored in a database.<\/p>\n\n\n\n<p>Macros have many features and benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Simplify end-user access<\/li><li>Control which operations may be performed by users<\/li><li>May accept user-provided parameter values<\/li><li>Are stored in the Teradata Database, thus available to all clients<\/li><li>Reduces query size<\/li><li>Are optimized at execution time<\/li><li>May contain multiple SQL statements<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-create-a-macro\">To create a macro:<\/h4>\n\n\n\n<p>CREATE MACRO Customer_ListAS (SELECT CustNameFROM Customer;);<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-execute-a-macro\">To execute a macro:<\/h4>\n\n\n\n<p>EXEC Customer_List;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-replace-a-macro\">To replace a macro:<\/h4>\n\n\n\n<p>REPLACE MACRO Customer_ListAS(SELECT CustNumber, CustNameFROM Customer;);<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-stored-procedures\">4. <strong>Stored Procedures<\/strong><\/h2>\n\n\n\n<p>A stored procedure contains a set of SQL statements and procedural statements. <\/p>\n\n\n\n<p>They consist of a set of control and condition handling comments that make SQL a computationally complete programming language. <\/p>\n\n\n\n<p>The definition of the stored procedure is stored in the database, and the parameters are stored in data dictionary tables.<\/p>\n\n\n\n<p>Teradata procedure support most of the operations, for example<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Insert \/ Update \/ Merge \/ Delete<\/li><li>Drop \/ Truncate \/ Create Table\/View<\/li><li>Collect Statistics<\/li><li>Procedure Calls<\/li><li>Iteration[For\/While loop]<\/li><li>Cursors<\/li><li>Variable manipulation<\/li><li>Conditions [If\/ELSE]<\/li><\/ul>\n\n\n\n<p>Teradata procedures can be of two types:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>General Procedure:<\/strong>&nbsp;Procedure that performs some action in the background<\/li><li><strong>Dynamic procedure:<\/strong>&nbsp;Procedures that returns result set\/query result<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"advantages-of-using-stored-procedures\">Advantages of using Stored Procedures:<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Stored procedures reduce the network load between the client and the server.<\/li><li>It provides better security since the data is accessed through stored procedures instead of accessing them directly.<\/li><li>It gives better maintenance since the business logic is tested and stored in the server.<\/li><\/ul>\n\n\n\n<p><strong>Syntax<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-create-a-procedure\">To Create <strong>a PROCEDURE .<\/strong><\/h4>\n\n\n\n<p>CREATE&nbsp;PROCEDURE&nbsp;&lt;procedurename&gt;&nbsp;(&nbsp;[parameter&nbsp;1&nbsp;data&nbsp;type,&nbsp;parameter&nbsp;2&nbsp;data&nbsp;type..]&nbsp;)&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>BEGIN&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&lt;SQL&nbsp;or&nbsp;SPL&nbsp;statements&gt;;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>END;&nbsp;&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Examples:<\/strong><\/p>\n\n\n\n<p>Consider the following Salary Table of the employees.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>CompanyID<\/th><th>Income<\/th><th>Taxpay<\/th><th>Totalpay<\/th><\/tr><tr><td>202001<\/td><td>40,000<\/td><td>2,000<\/td><td>38,000<\/td><\/tr><tr><td>202002<\/td><td>80,000<\/td><td>3,000<\/td><td>77,000<\/td><\/tr><tr><td>202003<\/td><td>85,000<\/td><td>5,000<\/td><td>80,000<\/td><\/tr><tr><td>202004<\/td><td>90,000<\/td><td>2,000<\/td><td>88,000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The following example creates a stored procedure named Insert Salary to accept the values and insert them into the Salary Table.<\/p>\n\n\n\n<p>CREATE&nbsp;PROCEDURE&nbsp;InsertSalary&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>(&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;IN&nbsp;in_CompanyID&nbsp;INTEGER,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;IN&nbsp;in_Income&nbsp;INTEGER,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;IN&nbsp;in_Taxpay&nbsp;INTEGER,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;IN&nbsp;in_Totalpay&nbsp;INTEGER&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>)&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>BEGIN&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;INSERT&nbsp;INTO&nbsp;Salary&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>(&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CompanyID,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Income,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Taxpay,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Totalpay&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;)&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;VALUES&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>(&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:in_CompanyID,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:in_Income,&nbsp;&nbsp;&nbsp;,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:in_Taxpay,&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:in_Totalpay&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;);&nbsp;&nbsp;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>END;&nbsp;&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-execute-stored-procedures\">To Execute Stored Procedures:<\/h4>\n\n\n\n<p>CALL&nbsp;&lt;procedure&nbsp;name&gt;&nbsp;[(parameter&nbsp;values)];&nbsp;&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-compiling-procedure\">To Compiling Procedure:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">.COMPILE FILE [procedure_file];\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-get-procedure-code\">To Get Procedure Code:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">SHOW PROCEDURE [database_name.procedurename];\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"to-drop-procedure\">To Drop Procedure:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">DROP PROCEDURE [database_name.procedurename];\n\n\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Teradata Objects Below are the list of objects contains in Teradata database or User: Tables\u2013rows and columns of data Views\u2013predefined subsets of existing tables Macros\u2013predefined, stored SQL statements Triggers\u2013SQL statements&#8230; <\/p>\n","protected":false},"author":48,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[7338],"tags":[],"class_list":["post-27337","post","type-post","status-publish","format-standard","hentry","category-teradata"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/27337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=27337"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/27337\/revisions"}],"predecessor-version":[{"id":27380,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/27337\/revisions\/27380"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=27337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=27337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=27337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}