August 17, 2009 at 10:54 am
I need to find PK column datatypes in a database that are GUID's..
Also need to know if PK's are clustered indexes or not ??
Thanx in Advance !
August 17, 2009 at 11:27 am
All this information can be obtained from the system tables...the query below is one way of getting the information needed:
SELECT
OBJECT_NAME(si.object_id) TableName,
sc.name ColumnName,
si.name IndexName,
type_desc IndexType,
is_primary_key IsPrimaryKey,
st.name ColumnDataType
FROM sys.indexes si INNER JOIN sys.index_columns sic ON
si.object_id = sic.object_id
AND si.index_id = sic.index_id
AND si.is_primary_key = 1
-- uncomment below to get only clustered index
--AND si.index_id = 1
INNER JOIN sys.columns sc ON
sc.object_id = si.object_id
AND sc.object_id = sic.object_id
AND sc.column_id = sic.column_id
INNER JOIN sys.types st ON
st.system_type_id = sc.system_type_id
-- filter on GUID columns
AND st.name = 'uniqueidentifier'
ORDER BY sc.object_id,sc.column_id
August 18, 2009 at 2:21 am
Hey thanx a lot... Exactly wot I was looking for...:-)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply