資源描述:
《sql server數(shù)據(jù)庫(kù)分區(qū)表創(chuàng)建和修改實(shí)例》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、-----------------------------建立分區(qū)表---------------------------------建數(shù)據(jù)庫(kù)createdatabaseTmp_dbon(name=Tmp_db_dat,filename='D:DateTmp_db.mdf',size=10,maxsize=50,filegrowth=5)logon(name=Tmp_db_log,filename='D:DateTmp_db.ldf',size=5,maxsize=25,filegrowth=5)gouseTmp_dbgo--增加文件組alterdatabaseTmp_db
2、addfilegroupf1alterdatabaseTmp_dbaddfilegroupf2alterdatabaseTmp_dbaddfilegroupf3alterdatabaseTmp_dbaddfilegroupf4--將文件分配到文件組alterdatabaseTmp_dbaddfile(name=N'Tmp_db_f1',filename=N'D:DateTmp_db_f1.ndf',size=3072kb,filegrowth=1024kb)tofilegroupf1alterdatabaseTmp_dbaddfile(name=N'Tmp_db_f2',fil
3、ename=N'D:DateTmp_db_f2.ndf',size=3072kb,filegrowth=1024kb)tofilegroupf2alterdatabaseTmp_dbaddfile(name=N'Tmp_db_f3',filename=N'D:DateTmp_db_f3.ndf',size=3072kb,filegrowth=1024kb)tofilegroupf3alterdatabaseTmp_dbaddfile(name=N'Tmp_db_f4',filename=N'D:DateTmp_db_f4.ndf',size=3072kb,filegro
4、wth=1024kb)tofilegroupf4--創(chuàng)建分區(qū)函數(shù)createpartitionfunctionpt_fn_test(int)asrangeleftforvalues(3000,6000,9000)--創(chuàng)建分區(qū)方案createpartitionschemesh_testaspartitionpt_fn_testto(f1,f2,f3,f4)--創(chuàng)建分區(qū)表createtablet_test(idintidentity(1,1)primarykey,class_avarchar(50),class_bvarchar(50),add_dtdatetime)onsh_test
5、(id)--為表插入W條數(shù)據(jù)declare@iintselect@i=1while@i<=14000begininsertintot_test(class_a,class_b,add_dt)selectcase@i%2when0then'class_a'+cast(@iasvarchar)elsecast(@iasvarchar)end,case@i%5when0then'class_b'+cast(@iasvarchar)elsecast(@iasvarchar)end,getdate()select@i=@i+1end--查看分區(qū)信息select$partition.pt_fn
6、_test(id)aspartition_number_id,min(id)asmin_id,max(id)asmax_id,count(*)aspartition_cntfromtmp_db.dbo.t_testgroupby$partition.pt_fn_test(id)orderbypartition_number_idgo-------------------------修改分區(qū)表--------------------------增加文件組alterdatabaseTmp_dbaddfilegroupf5--將文件分配到文件組alterdatabaseTmp_dbadd
7、file(name=N'Tmp_db_f5',filename=N'D:DateTmp_db_f5.ndf',size=3072kb,filegrowth=1024kb)tofilegroupf5--修改分區(qū)方案ALTERPARTITIONSCHEMEsh_testNEXTUSEDf5--修改分區(qū)函數(shù)ALTERPARTITIONFUNCTIONpt_fn_test()SPLITRANGE(12000)