Do we have a Rank function for this requirement ? - response (1) by srivigneshkn
Hot Standby Node - response (2) by RAMKUMAR.9298
Thank you very much Fred. It answers my question.
teradata insert to identity column? - forum topic by leaca
Generate a Alphanumeric ID - forum topic by ajaypratap
Hello Folks,
I have to create logic to generate 15 character alphanumeric id in this format during INSERT SQL:
- First three character would be static, say "OFFR"
- Next 6 character would be the date in one of the table
- Last last five character would be the number form 1 to 99999
For example first inseted row will have ID as OFFR11021600001,next can be OFFR13021600002 .
Generate a Alphanumeric ID - response (1) by sakthikrr
Hi,
Please refer the below link on generating the Sequential numbers Teradata.
https://forums.teradata.com/forum/database/best-way-to-generate-the-sequential-numbers-csum-or-identity-columns
You can concatenate the static text 'OFFR'& date along with that.
How Compression Works - response (6) by vlcik
Dieter, Nishant,
just to add the formula above differs for nullable and not nullable columns. Don't forget you need to save that extra state for "NULL" which is compressed implicitely for nullable columns. To describe further, I will work with the word STATE:
1) NULLABLE - NULL, (not compressed), ValueA, ValueB - 2 items on compression list, 4 states to be coded -> 2 presence bits required
2) NOT NULLABLE - (not compressed), ValueA, ValueB, ValueC - 3 items on compression list, 4 states to be coded -> 2 presence bits required
N presence bits can be used to code up 2^N states. Therefore you need n=[log(2)(k+2)] bits to code (k) nullable columns and n=[log(2)(k+1)] for not nullable...
Long story short - the ideal number of items on compression list is:
1) NULLABLE - (0),2,4,8,16... (0 means only compress)
2) NOT NULLABLE - 1,3,7,15...
If you need to go deeper, feel free to ask :)
Vlcik
Dynamic SQL and SELECT INTO - response (2) by Vivek79
Hi,
I need to execute the below query in teradata. Is there any way to achieve this?
SET l_sql = 'SELECT max('||l_rid_col||'), MAX(mentx_cid) INTO c2, c3 FROM '||p_database||'.'||p_table;
How Compression Works - response (7) by dnoeth
Hi Vlcik,
nope, the NULL is already included :-)
See Number of Presence Bits Required to Represent Compressed Values in the Database Design manual:
http://www.info.teradata.com/HTMLPubs/DB_TTU_15_10/Database_Management/B035_1094_151K/Database_Level_Capacity_Planning.064.031.html#ww19308315
DDL for entire database - forum topic by tenderfoot
Dear All
I'm new to the Teradata database and have good back ground with DB2 on LUW.
We have project for Migrating Teradata database from one server to the other. As part of this we have to extract DDL from source for all objects (Tables, View, Roles, Macros etc) and create it on the Target.
Is there a tool like db2look (to generate the DDL for the entire database) in Teradata where in I can get the DDL for entire database?
For tables and views, I was able to use below. However, am stuck with other objects.
sel 'show table ' || databasename ||'.'|| tablename ||';' from dbc.tables where databasename = 'dbname' and tablekind = 'T';
sel 'show view ' || databasename ||'.'|| tablename ||';' from dbc.tables where databasename = 'dbname' and tablekind = 'V';
Please help.
DBC ARCHIVE LOGGING Objects V help - forum topic by B_M
Hi,
I have a script that runs nightly after a backup job that finds and turns off archive enabled tables. I do this through bteq from the server and I also have a select statement against the DBC.ArchiveLoggingObjsV; to see when the database, table, and timestamp when an object was placed with archive online. But for some reason, it doesnt display the tablename (TVMNAME) or timestamp (CreateTimeStamp) columns through bteq. I have 14.10v in my environment. How do I make these columns appear through bteq?
Any help is greatly appreciated.
How Compression Works - response (8) by vlcik
Dieter,
thanks for the link. I see the information in the documentation contradictory though. As stated in one of the tables, it says:
col_1 CHAR(1) NOT NULL COMPRESS (‘A’) - requires 1 presence bit
col_1 CHAR(1) COMPRESS (‘A’) - requires 2 presence bits
Therefore NULL is not included, in fact nullability requires 1 extra state to be "coded" using presence bits and thus requires the extra presence bit in the case above. The only explanation would be that Teradata stores the information about nullability in a extra separate (presence?) bit, which would be very uneffective. The number of states to be represented by presence bits obviously differs - since compressing null values with COMPRESS is implicit and can't be skipped.
If I'm in fact wrong, can't you tell me why there is difference in the case above?
DDL for entire database - response (1) by srivigneshkn
1. The following statements would give the DDL's for view and table.
Select Requesttext from dbc.tables where tablekind='V'; -- View.
Select Requesttext from dbc.tables where tablekind='T'; -- Table.
2. However, in cases when the DDL was altered after a create statement , this would only give the latest DDL that was executed.
3. An alternative way is to prepare the show table, show view statements and run it via bteq looping through each line and exporting each command to a file.
Need help to implement the logic - response (11) by srivigneshkn
Query:
select a.tt_id,b.priority_id as StartPriority,a.priority_id as EndPriority from priority a
inner join priority b on (a.tt_id=b.tt_id and a.priority_id>b.priority_id) order by a.tt_id
O/P:
TT_Id StartPriority EndPriority
------- -------------- --------------
1201 1 2
1203 1 3
1204 2 3
Regards,
Srivignesh KN
Generate a Alphanumeric ID - response (3) by srivigneshkn
I was able to manipulate with the following statement.
select 'OFFR'||insertdt||trim(row_number() over (order by 1 desc)) from Tablename.
1. 'OFFR' is the static character
2. Insertdt is the date from your table.
3. Row_Number for the identity column.
This would give you the desired output.
If you want to have additional zeros you can pad zeros before the rownumber statement as well.
Regards,
Srivignesh KN
Recursive Query to List down the Lineage for a Particular Table with Immediate Parents - forum topic by himanshugaurav
Hi All
I have require to list down the lineage for a particular table as below:
Source --> Target1
Target1 --> Target2
Target1 --> Target 3
Target2 --> Target 4
Here the target become the source and so on. I used a recursive query but it is not giving me immediate parent but the source parent and data looks as below :
Source --> Target1
Source --> Target2
Source --> Target 3
Source --> Target 4
As we all know that there can be multiple views on a table , and then each of these views can be exposed in deifferent application via some new views on top of them .
I am trying to list it .
If anyone has already implemented this , Please share your inputs.
Regards
Himanshu
Execute Dynamic Select into string in Teradata - forum topic by Vivek79
This is the MYSQL query, now I need this below dynamic query to be execute in TERADATA SQL.
set l_sql=concat('SELECT max(',l_rid_col,'), MAX(cid) INTO @c2, @c3 FROM ',p_database,'.',p_table);
SET l_rid = @c2;
SET l_cid = @c3;
And this update query:
update table_a set row =ifnull(l_rid, 0),
column= ifnull(l_cid, 0) where databasename=p_database and tablename=p_table;
But in Teradata, I tried this way:
update table_a as a from (select max(l_rid) TR, MAX(l_cid) TCC from DEVP.employees )as b
set a.row= b.TR , a.column=b.TCC where a.databasename='DEVP' and a.tablename='employees';
But i'm getting this error:
STATEMENT 1: Update Statement failed. Elapsed time = 00:00:00.015 Executed as Single statement. Failed [3993 : HY000] Illegal usage of alias name.
Are we having any solution for this, in teradata?
Execute Dynamic Select into string in Teradata - response (1) by Vivek79
I got the answer, here
update table_a from (select max(l_rid) TR, MAX(l_cid) TCC from DEVP.employees )as b set row= b.TR , column=b.TCC where databasename='DEVP' and tablename='employees';
ISSUE: I just removed the alias name in UPDATE. finally got it.
How to decide compression? - response (2) by vlcik
Hi Yurij,
The quick answer on compression would be: use sampling and 1% rule.
Now if you continued reading, I can give you a bit more insight into your task. If you want to get optimal multi-value compression list, you would need to understand how presence bits work in TD. It might be beneficial to add less frequent values than 1% also or remove a few. The optimal number of values in compression list also depends on given the datatype (you get way more savings from compressing CHAR(20) than CHAR(2)). I've added some coments on presence bits here, check it out:
http://forums.teradata.com/forum/database/how-compression-works/
Also consider, whether the value could be subject to change (the optimum needs to be reviewed on a regular basis for critical tables) plus there are obviously wrong columns to consider compression (i.e. BUSINESS_DATE on a daily refreshed table).
Last but not least, there is procedure/macro available to do this semi-automatically table by table. Most importantly, if you want to check your DWH fully and do this task automatically, there are few great tools. We've been using tool named ATO on our project, it worked as a charm and it reviews also data-types, 1-click deployment, check out http://www.ato-tool.com/
Find table size and last access date - response (7) by varanasianup
All,
ObjectUseCountCollectRate is enabled(>0), Usecount is also enabled, but still i could find LastAccesstimestamp= null for few tables in a DB.
I observed if a table is defined on a NOPI, then LastAccesstimestamp=NULL, Somebody correct me here please.
Recursive SQL with update query - forum topic by Keep Smiling
I want to use the results obtained from a recursive query to update a table data. How can i do it.
for eg.
with RECURSIVE CTE (A,B,FLG) AS(
SELECT A,B,1 FROM TABLE1
UNION ALL
SELECT A,B,CASE WHEN A=3 THEN 1 ELSE 0 END FROM CTE WHERE FLG=1)
UPDATE TABLE1
FROM (SELECT A FROM CTE WHERE FLG=1 QUALIFY ROW_NUMBER() OVER( PARTITION BY A ORDER BY A)=1) TMP
SET A=TMP.A;
Can anyone help me in it.
The following query should work for this requirement.
select key_col,val,percent_rank () over (order by val desc) as Rank_value_needed from Table;
Output :
Key Col Val Rank_Value_Needed
-------- --- -------------------------
E 10,344 0.000000
C 56 0.100000
F 7 0.200000
D 7 0.200000
H 6 0.400000
G 6 0.400000
CC 2 0.600000
B 2 0.600000
AA 2 0.600000
BB 2 0.600000
A 0 1.000000
Thanks & Regards,
Srivignesh KN