涉及到的系统表汇总

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()

获取表信息(MSSQL)的更多相关文章

  1. JAVAEE_Servlet_04_在service()方法中连接数据库获取表信息

    在service()方法中连接数据库获取表信息 代码: package com.shige.controller; import javax.servlet.*; import java.io.IOE ...

  2. ORACLE获取表信息方法

    获取表: select table_name from user_tables; //当前用户的表 select table_name from all_tables; //所有用户的表 select ...

  3. mybatis获取表信息,以及遍历ResultSet

    @RunWith(SpringRunner.class) @SpringBootTest public class BravolinksCrmServerApplicationTests { @Aut ...

  4. mysql中 show table status 获取表信息

    用法 mysql>show table status; mysql>show table status like 'esf_seller_history'\G; mysql>show ...

  5. sql 2012中获取表的信息,包含字段的描述

    1.获取数据库中的表 select name from sysobjects where type='U' 2.获取表字段(此处是Route表) Select name from syscolumns ...

  6. C# 获取SqLite数据库表信息以及获取表内字段信息

    #region 最新数据表信息显示事件 /// <summary> /// 最新数据表信息显示事件 /// </summary> /// <param name=&quo ...

  7. mysql学习之-show table status(获取表的信息)参数说明

    --获取表的信息mysql> show table status like 'columns_priv'\G;*************************** 1. row ******* ...

  8. Oracle 获取表结构信息

    通过Oracle中的user_tab_cols, user_col_comments, user_constraints, user_cons_columns表联合查询. user_tab_cols用 ...

  9. 从Windows系统服务获取活动用户的注册表信息(当前活动用户的sessionId. 当前活动用户的 hUserToken)

    首先,对“活动用户”的定义是,当前拥有桌面的用户.对于Windows XP及其以后的系统,即使是可以多个用户同时登录了,拥有桌面的也仅仅只有一个. 如果系统级服务调用Windows API来获取注册表 ...

随机推荐

  1. WPF 操作键盘

    #region 打开键盘的键 const uint KEYEVENTF_EXTENDEDKEY = 0x1; const uint KEYEVENTF_KEYUP = 0x2; [DllImport( ...

  2. 百度编辑器Ueditor 初始化加载内容失败解决办法

    项目上有用到百度文本编辑器ueditor,在页面加载的时候初始化编辑器内容时候,使用 $.document.ready(function() { UE.getEditor('editor').setC ...

  3. zoj.3865.Superbot(bfs + 多维dp)

    Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you ...

  4. onfiguration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Una ...

  5. Windows2003操作系统SQL Server 2008安装图解(详细)

    最近不少用户在windows2003 server 32位操作系统上安装SQL Server2008总是失败,出现大量错误.今天经过通过我反复测试安装,找出了一个便捷的安装方法,节省大家宝贵时间,具体 ...

  6. apache2:Invalid option to WSGI daemon process definition

    版本说明: ubuntu 12.04 server /apache 2.2 / mod_wsgi 3.3 / python 2.7.3 /django 1.7 在ubuntu12的服务器上配置djan ...

  7. java中queue的使用

    Queue接口与List.Set同一级别,都是继承了Collection接口.LinkedList实现了Queue接 口.Queue接口窄化了对LinkedList的方法的访问权限(即在方法中的参数类 ...

  8. jstl数字转日期

    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <jsp: ...

  9. (转)SQL Server 中的事务和锁(三)-Range S-U,X-X 以及死锁

    在上一篇中忘记了一个细节.Range T-K 到底代表了什么?Range T-K Lock 代表了在 SERIALIZABLE 隔离级别中,为了保护范围内的数据不被并发的事务影响而使用的一类锁模式(避 ...

  10. Linux下永久修改主机名

    红帽系列的Linux发行版主机名存放位置是/etc/sysconfig/network,Ubuntu Linux主机名存放位置是/etc/hostname,所以只要修改主机名存放文件便可以永久的修改计 ...