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到最小值,要么清空。
  • 相关阅读:
    mybatis N+1问题解决
    Best Time to Buy and Sell Stock
    119. Pascal's Triangle II
    HBuilder打包ios
    关于JavaScript/TypeScript中的setTimeout和setInterval
    白色透明渐变css
    AntV 在小程序中的使用
    AntV 在h5页面中的使用
    js处理后端返回超过16位大数字方案(network中preview和response返回不一致)
    m站taro编译css的时候有些属性会被编译掉,如果遇到这个问题,用第一行代码,写到无法编译的代码上面
  • 原文地址:https://www.cnblogs.com/kala/p/7768590.html
Copyright © 2011-2022 走看看