Teradata: How to back up a table that uses an identity column?

China☆狼群 提交于 2019-12-11 03:42:47

问题


In Teradata, the way I've been doing backups for tables is like this:

create table xxx_bak as xxx with data

Works great, but I have just discovered that this doesn't work for tables with identity columns.

I need a backup method that can duplicate a table with its data intact so that I can roll it back in case I mess up some data.


回答1:


If you just want a copy of the table, you can create one with the same structure but without making the key column an identity column. You can then insert into it from the original table. However, you wouuldn't be able to insert back into the old table from the backup while retaining the same keys.

The way to make a backup that you can later restore with the same keys is to use the archive/restore tool ARCMAIN.

Backup like this:

logon my_server/my_user, my_password;
archive data tables (my_database.my_table), release lock, file=backup_file;

Restore like this:

logon my_server/my_user, my_password;
restore data tables (my_database.my_table), release lock, file=backup_file;



回答2:


This involves 3 steps:

 1. SHOW TABLE orig_Table; (*Get the DDL*)

 2.  Replace orig_Table with bkp_Table name

 3.  INSERT INTO bkp_Table SELECT * FROM orig_Table;



回答3:


After over a year and a half, I've finally found a slick solution to this issue:

create table mydb.mytablebackup as 
(select * from (select * from mydb.mytable) x) 
with data;

Be sure to qualify the innermost subquery or it won't work.



来源:https://stackoverflow.com/questions/10386043/teradata-how-to-back-up-a-table-that-uses-an-identity-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!