Friday, February 10, 2012

Autonumber

Hi
How does one set an auto-number field in sql server 2005? Is this a good way
to generate primary keys? If not, could I have some recommendations?
Thanks
RegardsYou have to use the IDENTITY property of the column to produce auto number.
For example:
CREATE TABLE dbo.x (c1 int IDENTITY(1, 1), c2 int)
GO
It is not really the ideal way to generate a primary key, but people do use
it for that purpose. If you could tell us about your table, may be someone
can suggest a better way.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"John" <John@.nospam.infovis.co.uk> wrote in message
news:OJMWrZrZFHA.2520@.TK2MSFTNGP09.phx.gbl...
Hi
How does one set an auto-number field in sql server 2005? Is this a good way
to generate primary keys? If not, could I have some recommendations?
Thanks
Regards|||You can use this. But you should have a look on that article before.
http://www.sqlservercentral.com/col...ntitycrisis.asp
So be careful of what you need before.
--
P.RUELLO
DBA
"John" wrote:

> Hi
> How does one set an auto-number field in sql server 2005? Is this a good w
ay
> to generate primary keys? If not, could I have some recommendations?
> Thanks
> Regards
>
>|||It's a "companies" table that needs an id column. Also records in
"individual contacts" table are tied to their company record in "companies"
table via this id.
Thanks
Regards
"Narayana Vyas Kondreddi" <answer_me@.hotmail.com> wrote in message
news:%23hZJmerZFHA.3032@.TK2MSFTNGP10.phx.gbl...
> You have to use the IDENTITY property of the column to produce auto
> number.
> For example:
> CREATE TABLE dbo.x (c1 int IDENTITY(1, 1), c2 int)
> GO
> It is not really the ideal way to generate a primary key, but people do
> use
> it for that purpose. If you could tell us about your table, may be someone
> can suggest a better way.
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "John" <John@.nospam.infovis.co.uk> wrote in message
> news:OJMWrZrZFHA.2520@.TK2MSFTNGP09.phx.gbl...
> Hi
> How does one set an auto-number field in sql server 2005? Is this a good
> way
> to generate primary keys? If not, could I have some recommendations?
> Thanks
> Regards
>
>

No comments:

Post a Comment