Re: query for identity columns

From: Gregory A. Larsen (greg.larsen_at_netzero.com)
Date: 05/20/04


Date: Thu, 20 May 2004 14:09:35 -0700

Try this:

master.dbo.sp_MSforeachdb 'SELECT ''?'' , TABLE_NAME, COLUMN_NAME,
DATA_TYPE, IDENT_CURRENT(TABLE_NAME)
  FROM ?.INFORMATION_SCHEMA.COLUMNS
 WHERE TABLE_SCHEMA = ''dbo''
   AND COLUMNPROPERTY(OBJECT_ID(TABLE_NAME),
                            COLUMN_NAME, ''IsIdentity'') = 1
 ORDER BY TABLE_NAME'

-- 
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Hassan" <fatima_ja@hotmail.com> wrote in message
news:O8QA0qqPEHA.1620@TK2MSFTNGP12.phx.gbl...
> Neat Anith..
>
> How can i take it to the next step and run the same for every database. I
> know theres something tricky while using a cursor for each database
>
> I would like to run this query on a particular server and list all the
> columns you provided except for that it loops through all user databases
> too. Could you help me here
>
> Thanks
>
> "Anith Sen" <anith@bizdatasolutions.com> wrote in message
> news:eeGUiUqPEHA.644@tk2msftngp13.phx.gbl...
> > Do:
> >
> > SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IDENT_CURRENT(TABLE_NAME)
> >   FROM INFORMATION_SCHEMA.COLUMNS
> >  WHERE TABLE_SCHEMA = 'dbo'
> >    AND COLUMNPROPERTY(OBJECT_ID(TABLE_NAME),
> >                             COLUMN_NAME, 'IsIdentity') = 1
> >  ORDER BY TABLE_NAME ;
> >
> > -- 
> > Anith
> >
> >
>
>


Relevant Pages

  • Re: SQL sever 2000 security
    ... but there is no security tab on my SQL server 2000. ... "Hassan" wrote: ... >> Database. ...
    (microsoft.public.sqlserver.server)
  • Re: MS Access DAO -> ADO.NET Migration
    ... William Vaughn ... Microsoft MVP ... Hitchhiker's Guide to Visual Studio and SQL Server ... My migration app works building a SSCE database file with imported data ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Cluster will not fail over.
    ... > As far as the TCP/IP issue goes, you had to rebuild the cluster and were ... > able to restore the master database. ... > a cluster installation you'll have to revisit. ... >> This worked bringing up the sql server in minimal mode. ...
    (microsoft.public.sqlserver.clustering)
  • Re: MS Access DAO -> ADO.NET Migration
    ... full SQL Server and I see the logic you explained in a multi user ... allow two users to access the same database file Read/Write at any given ... The book was a pleasure to read after the gibberish that Microsoft 'puts ... Hitchhiker's Guide to Visual Studio and SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: MS Access DAO -> ADO.NET Migration
    ... For that it is much harder to handle the incremental identifier, ... database but although they have the data, they are not connected at the same ... The book was a pleasure to read after the gibberish that Microsoft 'puts ... SQL Server Management Studio is nowhere to be found on my ...
    (microsoft.public.dotnet.framework.adonet)