工作中遇到:在为一个表新增字段后,新增字段在最后,想调整新增字段的位置. 1.原始方法: --新建临时表以存储正确的顺序 create table A_2 as select (column1,colum2,……A表中的顺序) from A_1 ; --删除表A_1 drop table A_1; --新建A_1并从A_2表中赋予其正确的顺序和值 create table A_1 as select * from A_2; --删除临时表A_2 drop table A_2; 这种方法对字段较少
解决方案: 1.删除分区后重新跑数据 alter table drop partition(分区字段=“”): 2.新增字段运行程序后其实数据已经有了,只是查询hive的时候无法显示出来, 这个时候只要刷新一下表结构就出来了 ALTER TABLE name REPLACE COLUMNS (col_spec[, col_spec ...]):
1.查询数据表的属性(名称.说明.是否主键.数据类型.是否自增) SELECT t1.name columnName,case when t4.id is null then 'false' else 'true' end as pkColumn, case when COLUMNPROPERTY( t1.id,t1.name,'IsIdentity') = 1 then 'true' else 'false' end as autoAdd ,t5.name jdbcType ,cast(isn
)-- 表名 set @table_name='bqcform101' --============表结构 select 类别,表名or字段名,描述,字段类型,是否自增,允许为NULL,默认值 from ( column_id,tbs.name 表名or字段名,ds.value 描述, rn FROM sys.extended_properties ds LEFT JOIN sysobjects tbs ON ds.major_id=tbs.id and tbs.name=@table_name
大家都可能遇到字段重复的情况,网上很多人在找方法,也给出了一些方法,但是有的方法是误导大家,铁牛写出以下方法,方便大家使用 1.通过group by把重复的字段筛选出来,并建立临时表tmp 1 create table tmp as select max(id) as col1 from www group by dfdfd; 2.从去重表对象里通过not in的条件来筛选出不在临时表的列col1,执行not in的删除操作 1 delete from www where id not in (
SELECT 表名 then d.name else '' end, 表说明 then isnull(f.value,'') else '' end, 字段序号=a.colorder, 字段名=a.name, 标识 then '√'else '' end, 主键 FROM sysobjects where xtype='PK' and name in ( SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexk
插入数据 1 insert into TbYTZ(UserID) select UserID from TbUser 更新数据则在TbUser和TbYTZ两个表要有一个关系... 如TbUser.a1=TbYTZ.a2 1 UPDATE TbYTZ SET TbYTZ.UserID = (SELECT UserID FROM TbUser WHERE TbUser.a1=TbYTZ.a2)