Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Autonumbering

Author  Topic 

bwill1980
Starting Member

1 Post

Posted - 2009-02-12 : 05:03:12
Dear All,

I have a small SQL database that users imput data via Access.

There are two main fields in the table tbProjects

ProjectID (int, autonumber, primary key, hidden)
ProjectNumber (numeric, no user entry)

The table also contains other fields

After the user has completed data entry for a record and clicked ok, I need SQL to assign an project number to the ProjectNumber field and display it in a windiow.

The project numbers are incremental e.g 4000 4001 4002

Can anyone help?

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-02-12 : 05:24:20
use an identity field if they are incremental, usage is

create table <tablename>
ProjectNumber numeric(15,0) identity(<startseed>,<increment>) NOT NULL,
<...>
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-12 : 05:46:01
if ur table is already created with out identity columns
do as
right click on tablename and click on design mode
in column properties identityspecification --> yes --> give value as idetnity seed as 4000 and identity increment as 1
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-02-12 : 07:27:58
eventhough u change in design mode, if ur table has already data it will not allocate autonumber starting from 4000 to already existing records. It will allocate numbers by autoincrementing for new records which are inserted after setting identity property
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-02-12 : 07:30:35
see this

http://www.mssqltips.com/tip.asp?tip=1397
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-12 : 09:37:16
you could however alter table to add a new identity column which will get autonumbered automatically starting from your prescribed seed value.
Go to Top of Page
   

- Advertisement -