Monday, March 12, 2012

IDENTITY on non-PK

Is there a way to have an "autonumber" on a non-Primary Key column in SQL
Server?
Thanks,
Ericyou can use IDENTITY on any field, regardless of whether it is a PK
<Eric> wrote in message news:OitsJtRQFHA.576@.TK2MSFTNGP15.phx.gbl...
> Is there a way to have an "autonumber" on a non-Primary Key column in SQL
> Server?
> Thanks,
> Eric
>
--== Posted via mcse.ms - Unlimited-Uncensored-Secure Usenet News==-
--
http://www.mcse.ms The #1 Newsgroup Service in the World! 120,000+ New
sgroups
--= East and West-Coast Server Farms - Total Privacy via Encryption =--|||Sure, as long as it's the only one in the table.
Thomas
<Eric> wrote in message news:OitsJtRQFHA.576@.TK2MSFTNGP15.phx.gbl...
> Is there a way to have an "autonumber" on a non-Primary Key column in SQL
> Server?
> Thanks,
> Eric
>|||Sorry...I worded that poorly.
Suppose you already have a PK column that is an identity column. It also
has the identity seed and increment specified.
As Thomas said, you can only have one identity column per table. Is there
an easy way, then, to mimic the identity seed and identity increment
properties on a different column besides the PK?
Thanks,
Eric
<Eric> wrote in message news:OitsJtRQFHA.576@.TK2MSFTNGP15.phx.gbl...
> Is there a way to have an "autonumber" on a non-Primary Key column in SQL
> Server?
> Thanks,
> Eric
>|||You can generate an incrementing key with an INSERT statement but that isn't
the same as an IDENTITY.
http://www.google.co.uk/groups?selm...r />
roups.com
Please explain your requirement. Why do you want to generate two artificial
keys?
David Portas
SQL Server MVP
--|||Thanks for the reply. It turns out my colleauge just needed to have a
sequential way to order search results while ignoring the primary key. He
just added a date/time column with a default of GETDATE(), and used "ORDER
BY myDate" in the SELECTs.
Eric
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:x8-dnQ-Q1IkZI8PfRVn-2g@.giganews.com...
> You can generate an incrementing key with an INSERT statement but that
isn't
> the same as an IDENTITY.
>
http://www.google.co.uk/groups?selm...ooglegroups.com

> Please explain your requirement. Why do you want to generate two
artificial
> keys?
> --
> David Portas
> SQL Server MVP
> --
>|||OK. Ordering by date makes much more sense than sorting on an artificial
key.
David Portas
SQL Server MVP
--

No comments:

Post a Comment