Maziar Aflatoun (maz00@rogers.com) writes:
[quoted text, click to view] > Is there a way in SQL to define an Auto Increment column which is always
> in order, even after removing elements from the middle.
>
> For instance, currently if you define something as Auto Increment it
> will be like
> 1,2,3,4,5,6,7,8,9,10 however, if you remove rows 4 and 9 then it will be
> 1,2,3,5,6,7,8,10
>
> I want it to always remain as Ex. ID=1,2,3,4,5,6,7,8,9 and when you delete
> row 4 I want to read 1,2,3,4,5,6,7,8
SQL Server MVP Fernando Guerrero had an article about this in SQL Server
Magazine a couple of years back. You can search the archives at
www.sqlmag.com, although you have to be a subscriber to access the article.
However, I would ask to think twice before you implement anything like
this. It will cost some machine power to maintain this, and it might
be only moderately useful.
You are probably better off numbering when you select as David Portas
suggested.
[quoted text, click to view] > Also, What is the purpose of defining a #Temp table vs. regular table?
A temp table goes away when the scope you created it in, goes away.
That is, if you create a temp table in a stored procedure the table
goes away when the procedure exists. The same happens if you create it
in a piece of dynamic SQL. If you submit a CREATE TABLE command directly
from the client, the table goes away when you disconnect.
Temp tables are mainly used to store intermediary results for data that
is not to be persisted.
[quoted text, click to view] > also how do you define it in SQL Server Enterprise Manager?
I have no idea if you can (I never create tables from EM), but it seems
like a pointless thing to do, for the reasons I described above.
--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se
Books Online for SQL Server SP3 at