We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
ALTER PROCEDURE [dbo].[stU_GetIdentityFieldName] @tableName varchar(500), @identityFieldName varchar(500) output AS BEGIN set nocount on create table #identity (name varchar(1000)) --make sure this isn't a temp table if @tableName not like '[#]%' begin exec(' declare @name varchar(100) declare c cursor for select name from syscolumns where ID = object_ID(N''[' + @tableName + ']'') open c fetch next from c into @name while @@fetch_status = 0 begin if (select columnproperty(object_ID(N''[' + @tableName + ']''), @name, ''IsIdentity'')) = 1 insert #identity select @name fetch next from c into @name end close c deallocate c ') select @identityFieldName = name from #identity end else begin --if we have a temp table, we can't find it print('As of now, we know no way of determining a sure-fire way of finding an identity column on a temporary table.') end set nocount off end
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.