Ani*_*kur 4 sql database oracle backup plsql
我为我的国家/地区表创建了备份.
create table country_bkp as select * from country;
Run Code Online (Sandbox Code Playgroud)
我应该用什么SQL将country
表恢复到原始状态?我可以
insert into country select * from country_bkp;
Run Code Online (Sandbox Code Playgroud)
但它只会有重复的条目,可能会失败,因为主键是相同的.
是否有用于合并数据的SQL命令?
最后的选择是
DROP TABLE country;
create table country as select * from country_bkp;
Run Code Online (Sandbox Code Playgroud)
但我想避免这种情况,因为所有人grants/permissions
都会因此而迷失方向.
其他更干净的方式
delete from country ;
insert into country select * from country_bkp;
Run Code Online (Sandbox Code Playgroud)
但我正在寻找更多的合并方法,而无需从原始表中清除数据.
而不是丢弃表,正如您所指出的那样,它会丢失所有权限定义,您可以truncate
只删除所有数据,然后插入 - 选择旧数据:
TRUNCATE TABLE country;
INSERT INTO country SELECT * FROM county_bkp;
Run Code Online (Sandbox Code Playgroud)
就我而言,INSERT INTO country SELECT * FROM county_bkp;
没有用,因为:
indentity_insert
。TimeStamp
列。在这种情况下:
identity_insert
在OriginalTable
OriginalTable
(排除TimeStamp
列)的所有列,并从(排除列)Values
中选择所有列BackupTable
TimeStamp
例子:
Set Identity_insert OriginalTable ON
insert into OriginalTable (a,b,c,d,e, ....) --[Exclude TimeStamp Columns here]
Select a,b,c,d,e, .... from BackupTable --[Exclude TimeStamp Columns here]
Set Identity_insert OriginalTable Off
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9988 次 |
最近记录: |