You can create a stored procedure owned by SYSDBA or another user at the administrator level, with the corresponding DROP TABLE and CREATE TABLE privileges, which perform the following actions:
- Check DBC.Tables to see if the object exists.
- If the object exists, leave it.
- Run DDL to recreate the table:
CREATE TABLE <TargetDB>.<TargetTable> AS <SourceDB>.<SourceTable> WITH DATA AND STATS;
You can make it more dynamic by accepting additional parameters about whether data and / or statistics should be copied to a new table.
If you use BTEQ, you can do something similar (the syntax of the BTEQ commands may be a little bit, but close enough to get the point):
SELECT 1 FROM DBC.TABLES WHERE DatabaseName = '<TargetDB>' AND TableName = '<TargetTable>' AND TableKind = 'T' .IF ACIVITYCOUNT = 0 THEN GOTO CreateNewTable; DROP TABLE <TargetDB>.<TargetTable>; .IF ERRORCODE = 3807 THEN GOTO CreateNewTable; .IF ERRORCODE > 0 THEN .QUIT ERRORCODE; .LABEL CreateNewTable; CREATE <TargetDB>.<TargetTable> AS <SourceDB>.<SourceTable> WITH DATA AND STATISTICS;
source share