Home  >  Article  >  Database  >  关于数据库分区后的几个查询和补充

关于数据库分区后的几个查询和补充

WBOY
WBOYOriginal
2016-06-07 15:24:091251browse

--查看分区及分区范围的情况select * from sys.partitions where object_id = object_id('SecureUsbLog');select * from sys.partition_range_values;--查看分区架构情况select * from sys.partition_schemes;--查看某一特定分区列值属于哪个分区select M2.$

--查看分区及分区范围的情况
select * from sys.partitions where object_id = object_id('SecureUsbLog');
select * from sys.partition_range_values;


--查看分区架构情况
select * from sys.partition_schemes;


--查看某一特定分区列值属于哪个分区
select M2.$partition.Part_mediasec_func('20150325') as partition_num;


--查看某一特定分区的记录
select * from SecureUsbLog where M2.$partition.Part_mediasec_func(logTime) = 3


--查看各分区所包含的记录数
select $partition.Part_mediasec_func(logTime) as partition_num,
count(*) as record_num
from SecureUsbLog 
group by $partition.Part_mediasec_func(logTime)
order by $partition.Part_mediasec_func(logTime);

这部分是为了以后扩展,比如以后分区不够的时候,可以手动的添加分区。

--添加文件组
alter database M2
add filegroup [FG10];
go
--文件组
alter database M2
add file(name=FG10_data,filename='c:\esafenet\FG10_data.ndf',size=1MB) to filegroup[FG10];
--添加分区,以后扩展
USE M2    
GO    
ALTER PARTITION SCHEME Part_mediasec_scheme NEXT USED FG10    
ALTER PARTITION FUNCTION Part_mediasec_func() SPLIT RANGE ('20221231 23:59:59') 
GO

数据库日志这块,分区是一个很好的选择,如果不分区,还有一个方法就是日志分表,按月将每个月的数据放到不同的表中。

总之日志这块分区是一个很好的选择,但也不是唯一的选择,还有一个就是syslog。什么是syslog?

下集我再分享。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn