先说结论 不能重名个
刚接触hive 看到 内外表这个 标志的时候第一反应是隔绝开的 ,所以有个疑问就是 内表外表是否可以重名
创建外表
create external table if not exists dept(
deptno int,
dname string,
loc int
)
row format delimited fields terminated by '\t';
查看信息 部分删除
hive> desc formatted dept ;
OK
Table Type: EXTERNAL_TABLE
验证再有 if not exists 是否存在判读的过程中 是否可以覆盖原表 或者 创建一张内表
hive> create external table if not exists dept(
> deptno int,
> dname string,
> loc int
> )
> row format delimited fields terminated by '\t';
OK
Time taken: 0.463 seconds
hive> show tables ;
OK
dept
Time taken: 0.04 seconds, Fetched: 1 row(s)
hive> desc formatted dept ;
OK
Table Type: EXTERNAL_TABLE
查看之后发现 dept 表只有一个 , 而且依旧是外表说明 既不会出现多个 也不会覆盖原有表类型
hive> create table dept(
> deptno int,
> dname string,
> loc int
> )
> row format delimited fields terminated by '\t';
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. AlreadyExistsException(message:Table dept already exists)
hive>
去除掉 if not exists 直接报表纯在的错误
结论 hive内外表不可以重名
(其实很简单 如果两个表名重复 在查询时候语句没有要求 内外表 查询需要加 特殊标识 )
名称重复 select 一定会有问题 反推就知道内外表名称不能重复