Finding the Identity column

Finding the Identity column

Post by Mats Helande » Fri, 18 Oct 2002 10:11:37



Hi all

I wonder if anyone could tell me how to "discover" the Identity column (the
auto-increasing one) of an SQL Server table, using (classic) ADO's
OpenSchema method? That is, how can I find out if a column is the Identity
column?

If anyone knows how to do the same witrh an Access database, I'd be
interested in that too, though I know this isn't the right forum...

Many thanks in advance!

/Mats Helander

 
 
 

Finding the Identity column

Post by Anith Se » Fri, 18 Oct 2002 10:54:37


Try:

SELECT t1.TABLE_NAME,
       c1.COLUMN_NAME
  FROM INFORMATION_SCHEMA.TABLES  t1
 INNER JOIN INFORMATION_SCHEMA.COLUMNS c1
    ON t1.TABLE_NAME = c1.TABLE_NAME
 WHERE c1.TABLE_SCHEMA = 'dbo'
   AND t1.TABLE_TYPE = 'BASE TABLE'
   AND COLUMNPROPERTY(OBJECT_ID(c1.TABLE_NAME),
                        c1.COLUMN_NAME, 'IsIdentity') = 1

--
- Anith

 
 
 

Finding the Identity column

Post by Mats Helande » Fri, 18 Oct 2002 11:36:12


Big thanks, it works super!

All the best

/Mats


Quote:> Try:

> SELECT t1.TABLE_NAME,
>        c1.COLUMN_NAME
>   FROM INFORMATION_SCHEMA.TABLES  t1
>  INNER JOIN INFORMATION_SCHEMA.COLUMNS c1
>     ON t1.TABLE_NAME = c1.TABLE_NAME
>  WHERE c1.TABLE_SCHEMA = 'dbo'
>    AND t1.TABLE_TYPE = 'BASE TABLE'
>    AND COLUMNPROPERTY(OBJECT_ID(c1.TABLE_NAME),
>                         c1.COLUMN_NAME, 'IsIdentity') = 1

> --
> - Anith

 
 
 

1. finding autonumber (identity) column with OLEDB for Jet 4.0

Hi --

I'm trying to use the ADO schema recordsets from VB to get schema
information for an Access database. In particular, I'm trying to determine
whether a given column is an identity column.

The ADO Columns schema recordset has a COLUMN_FLAGS field, which supposedly
gets its values from the DBCOLUMNFLAGS enum.

But the values I'm getting back via ADO don't correspond to any of the
expected bit combinations provided by DBCOLUMNFLAGS.

For example, the DBCOLUMNFLAGS_ISROWID bit has a value of 256, but the
values I'm getting back from my Columns schema recordset (tested on
Northwind.mdb) are nowhere near that high. The autonumber columns seem to be
coming back as 90.

Here's the code. Am I doing something wrong? Is there any other way to
identify an autonumber column with the Jet provider?

    ' Open schema recordset.
    Set rstCols = connFrom.OpenSchema(adSchemaColumns, Array(Empty, Empty,
strTable))

    With rstCols
        Do Until .EOF
            Debug.Print !TABLE_NAME, !COLUMN_NAME, !COLUMN_FLAGS
            .MoveNext
        Loop
    End With

2. About interbase's datetime

3. HOW do I find an identity column

4. help

5. how to alter an identity column to a non-identity column

6. Please comments This Tablespace Setup

7. How to change an identity column to non identity column

8. pgsql/src/interfaces/ecpg/lib (data.c)

9. How do make an identity column NOT an identity column

10. Using OpenSchema to find AutoNumber or IDENTITY columns

11. How to find Identity column?

12. Find/change Identity value of column?

13. How to find skipped number in identity column ?