473,549 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...weir d.
Anyways, I'm just a rookie in sql, any help would be appreciated
Thanks
JMT

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

<bi****@hotmail .com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.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...weir d.
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******** *************@g 47g2000cwa.goog legroups.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...weir d.
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
2567
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 EX,PREPAID,WEBSITE,CA,Poster,10.00,??? CalJoe33,18,08/23/2004,FED EX,PREPAID,WEBSITE,CA,Video,49.95,??? I need to have a column where I can...
8
3474
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 only if the three letters are reproduced. e.g. JDP-001 JDP-002 YPT-001 YRT-001 RPT-001
2
1151
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 get add a column which simply showns an incremented number for each row.
7
1917
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 understand how to use HTML_Table to add a table to a page, and that portion of my project is coming along nicely. The problem is at this point, that I...
1
1624
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 seek more help. Let's start with a hypothetical database: ID Name 1 Peter
7
5466
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 index will increment to store the number. Is this possible? I'm thinking of ArrayList in Java where the array can dynamically expand, does C++...
1
941
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 number was and increment it by 1 and that is the new ref number, they can then fill it out and submit it. However there is also another part where...
8
1526
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 really very green at this and don't want to give up, but its not always easy to move forward without help so here goes. I have this simple, simple...
1
3500
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 trying to do: I have a Form that has a subform. My primary form has a field that autonumber and this field has a one to many relationship to a field in my...
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.