Sunday, February 19, 2012

How to query bitmap columns

I need to find out all columns that are identity. How do I query syscolumn to find out this information.

Thanks.

I need to find all the identity columns in my database. How do I query syscolumns to get this information>

Thanks.

|||Try this: select object_name(object_id) + '.' + name as Table_Column from sys.columns where is_identity = 1 You may want to filter further to eliminate system table identity columns. Please don't post the same question more than once, either. Steve Kass Drew University http://www.stevekass.com MJM2@.discussions.microsoft.com wrote: > I need to find out all columns that are identity. How do I query > syscolumn to find out this information. > > Thanks. > >|||Create the below stored procedure in ur SQL server 2005 database

and execute .It will return all identity column information

Code Snippet

CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON

SELECT QUOTENAME(SCHEMA_NAME(t.schema_id)) + '.' + QUOTENAME(t.name) AS TableName,
c.name AS ColumnName,
CASE c.system_type_id
WHEN 127 THEN 'bigint'
WHEN 56 THEN 'int'
WHEN 52 THEN 'smallint'
WHEN 48 THEN 'tinyint'
END AS 'DataType',
IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) AS CurrentIdentityValue,
CASE c.system_type_id
WHEN 127 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 9223372036854775807
WHEN 56 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 2147483647
WHEN 52 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 32767
WHEN 48 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id) + '.' + t.name) * 100.) / 255
END AS 'PercentageUsed'
FROM sys.columns AS c
INNER JOIN
sys.tables AS t
ON t.[object_id] = c.[object_id]
WHERE c.is_identity = 1
ORDER BY PercentageUsed DESC
END


|||This is what I need. Thanks (and sorry for the double post - am new at this).

|||This works as well. Appreciate the responses. Thanks!

No comments:

Post a Comment