zoukankan      html  css  js  c++  java
  • 拆分数据库测试之--收缩数据库

    select db_name(database_id) as DBName,
    name,
    size*8/1024 MB,
    type_desc
    from sys.master_files where database_id=db_id('SplitDB')
    
    
    use SplitDB
    
    declare @i int
    set @i =3
    
    while(@i <> 0)
    begin
    insert into T1 select * from T1
    set @i=@i-1
    end
    
    
    insert into T1 select * from T1
    
    
    use SplitDB
    
    declare @i int
    set @i =10
    
    while(@i <> 0)
    begin
    insert into T1 select * from T1
    set @i=@i-1
    end
    
    
    select * from T1
    
    
    
    select db_name(database_id) as DBName,
    name,
    size*8/1024 MB,
    type_desc
    from sys.master_files where database_id=db_id('SplitDB')
    
    
    
    
    select o.Name as TableName, fg.groupname as FileGroupName
    from sysobjects o
     inner join sysindexes i
      on i.id = o.id
     inner join sysfilegroups fg
      on i.groupid = fg.groupid
    where type = 'U'
     and i.indid in (0,1)
    
    
     select o.name as TableName from sys.objects o inner join sys.indexes i on o.object_id = i.object_id
     inner join sys.master_files mf on i.object_id=md.o
     where o.type = 'U' 
    
    
     select * from sysindexes
     
     
     
     
     
     
     
     
     
     
     -------------------------------------------- 
     ----清空文件
     
     
     
    注意:新建的DB文件一定autogrowth一定要设置成一样,并且不要太大,100M就行。
    
    写入方式:
    哪个文件还没满就一直写这个文件,写满了换下一个
    
    主文件是不能被移除的
     
     USE AdventureWorks2012;  
    GO  
    -- Create a data file and assume it contains data.  
    ALTER DATABASE AdventureWorks2012   
    ADD FILE (  
        NAME = Test1data,  
        FILENAME = 'C:	1data.ndf',  
        SIZE = 5MB  
        );  
    GO  
    -- Empty the data file.  
    DBCC SHRINKFILE (Test1data, EMPTYFILE);  
    GO  
    -- Remove the data file from the database.  
    ALTER DATABASE AdventureWorks2012  
    REMOVE FILE Test1data;  
    GO  
    
    
    
    DBCC SHRINKFILE (SplitDB, EMPTYFILE);  
    GO  
    
    
    -- Remove the data file from the database.  
    ALTER DATABASE SplitDB  
    REMOVE FILE SplitDB;  
    GO  
    
    
    This option is not supported for FILESTREAM filegroup containers.
    If target_size is specified, DBCC SHRINKFILE tries to shrink the file to the specified size. Used pages in the part of the file to be freed are relocated to available free space in the part of the file retained. For example, if there is a 10-MB data file, a DBCC SHRINKFILE operations with a target_size of 8 causes all used pages in the last 2 MB of the file to be reallocated into any unallocated pages in the first 8 MB of the file. DBCC SHRINKFILE does not shrink a file past the size needed to store the data in the file. For example, if 7 MB of a 10-MB data file is used, a DBCC SHRINKFILE statement with a target_size of 6 shrinks the file to only 7 MB, not 6 MB.
    
    
    根据上面微软官方的一段话,说明shrinkDB要么shrink到最小值,要么清空。
  • 相关阅读:
    电子书下载:Pro jQuery
    神鬼传奇小技巧:教你如何修改自己想要的时装
    用虚拟机玩游戏的方法!! 开3D加速!
    如何让DevExpress的DateEdit控件正确显示日期的周名
    SOAP Version 1.2
    Delphi中的容器类
    <神鬼传奇>客户端终极优化精简方法
    今日阅读20090102基本数据结构
    判断一个char[]里是否包含两个连续的\r\n
    蛙蛙推荐:改进同步等待的网络服务端应用
  • 原文地址:https://www.cnblogs.com/kala/p/7768590.html
Copyright © 2011-2022 走看看