• 常用sql备份


    统计数据库中表格数据行数所占空间和索引情况

     1 set nocount on 
     2 exec sp_MSForEachTable 
     3 @precommand=N'
     4 create table ##(
     5 id int identity,
     6 表名 sysname,
     7 字段数 int,
     8 记录数 int,
     9 保留空间 Nvarchar(20),
    10 使用空间 varchar(20),
    11 索引使用空间 varchar(20),
    12 未用空间 varchar(20))',
    13 @command1=N'insert ##(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_spaceused ''?''
    14         update ## set 字段数=(select count(*) from syscolumns where id=object_id(''?'')) where id=scope_identity()',
    15 @postcommand=N'select 
    16     id,
    17     表名,
    18     字段数 列数,
    19     (记录数/10000.0) 记录数万,
    20     (Convert(bigint,rtrim(Replace(保留空间,''KB'','''')))/1024.0) 保留空间M,
    21     (Convert(bigint,rtrim(Replace(使用空间,''KB'','''')))/1024.0) 使用空间M,
    22     (Convert(bigint,rtrim(Replace(索引使用空间,''KB'','''')))/1024.0) 索引使用空间M,
    23     (Convert(bigint,rtrim(Replace(未用空间,''KB'','''')))/1024.0) 未用空间M
    24  from ## a order by 使用空间M desc;
    25  drop table ##'
    26 set nocount off
    View Code

    统计分区信息

     1 SELECT *,$partition.PartFunCreateTime(InsertTime) [Partition Number]
     2 --, min(o.InsertTime) AS [Min StudentID]
     3 --, max(o.InsertTime) AS [Max StudentID]
     4 --, count(*) as [Rows In Partition]
     5 FROM Person AS o
     6 --GROUP BY $partition.PartFunCreateTime(InsertTime)
     7 ORDER BY [Partition Number]
     8 
     9 SELECT $partition.PartFunCreateTime(InsertTime) [Partition Number]
    10 , min(o.InsertTime) AS [Min StudentID]
    11 , max(o.InsertTime) AS [Max StudentID]
    12 , count(*) as [Rows In Partition]
    13 FROM Person AS o
    14 GROUP BY $partition.PartFunCreateTime(InsertTime)
    15 ORDER BY [Partition Number]
    View Code

    分区测试

     1 BEGIN TRANSACTION
     2 USE [FenQuTest]
     3 SET ANSI_NULLS ON
     4 SET QUOTED_IDENTIFIER ON
     5 CREATE TABLE [dbo].[staging_Person_0](
     6     [ID] [int] NOT NULL,
     7     [InsertTime] [smalldatetime] NULL
     8 ) ON [fg1]
     9 
    10 USE [FenQuTest]
    11 ALTER TABLE [FenQuTest].[dbo].[Person] SWITCH PARTITION 1 TO [FenQuTest].[dbo].[staging_Person_0]PARTITION 1
    12 USE [FenQuTest]
    13 ALTER PARTITION FUNCTION [PartFunCreateTime]() MERGE RANGE(N'2013-01-01T00:00:00.000')
    14 COMMIT TRANSACTION
    View Code

    表到分区

    1 ALTER TABLE [FenQuTest].[dbo].[staging_Person_0] SWITCH TO [FenQuTest].[dbo].[Person]PARTITION 1
    View Code
  • 相关阅读:
    [k8s]kube-dns/dashboard排错历险记(含sa加载用法/集群搭建)
    禁用nginx的access日志
    redis info 各信息意义
    使用JProfiler进行内存分析
    lr11 BUG?Failed to send data by channels
    loadrunner 怎么能得到返回的http状态?
    SQL SERVER查看当前连接情况
    总结: Struts2 + Spring 的线程安全问题
    转发:maven打包时始终出现以下提示:-source 1.3 中不支持泛型(请使用 -source 5 或更高版本以启用泛型)
    SQL Server 索引结构及其使用(一)
  • 原文地址:https://www.cnblogs.com/cxd4321/p/3718200.html
Copyright © 2020-2023  润新知