|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
DBaaS系统本身并不提供面对面访问或个人客户关系或持续不断的支持MySQL学习教程。这些就是需要解决方案提供商的原因。他们帮助客户选择正确的解决方案、规划集成和迁移战略,然后协助实施。server|索引在SQLServer2005中查询表布局及索引
--1.表布局信息查询
--========================================================================
--表布局信息查询
--邹建2005.08(援用请保存此信息)
--========================================================================
SELECT
TableName=CASEWHENC.column_id=1THENO.nameELSENEND,
TableDesc=ISNULL(CASEWHENC.column_id=1THENPTB.[value]END,N),
Column_id=C.column_id,
ColumnName=C.name,
PrimaryKey=ISNULL(IDX.PrimaryKey,N),
[IDENTITY]=CASEWHENC.is_identity=1THENN√ELSENEND,
Computed=CASEWHENC.is_computed=1THENN√ELSENEND,
Type=T.name,
Length=C.max_length,
Precision=C.precision,
Scale=C.scale,
NullAble=CASEWHENC.is_nullable=1THENN√ELSENEND,
[Default]=ISNULL(D.definition,N),
ColumnDesc=ISNULL(PFD.[value],N),
IndexName=ISNULL(IDX.IndexName,N),
IndexSort=ISNULL(IDX.Sort,N),
Create_Date=O.Create_Date,
Modify_Date=O.Modify_date
FROMsys.columnsC
INNERJOINsys.objectsO
ONC.[object_id]=O.[object_id]
ANDO.type=U
ANDO.is_ms_shipped=0
INNERJOINsys.typesT
ONC.user_type_id=T.user_type_id
LEFTJOINsys.default_constraintsD
ONC.[object_id]=D.parent_object_id
ANDC.column_id=D.parent_column_id
ANDC.default_object_id=D.[object_id]
LEFTJOINsys.extended_propertiesPFD
ONPFD.class=1
ANDC.[object_id]=PFD.major_id
ANDC.column_id=PFD.minor_id
--ANDPFD.name=Caption--字段申明对应的形貌称号(一个字段能够增加多个分歧name的形貌)
LEFTJOINsys.extended_propertiesPTB
ONPTB.class=1
ANDPTB.minor_id=0
ANDC.[object_id]=PTB.major_id
--ANDPFD.name=Caption--表申明对应的形貌称号(一个表能够增加多个分歧name的形貌)
LEFTJOIN--索引及主键信息
(
SELECT
IDXC.[object_id],
IDXC.column_id,
Sort=CASEINDEXKEY_PROPERTY(IDXC.[object_id],IDXC.index_id,IDXC.index_column_id,IsDescending)
WHEN1THENDESCWHEN0THENASCELSEEND,
PrimaryKey=CASEWHENIDX.is_primary_key=1THENN√ELSENEND,
IndexName=IDX.Name
FROMsys.indexesIDX
INNERJOINsys.index_columnsIDXC
ONIDX.[object_id]=IDXC.[object_id]
ANDIDX.index_id=IDXC.index_id
LEFTJOINsys.key_constraintsKC
ONIDX.[object_id]=KC.[parent_object_id]
ANDIDX.index_id=KC.unique_index_id
INNERJOIN--关于一个列包括多个索引的情形,只显现第1个索引信息
(
SELECT[object_id],Column_id,index_id=MIN(index_id)
FROMsys.index_columns
GROUPBY[object_id],Column_id
)IDXCUQ
ONIDXC.[object_id]=IDXCUQ.[object_id]
ANDIDXC.Column_id=IDXCUQ.Column_id
ANDIDXC.index_id=IDXCUQ.index_id
)IDX
ONC.[object_id]=IDX.[object_id]
ANDC.column_id=IDX.column_id
--WHEREO.name=N要查询的表--假如只查询指定表,加上此前提
ORDERBYO.name,C.column_id
--2.索引及主键信息
--========================================================================
--索引及主键信息
--邹建2005.08(援用请保存此信息)
--========================================================================
SELECT
TableId=O.[object_id],
TableName=O.Name,
IndexId=ISNULL(KC.[object_id],IDX.index_id),
IndexName=IDX.Name,
IndexType=ISNULL(KC.type_desc,Index),
Index_Column_id=IDXC.index_column_id,
ColumnID=C.Column_id,
ColumnName=C.Name,
Sort=CASEINDEXKEY_PROPERTY(IDXC.[object_id],IDXC.index_id,IDXC.index_column_id,IsDescending)
WHEN1THENDESCWHEN0THENASCELSEEND,
PrimaryKey=CASEWHENIDX.is_primary_key=1THENN√ELSENEND,
[UQIQUE]=CASEWHENIDX.is_unique=1THENN√ELSENEND,
Ignore_dup_key=CASEWHENIDX.ignore_dup_key=1THENN√ELSENEND,
Disabled=CASEWHENIDX.is_disabled=1THENN√ELSENEND,
Fill_factor=IDX.fill_factor,
Padded=CASEWHENIDX.is_padded=1THENN√ELSENEND
FROMsys.indexesIDX
INNERJOINsys.index_columnsIDXC
ONIDX.[object_id]=IDXC.[object_id]
ANDIDX.index_id=IDXC.index_id
LEFTJOINsys.key_constraintsKC
ONIDX.[object_id]=KC.[parent_object_id]
ANDIDX.index_id=KC.unique_index_id
INNERJOINsys.objectsO
ONO.[object_id]=IDX.[object_id]
INNERJOINsys.columnsC
ONO.[object_id]=C.[object_id]
ANDO.type=U
ANDO.is_ms_shipped=0
ANDIDXC.Column_id=C.Column_id
--INNERJOIN--关于一个列包括多个索引的情形,只显现第1个索引信息
--(
--SELECT[object_id],Column_id,index_id=MIN(index_id)
--FROMsys.index_columns
--GROUPBY[object_id],Column_id
--)IDXCUQ
--ONIDXC.[object_id]=IDXCUQ.[object_id]
--ANDIDXC.Column_id=IDXCUQ.Column_id
--
那时候Sybase已经诞生了6年的时间。至于其他值得关注的开源数据库,PostgreSQL将在2009年达到20岁的生日。虽然MySQL并不是市场上最年轻的数据库,但是却有更多成熟的数据库可供我们选择。 |
|