HIVE中DROP TABLE IF EXISTS

时间: 2023-12-30 07:39:52 浏览: 268
在Hive中,使用DROP TABLE IF EXISTS命令可以删除表。\[1\]该命令可以确保在删除表之前先检查表是否存在,如果存在则删除表。如果表不存在,则不执行任何操作。这个命令可以用来避免在删除表时出现错误。另外,如果要删除一个库,可以使用DROP DATABASE IF EXISTS命令。\[1\]在删除表时,还可以使用TRUNCATE TABLE命令来删除表中的数据,但是注意,TRUNCATE TABLE不能删除外部表的数据,因为外部表的数据并不是存放在Hive Metastore中。\[3\]如果想要删除外部表的数据,可以将外部表转换为内部表或者直接删除HDFS文件。 #### 引用[.reference_title] - *1* [【Hive】删除表(drop、truncate)](https://blog.csdn.net/weixin_31866177/article/details/113864827)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [记一次hive drop table 卡死的事故](https://blog.csdn.net/qq1226317595/article/details/84306519)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Hive操作——删除表(drop、truncate)](https://blog.csdn.net/u013185349/article/details/106191780)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
阅读全文

相关推荐

set hive.exec.dynamic.partition.mode=nonstrict; set hive.exec.parallel=true; set hive.exec.parallel.thread.number=30; --drop table if exists dm_finrisk.dm_event_walletSettleSuccessEvent_di; create table if not exists dm_finrisk.dm_event_cashLoanEvent_di( event_uuid string ,event_code string ,dt string ,event_time string ,rawSnapshot string ) COMMENT 'cashLoanEvent' PARTITIONED BY ( day bigint)stored as parquet; drop table if exists tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")}; create table if not exists tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")} as select uuid as event_uuid ,event as event_code ,from_unixtime(unix_timestamp(cast(day as string),'yyyymmdd'),'yyyy-mm-dd') as dt ,from_unixtime(cast(cast(time AS BIGINT)/1000 AS BIGINT),'yyyy-MM-dd HH:mm:ss') as event_time ,get_json_object(data,'$.hotPublish.rawSnapshot') as rawSnapshot from dm_finrisk.ods_event_hdfs_snapshot_di where code = 'shield@cashLoanEvent' and day=${zdt.addDay(-1).format("yyyyMMdd")} drop table if exists tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")}; create table if not exists tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")} as select event_uuid ,event_code ,dt ,event_time ,rawSnapshot from tmp.tmp_dm_event_cashLoanEvent_di_01_${zdt.addDay(-1).format("yyyyMMdd")}; alter table dm_finrisk.dm_event_cashLoanEvent_di drop if exists partition (day = ${zdt.addDay(-1).format("yyyyMMdd")}); insert overwrite table dm_finrisk.dm_event_cashLoanEvent_di partition (day = ${zdt.addDay(-1).format("yyyyMMdd")}) select event_uuid ,event_code ,dt ,event_time ,rawSnapshot from tmp.tmp_dm_event_cashLoanEvent_di_02_${zdt.addDay(-1).format("yyyyMMdd")}分析下上面代码