wrote:
> Matt Brown - identify wrote:
>
> > Hello,
>
> > Several consecutive records have been deleted out of an MSDE database
> > and the program that uses the database doesn't like it. I'm curious
> > if it's possible to... say... reset the primary key count so that the
> > records all shift to fill the "dead space" left by the deleted
> > records.
>
> > I have the feeling that this may be humorous to some of you, but any
> > input (including "you can't do this. that's the point of a primary
> > key") is appreciated.
>
> ooopppsss...
> Hugo is right, completely right... I did not read with enougth attention and
> only saw the "identity" resetting requirement... I'm sorry..
> I'm just curious why "..program that uses the database doesn't like it.." :D
> Agreeing completely with Hugo about the "keys" immutability, you can perhaps
> workaround that..
> you could create a "temporary" table where you insert all the current valid
> rows of your table, truncate the original table in order to empty it and to
> reset the idientity table's value, and finally refill it with the "orphaned"
> rows..
> so you can write something like
> INSERT INTO tempTable SELECT * FROM dbo.YourTable WHERE... ORDER BY...;
>
> TRUNCATE TABLE dbo.YourTable;
>
> INSERT INTO dbo.YourTable (all_columns_but_the_identity_col)
> SELECT all_columns_but_the_identity_col
> FROM tempTable
> WHERE... ORDER BY...;
>
> DROP TABLE tempTable;
>
> but, again, this is a "poor strategy"... you'll end up with gaps anyway, now
> or then.. and this "workaround" does not work if you have declarative
> referential integrity set on that table, if it's referenced by other rows in
> other tables...
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://italy.mvps.org > DbaMgr2k ver 0.21.0 - DbaMgr ver 0.65.0 and further SQL Tools
> --------- remove DMO to reply
I haven't checked this is a while. That's actually perfect. I can