博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取表信息(MSSQL)
阅读量:5978 次
发布时间:2019-06-20

本文共 5147 字,大约阅读时间需要 17 分钟。

涉及到的系统表汇总

sys.databases

sys.objects

sys.indexes

sys.tables

sys.columns

sys.data_spaces

sys.partitions

sys.allocation_units

sys.fulltext_indexes

sys.fulltext_index_columns

sys.fn_helpcollations()

 

=======确定全文索引是否可用:

SELECT

dtb.is_fulltext_enabled AS [IsFullTextEnabled]
FROM
master.sys.databases AS dtb
WHERE
(dtb.name=N'DLib')

 

=======表中全文索引的几本信息:

SELECT

CAST(fti.is_enabled AS bit) AS [IsEnabled],
OBJECTPROPERTY(fti.object_id,'TableFullTextPopulateStatus') AS [PopulationStatus],
(case change_tracking_state when 'M' then 1 when 'A' then 2 else 0 end) AS [ChangeTracking]
FROM
sys.tables AS tbl
INNER JOIN sys.fulltext_indexes AS fti ON fti.object_id=tbl.object_id
WHERE
(tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')

 

=======获得全文索引列:

SELECT

col.name AS [Name]
FROM
sys.tables AS tbl
INNER JOIN sys.fulltext_indexes AS fti ON fti.object_id=tbl.object_id
INNER JOIN sys.fulltext_index_columns AS icol ON icol.object_id=fti.object_id
INNER JOIN sys.columns AS col ON col.object_id = icol.object_id and col.column_id = icol.column_id
WHERE
(tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')

 

=======获得获得服务器名:

select SERVERPROPERTY(N'servername')

 

=======排序规则信息:

SELECT

dtb.collation_name AS [Collation],
dtb.name AS [DatabaseName2]
FROM master.sys.databases AS dtb
WHERE (dtb.name=N'master')

SELECT

CAST(COLLATIONPROPERTY(name, 'LCID') AS int) AS [LocaleID]
FROM sys.fn_helpcollations() cl
WHERE (cl.name=N'Chinese_PRC_CI_AS')

 

=======获取兼容级别:

SELECT

dtb.compatibility_level AS [CompatibilityLevel],
dtb.name AS [DatabaseName2]
FROM master.sys.databases AS dtb
WHERE (dtb.name=N'DLib')

 

=======表名和架构名:

SELECT
SCHEMA_NAME(tbl.schema_id) AS [Schema],
tbl.name AS [Name]
FROM sys.tables AS tbl
WHERE (tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')

 

=======Version:

SELECT

(@@microsoftversion / 0x1000000) & 0xff AS [VersionMajor]

 

=======创建时间、所属文件组等信息:

SELECT

tbl.name AS [Name],
tbl.object_id AS [ID],
tbl.create_date AS [CreateDate],
tbl.modify_date AS [DateLastModified],
SCHEMA_NAME(tbl.schema_id) AS [Schema],
CAST(
 case
    when tbl.is_ms_shipped = 1 then 1
    when (
        select
            major_id
        from
            sys.extended_properties
        where
            major_id = tbl.object_id and
            minor_id = 0 and
            class = 1 and
            name = N'microsoft_database_tools_support')
        is not null then 1
    else 0
end         
             AS bit) AS [IsSystemObject],
CAST(OBJECTPROPERTY(tbl.object_id, N'HasAfterTrigger') AS bit) AS [HasAfterTrigger],
CAST(OBJECTPROPERTY(tbl.object_id, N'HasInsertTrigger') AS bit) AS [HasInsertTrigger],
CAST(OBJECTPROPERTY(tbl.object_id, N'HasDeleteTrigger') AS bit) AS [HasDeleteTrigger],
CAST(OBJECTPROPERTY(tbl.object_id, N'HasInsteadOfTrigger') AS bit) AS [HasInsteadOfTrigger],
CAST(OBJECTPROPERTY(tbl.object_id, N'HasUpdateTrigger') AS bit) AS [HasUpdateTrigger],
CAST(OBJECTPROPERTY(tbl.object_id, N'IsIndexed') AS bit) AS [HasIndex],
CAST(OBJECTPROPERTY(tbl.object_id, N'IsIndexable') AS bit) AS [IsIndexable],
CAST(CASE idx.index_id WHEN 1 THEN 1 ELSE 0 END AS bit) AS [HasClusteredIndex],
ISNULL(dstext.name,N'') AS [TextFileGroup],
tbl.is_replicated AS [Replicated],
ISNULL( ( select sum (spart.rows) from sys.partitions spart where spart.object_id = tbl.object_id and spart.index_id < 2), 0) AS [RowCount],
tbl.uses_ansi_nulls AS [AnsiNullsStatus],
CAST(OBJECTPROPERTY(tbl.object_id,N'IsQuotedIdentOn') AS bit) AS [QuotedIdentifierStatus],
CAST(0 AS bit) AS [FakeSystemTable],
CASE WHEN 'FG'=dsidx.type THEN dsidx.name ELSE N'' END AS [FileGroup],
CASE WHEN 'PS'=dsidx.type THEN dsidx.name ELSE N'' END AS [PartitionScheme],
CAST(CASE WHEN 'PS'=dsidx.type THEN 1 ELSE 0 END AS bit) AS [IsPartitioned]
FROM
sys.tables AS tbl
INNER JOIN sys.indexes AS idx ON idx.object_id = tbl.object_id and idx.index_id < 2
LEFT OUTER JOIN sys.data_spaces AS dstext  ON tbl.lob_data_space_id = dstext.data_space_id
LEFT OUTER JOIN sys.data_spaces AS dsidx ON dsidx.data_space_id = idx.data_space_id
WHERE
(tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')

 

=======数据空间已使用的情况:

declare @PageSize float 
select @PageSize=v.low/1024.0 from master.dbo.spt_values v where v.number=1 and v.type='E'

SELECT

ISNULL((select @PageSize * SUM(CASE WHEN a.type <> 1 THEN a.used_pages WHEN p.index_id < 2 THEN a.data_pages ELSE 0 END)
FROM sys.indexes as i
JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id
JOIN sys.allocation_units as a ON a.container_id = p.partition_id
where i.object_id = tbl.object_id),0.0) AS [DataSpaceUsed]
FROM
sys.tables AS tbl
WHERE
(tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')

 

=======索引空间已使用的情况:

declare @PageSize float
select @PageSize=v.low/1024.0 from master.dbo.spt_values v where v.number=1 and v.type='E'
SELECT
ISNULL((select @PageSize * SUM(a.used_pages - CASE WHEN a.type <> 1 THEN a.used_pages WHEN p.index_id < 2 THEN a.data_pages ELSE 0 END)
FROM sys.indexes as i
JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id
JOIN sys.allocation_units as a ON a.container_id = p.partition_id
where i.object_id = tbl.object_id),0.0) AS [IndexSpaceUsed]
FROM
sys.tables AS tbl
WHERE
(tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')

 

=======当前连接用户:

select suser_sname()

转载地址:http://tdsox.baihongyu.com/

你可能感兴趣的文章
艾伟也谈项目管理,创业公司技术选型参考
查看>>
ios中MKHorizMenu用法
查看>>
C# 制作外挂常用的API
查看>>
快速批量导入庞大数据到SQL SERVER数据库(ADO.NET)
查看>>
LoadRunner常见问题整理
查看>>
SortedMap接口
查看>>
清理Mac上的软件容易吗?
查看>>
Leetcode[26]-Remove Duplicates from Sorted Array
查看>>
读书笔记6pandas简单使用
查看>>
CSS3鼠标悬停图片上浮显示描述代码
查看>>
python 函数的参数
查看>>
composer 报 zlib_decode(): data error
查看>>
利用ArcMap对tiff或jpg格式地图图片的配准步骤
查看>>
发现了一个好用的在线勾图的站点
查看>>
结合Jexus + Kestrel 部署 asp.net core 生产环境
查看>>
memcache的windows下的安装和简单使用
查看>>
记账类问题汇总
查看>>
URL编码总结
查看>>
JDBC 4.2 Specifications 中文翻译 -- 第九章 连接
查看>>
es6的Proxy(代理)
查看>>