You are here: Re: Primary key generating « MsSQL Server « IT news, forums, messages
Re: Primary key generating

Posted by mutemode on 10/02/02 11:56

Thanks! Worked great. Sorry for not understanding it earlier Zeldor :)
Alexander Kuznetsov wrote:
> SET NOCOUNT ON
> go
>
> CREATE TABLE Target(TargetID INT PRIMARY KEY, someData CHAR(1))
> INSERT Target VALUES(1, 'A')
> INSERT Target VALUES(2, 'B')
> go
> create table staging(someData CHAR(1))
> INSERT staging VALUES('C')
> INSERT staging VALUES('D')
> go
> SELECT IDENTITY(INT, 1,1) AS TargetID, someData
> INTO #t FROM staging
>
> INSERT Target
> SELECT TargetID + (SELECT COALESCE(MAX(TargetID), 0) FROM Target),
> someData
> FROM #t
>
> go
> SELECT * FROM Target
> go
>
> TargetID someData
> ----------- --------
> 1 A
> 2 B
> 3 C
> 4 D
>
>
> DROP TABLE Target
> DROP TABLE Staging
> DROP TABLE #t

 

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

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