TD123
TD123

Reputation: 27

convert t-sql statement to teradata

I am trying to understand the equivalent of this statement

IF OBJECT_ID('Current') IS NOT NULL 
   DROP TABLE Current; 

in Teradata.

Can someone help me out converting this statement to TD14. Thank you!

Upvotes: 0

Views: 1057

Answers (1)

Andrew
Andrew

Reputation: 8693

You can do this in at least newer versions of TD:

select
count (*)
from
dbc.tablesv where tablename = '<your table>'
and databasename = '<your db>'

having count (*) > 0;

.if activitycount = 1  then .GOTO DropTable;
.if activitycount <> 1  then .quit;

.LABEL DropTable
select 'DROP TABLE!';
drop table <your db>.<your table>;

Sadly enough, this won't work with volatile tables. If they are global temporary tables, you can use select count (*) from dbc.AllTempTablesVX where B_tablename =

Upvotes: 1

Related Questions