zoukankan
html css js c++ java
Sql Server 分区演练
代码加注释,希望对初学者有用。
USE
[
master
]
GO
if
exists
(
select
*
from
sys.databases
where
name
=
'
Test_1
'
)
drop
database
Test_1
GO
--
创建新库,要演练分区所以我们会多创建两个文件组Test_A,Test_B,以便在后面的分区方案中使用。
CREATE
DATABASE
[
Test_1
]
ON
PRIMARY
( NAME
=
N
'
test_1
'
, FILENAME
=
N
'
D:\sqldata\test_1.mdf
'
, SIZE
=
10240KB , MAXSIZE
=
UNLIMITED, FILEGROWTH
=
1024KB ),
FILEGROUP
[
test_A
]
( NAME
=
N
'
Test_A
'
, FILENAME
=
N
'
D:\sqldata\test_A.ndf
'
, SIZE
=
1024KB , MAXSIZE
=
UNLIMITED, FILEGROWTH
=
1024KB ),
FILEGROUP
[
test_B
]
( NAME
=
N
'
Test_B
'
, FILENAME
=
N
'
D:\sqldata\test_B.ndf
'
, SIZE
=
1024KB , MAXSIZE
=
UNLIMITED, FILEGROWTH
=
1024KB )
LOG
ON
( NAME
=
N
'
Test_log
'
, FILENAME
=
N
'
D:\sqldata\Test_log.ldf
'
, SIZE
=
7616KB , MAXSIZE
=
2048GB , FILEGROWTH
=
10
%
)
COLLATE Chinese_PRC_CI_AS
GO
USE
[
Test_1
]
GO
--
若分区函数存在则先drop掉
IF
EXISTS
(
SELECT
*
FROM
sys.partition_functions
WHERE
name
=
N
'
test_partition
'
)
DROP
PARTITION
FUNCTION
[
test_partition
]
GO
/**/
/*
创建分区函数给后面的分区方案使用,分区函数很简单就是指定一个范围确定在某个值为什么的时候放在那个分区上
*/
--
新建一个简单的分区函数,该函数以1000为界分两个区
create
partition
function
test_partition(
int
)
AS
RANGE
LEFT
FOR
VALUES
(
1000
)
go
/**/
/*
看分区方案是否存在,若存在先drop掉
*/
IF
EXISTS
(
SELECT
*
FROM
sys.partition_schemes
WHERE
name
=
N
'
test_scheme
'
)
DROP
PARTITION SCHEME test_scheme
GO
--
创建分区方案,分区方案需要指定一个分区函数,并指定在分区函数中分的区需要放在哪一个文件组上
create
partition scheme test_scheme
AS
PARTITION
[
test_partition
]
TO
(test_A,test_B)
GO
--
创建分区表
if
object_id
(
'
student
'
,
'
U
'
)
is
not
null
drop
table
student;
go
create
table
student
(
id
int
identity
(
1
,
1
)
not
null
,
name
varchar
(
10
)
not
null
,
class
int
not
null
,
grade
int
)
on
test_scheme(class)
--
在此处指定该表要使用的分区方案,并将指定分区依据列
go
--
随便插入几条数据
insert
into
student
values
(
'
AQU
'
,
10
,
100
);
--
这条数据在A分区上
insert
into
student
values
(
'
AQU_边界
'
,
1000
,
89
);
--
这边数据也在A分区上是个边界,因为我们上面在函数中指定的是RANGE LEFT,所以1000在A分区上
insert
into
student
values
(
'
BQU
'
,
1001
,
90
);
--
这一条肯定是在B分区上了。
go
--
最后看看结果。$partition.分区函数(分区列)可以返回某一行所在的分区序号
select
*
,分区序号
=
$partition.test_partition(class)
from
student
GO
注释:代码来源于
博客园
的博文。
第七影视
_
最新电影
_
好看的美剧
_
天天美剧
查看全文
相关阅读:
【容斥】Four-tuples @山东省第九届省赛 F
【树形dp入门】没有上司的舞会 @洛谷P1352
【贪心】LIS @The 15th Zhejiang Provincial Collegiate Programming Contest E
【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D
PCA & whitening
Autoencoders and Sparsity(二)
Autoencoders and Sparsity(一)
Regularized logistic regression
Regularization —— linear regression
Logistic Regression and Newton's Method
原文地址:https://www.cnblogs.com/goooto/p/1747857.html
最新文章
.Net 服务(WCF) 中访问共享文件
VS 工具加密DLL文件
Access 开发日记
VS 崩溃
SQL Server 2008 脚本导入Execl数据
SQL Server 2008 实用高级查询
jquery each,click ,元素选择器
sql server查找字段中含有汉字
ckfinder,ckeditor 编辑器 上传图片配置
asp.net ado.net setParameter
热门文章
php调用wcf,webservice
sql server min max ,rownum 去除重复
关于tag处理
think php orm大小写问题
【容斥+组合数】Massage @2018acm徐州邀请赛 E
【分治-前缀积后缀积】JS Window @2018acm徐州邀请赛G
【数论】Factors of Factorial @upcexam6503
【倍增】Tak and Hotels II @ABC044&ARC060/upcexam6463
【二分图最大匹配】Bullet @山东省第九届省赛 B
【二分图带权匹配】Anagram @山东省第九届省赛 A
Copyright © 2011-2022 走看看