![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-im8rShBY-1636032215912)(.\SQL 案例图片\5 分区表.png)]](/https://i-blog.csdnimg.cn/blog_migrate/42cfa1ec0da2209fc50a459aa8301ee4.png)
1. 创建分区函数
create partition function testfunc(int) -- partition function 分区函数名(分区列的数据类型)
as range left -- 左排序|右排序
for values (1,100) -- 分区边界值
go
2. 创建分区方案
create partition scheme testscheme -- scheme 方案,schema 架构
as partition testfunc -- 使用哪个分区函数
to([primary],Gdata,test) -- 到哪几个文件组
go
3. 创建表
create table StudentDB.my.test -- 创建表
(
StuID int identity(1,1) not null, -- identity(1,1) 从 1 自增长 1 个单位
StuName varchar(20) not null,
StdYear int not null
)
on testscheme(StdYear) -- 以哪个为索引,建立在哪个分区方案之上
go
4. 检查所属分区
use StudentDB
select *,$partition.testfunc(StdYear) as '所属分区'
from my.test
本文详细介绍了如何在SQL Server中创建分区函数、分区方案、表并检查数据所属分区,涵盖了从理论到实践的全过程,是备考数据库三级的实用指南。

606

被折叠的 条评论
为什么被折叠?



