473,378 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 5782
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom | last post by:
Anyone help on this? PHP/MySQL I have a repeat region displaying records from orders in a CSV format: CalJoe33,18,08/23/2004,FED EX,PREPAID,WEBSITE,CA,Book,25.95,??? CalJoe33,18,08/23/2004,FED...
8
by: JD via AccessMonster.com | last post by:
I am trying to create a field where the primary key field will produce JDP- 001; where the three letters come from the first name, middle intial and last name of my table. I want to auto increment...
2
by: Glenn | last post by:
I have a grid view which takes its data from an SQL query. The query returns a league Table of results. I would like to a add a column which show the poistion of result (i.e 1,2,3,4) how can i...
7
by: jwhitby3 | last post by:
Hi all, I am trying to develop what amounts to a data entry page for the company I work for, (mostly to make my job easier). I think that I am beginning to grasp php, but I am at a loss now. I...
1
by: senger.kim | last post by:
Hello World, I'm relatively new to MS Access (2003) and am trying to implement something that I feel should be simple but cannot find a solution. Hoping that you can help me or point me where to...
7
by: Roger | last post by:
Is it possible to increment the array index in a for loop? I want to make a program where the user inputs numbers individually and then store them into an array. For each integer input, the array...
1
by: RubyRue | last post by:
Hi Looking for a bit of help. I have a request form that when a user opens a new request it populates the ref number straight away. What I'd like it to do it check the db to see what the last...
8
by: TXpugslave | last post by:
And here it is. I'm just, JUST learning how to use perl, and how to do any sort of programming in general. I'm trying to self-teach and have read a book on C programming and wanted to try PERL. I'm...
1
by: asandiego | last post by:
Hey guys, this is my first post here but have been checking this site a lot for anything I need. I hope someone can lead me to what I should do or just an idea to what can be done. What I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.