469,588 Members | 2,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

Incrementing number in a column -- rookie sql user

Sorry to bother you guys with what I though would be an easy task. I
have a table in my database were I would like one of the rows to
increment a number for each row. I want the first row to start at 1000
and keep on incrementing by 1 'till the end of the rows (about 2.7
million rows). I though this would be a piece of cake, but I just can't
seem to find anything like it on the internet...weird.
Anyways, I'm just a rookie in sql, any help would be appreciated
Thanks
JMT

Jul 23 '05 #1
6 5631
MC
look in the BOL under the 'identity'. Its a column property....
MC

<bi****@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Sorry to bother you guys with what I though would be an easy task. I
have a table in my database were I would like one of the rows to
increment a number for each row. I want the first row to start at 1000
and keep on incrementing by 1 'till the end of the rows (about 2.7
million rows). I though this would be a piece of cake, but I just can't
seem to find anything like it on the internet...weird.
Anyways, I'm just a rookie in sql, any help would be appreciated
Thanks
JMT

Jul 23 '05 #2
Sorry to sound so dumb, but what is the BOL, and what steps do I have
to take to set that property column ??

Jul 23 '05 #3
I found out that BOL is Books Online and found the Identity poperty.
But running this in my sql query gives me error:
************************
Incorrect syntax near the keyword 'IDENTITY'.

Alter TABLE [dbo].[Microsoft]
Alter Column [Barcode] [int] IDENTITY (1000, 1) NOT NULL
************************
Microsoft is my table name and Barcode is my column name.

What am I doing wrong ??
Thanks for the reply!!

JMT

Jul 23 '05 #4
BOL is Books Online, the MSSQL documentation. It's installed with MSSQL
or the client tools (but not MSDE), but you should grab the latest
version from the Microsoft download site - there have been a couple of
updates since the product shipped.

You can add a column with ALTER TABLE:

alter table dbo.MyTable add NewCol int not null identity(1000,1)

You can't control which row gets which identity value, so adding a
column like this is probably only useful as an artificial key.

Simon

Jul 23 '05 #5
Thanks alot Simon,
It worked fine for what I need. Just needed to generate different
numbers for every row in my table of 2.7 million rows. It does the job
wonderfully !!

Later and thanks again

JMT

Jul 23 '05 #6

<bi****@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Sorry to bother you guys with what I though would be an easy task. I
have a table in my database were I would like one of the rows to
increment a number for each row. I want the first row to start at 1000
and keep on incrementing by 1 'till the end of the rows (about 2.7
million rows). I though this would be a piece of cake, but I just can't
seem to find anything like it on the internet...weird.
Anyways, I'm just a rookie in sql, any help would be appreciated
Thanks
First thing to understand.

There is no concept of "first row" or "last row" in a table. It's an
unordered set.

The only way to specify an order when doing a query is with an order by in
the query.

JMT

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tom | last post: by
8 posts views Thread by JD via AccessMonster.com | last post: by
2 posts views Thread by Glenn | last post: by
1 post views Thread by senger.kim | last post: by
7 posts views Thread by Roger | last post: by
1 post views Thread by RubyRue | last post: by
8 posts views Thread by TXpugslave | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.