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到最小值,要么清空。
  • 相关阅读:
    BOM和DOM
    前端CSS
    前端HTML
    索引 创建用户和授权 锁 事务
    多表查询 Naricat pymysql
    外键关联的修改 级联 修改表行记录的操作
    表的基础数据类型 MySQL的mod设置 表的约束
    数据库初识及操作命令
    LINUX 下LAMP之源码环境部署
    Nginx负载均衡配置实例详解【原】
  • 原文地址:https://www.cnblogs.com/kala/p/7768590.html
Copyright © 2011-2022 走看看