用SQL得到分区表的分区键和分区值
ASE自15.0后增加了3中语义分区:hash、range、list。默认的轮询分区(roundrobin)为非语义分区,是为了兼容15.0之前的版本而设计的。
语义分区表的分区信息主要存储在:syspartitions和syspartitionkeys这两张表中。
查看表的分区信息可以使用系统自带的存储过程:sp_helpartition
本文提供3个SQL语句:
-
如何判断一个表是否是分区表?
select count(*) from dbo.syspartitionkeys where id=object_id(table_name)
示例:
1> if exists(select 1 from dbo.syspartitionkeys where id = object_id("PART_RESDISK"))
2> print "table PART_RESDISK exists!"
3> else
4> print "table PART_RESDISK not exists!"
5> go
table PART_RESDISK exists!
ASE15.0中的表默认为roundrobin类型的"分区表",系统表syspartitionkeys表中仅仅记录语义分区表的分区键信息。
-
如何查看一个语义分区表的分区键
使用如下SQL语句:
select c.name
from syspartitionkeys pk,syscolumns c
where pk.id = object_id(table_name)
and pk.id = c.id
and pk.colid = c.colid
示例:
1> select c.name
2> from syspartitionkeys pk,syscolumns c
3> where pk.id = object_id("PART_RESDISK")
4> and pk.id = c.id
5> and pk.colid = c.colid
6> go
name
---------------------------------------------------
TIME_ID
(1 row affected)
-
查看语义分区表的分区值信息
查看分区值信息,比如查看范围分区表的分区粒度、列表分区的各个列表值。
select c.number,c.text,c.partitionid,p.name
from sysindexes i, syscomments c,syspartitions p
where i.conditionid = c.id and c.partitionid = p.partitionid
and i.id =object_id("PART_RESDISK")
示例:
1> select c.number,c.text,c.partitionid,p.name
2> from sysindexes i, syscomments c,syspartitions p
3> where i.conditionid = c.id and c.partitionid = p.partitionid
4> and i.id =object_id("PART_RESDISK")
5> go
number text partitionid name
------ ------------------------- ----------- ---------------
1 VALUES <=(2010042600) 1956251043 P_20100426
2 VALUES <=(2010050300) 1972251100 P_20100503
3 VALUES <=(2010051000) 1988251157 P_20100510
4 VALUES <=(2010051700) 2004251214 P_20100517
5 VALUES <=(2010052400) 2020251271 P_20100524
6 VALUES <=(2010053100) 2036251328 P_20100531
7 VALUES <=(2010060700) 2052251385 P_20100607
8 VALUES <=(2010061400) 2068251442 P_20100614
9 VALUES <=(2010062100) 2084251499 P_20100621
10 VALUES <=(2010062800) 2100251556 P_20100628
11 VALUES <=(2010070500) 2116251613 P_20100705
12 VALUES <=(2010071200) 2132251670 P_20100712
13 VALUES <=(2010071900) 768079 P_20100719
14 VALUES <=(2010072600) 16768136 P_20100726
(14 rows affected)
1>