You are here: Re: adding identity column dynamically « MsSQL Server « IT news, forums, messages
Re: adding identity column dynamically

Posted by Erland Sommarskog on 11/16/05 17:34

Sam (samuel.berthelot@voila.fr) writes:
> In my stored procedure I'm doing a SELECT on
> INFORMATION_SCHEMA.TABLE_CONSTRAINTS. However there is no unique id on
> this table, so I was wondering if it was possible to add it dynamically
> in my SELECT, so that I would assign a unique id to each record
> returned by my SELECT?

There should be no need for this. There is a unique key in
(CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME).

To get an IDENTITY column you could bounce over a temp table with:

SELECT ident = IDENTITY(int, 1, 1), CONSTRAINT_CATATLOG, ...
INTO #temp
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE ...

SELECT * FROM #temp

But, as I said there is no need to do this.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация