涉及到的系统表汇总
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]FROMmaster.sys.databases AS dtbWHERE(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]FROMsys.tables AS tblINNER JOIN sys.fulltext_indexes AS fti ON fti.object_id=tbl.object_idWHERE(tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')
=======获得全文索引列:
SELECT
col.name AS [Name]FROMsys.tables AS tblINNER JOIN sys.fulltext_indexes AS fti ON fti.object_id=tbl.object_idINNER JOIN sys.fulltext_index_columns AS icol ON icol.object_id=fti.object_idINNER JOIN sys.columns AS col ON col.object_id = icol.object_id and col.column_id = icol.column_idWHERE(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 dtbWHERE (dtb.name=N'master')SELECT
CAST(COLLATIONPROPERTY(name, 'LCID') AS int) AS [LocaleID]FROM sys.fn_helpcollations() clWHERE (cl.name=N'Chinese_PRC_CI_AS')
=======获取兼容级别:
SELECT
dtb.compatibility_level AS [CompatibilityLevel],dtb.name AS [DatabaseName2]FROM master.sys.databases AS dtbWHERE (dtb.name=N'DLib')
=======表名和架构名:SELECT
SCHEMA_NAME(tbl.schema_id) AS [Schema],tbl.name AS [Name]FROM sys.tables AS tblWHERE (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 0end 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]FROMsys.tables AS tblINNER JOIN sys.indexes AS idx ON idx.object_id = tbl.object_id and idx.index_id < 2LEFT OUTER JOIN sys.data_spaces AS dstext ON tbl.lob_data_space_id = dstext.data_space_idLEFT OUTER JOIN sys.data_spaces AS dsidx ON dsidx.data_space_id = idx.data_space_idWHERE(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 iJOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_idJOIN sys.allocation_units as a ON a.container_id = p.partition_idwhere i.object_id = tbl.object_id),0.0) AS [DataSpaceUsed]FROMsys.tables AS tblWHERE(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'SELECTISNULL((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 iJOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_idJOIN sys.allocation_units as a ON a.container_id = p.partition_idwhere i.object_id = tbl.object_id),0.0) AS [IndexSpaceUsed]FROMsys.tables AS tblWHERE(tbl.name=N'AreaInfo' and SCHEMA_NAME(tbl.schema_id)=N'dbo')
=======当前连接用户:
select suser_sname()