English 中文(简体)
资料库服务器中的等值查询
原标题:Equivalent query in sql server for INFORMATION_SCHEMA

我在一页上工作,我们需要对两个数据库的表象进行直观的比较,一个数据库是板球服务器,另一个是神话。 我还必须包括指数。

如今,我的心脏病和指数显示胎儿衰变。

select column_name,column_type,table_name,column_key 
  from INFORMATION_SCHEMA.COLUMNS where table_name =  tbl_ClientDN 

但是,对于ql服务器来说,同样的问题并不包括返回指数。

 select * from INFORMATION_SCHEMA.COLUMNS where table_name =  tbl_ClientDN 

因此,需要确定:

 sp_helpindex  tbl_ClientDN 

how to get column_key showing indexes in mssql query. any suggestion ?

最佳回答

远离<代码>INFORMATION_SCHEMA.COLUMNS,特别是在索引方面,因为诸如过滤指数和列入一栏等内容不属于定义的范围。 我在此更详细地谈到这一点:

页: 1 例如:

DECLARE @tablename NVARCHAR(512) =  dbo.tbl_ClientDN ;

SELECT
    [Index]  = i.name,
    [Column] = c.Name, 
    [Type]   = i.type_desc,
    PK = i.is_primary_key,
    [Unique] = i.is_unique,
    [Unique Constraint] = i.is_unique_constraint,
    [DESC] = ic.is_descending_key,
    [INCLUDE] = ic.is_included_column,
    [Filtered] = i.filter_definition -- only for SQL Server 2008+
FROM
    sys.indexes AS i 
INNER JOIN 
    sys.index_columns AS ic 
    ON i.[object_id] = ic.[object_id] 
    AND i.index_id = ic.index_id
INNER JOIN 
    sys.columns c
    ON ic.column_id = c.column_id
    AND ic.[object_id] = c.[object_id]
WHERE 
    i.[object_id] = OBJECT_ID(@tablename)
ORDER BY [Index], ic.index_column_id;

如果你想一劳永逸地对所有表格都这样做,那么简单改动:

SELECT
    [Table] = QUOTENAME(OBJECT_SCHEMA_NAME(i.[object_id]))
      +  .  + QUOTENAME(OBJECT_NAME(i.[object_id])),
    [Index]  = i.name,
    [Column] = c.Name, 
    [Type]   = i.type_desc,
    PK = i.is_primary_key,
    [Unique] = i.is_unique,
    [Unique Constraint] = i.is_unique_constraint,
    [DESC] = ic.is_descending_key,
    [INCLUDE] = ic.is_included_column,
    [Filtered] = i.filter_definition -- only for SQL Server 2008+
FROM
    sys.indexes AS i 
INNER JOIN 
    sys.index_columns AS ic 
    ON i.[object_id] = ic.[object_id] 
    AND i.index_id = ic.index_id
INNER JOIN 
    sys.columns c
    ON ic.column_id = c.column_id
    AND ic.[object_id] = c.[object_id]
ORDER BY [Table], [Index], ic.index_column_id;

https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-indexes-transact-sql”rel=“nofollow noretinger”>sys.indexes 和

您也不妨对 Kimberley L. Tripp s sp_helpindex2


http://www.ohchr.org。

总的来说,我同意“Brian White s”的意见。 如果你全力以赴,你就应该利用这一工具,而不是重新发明轮椅,并试图书写轮椅。 或许你在时间上已经花掉了好工具的成本。 请改为:

问题回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签