Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Autonumber Data Type in SQL Server 2K

    I have a database created in SQL 2K that I wanted to bind a VB.Net app to (just started using .NET). When using the wizard by dragging the connection to the form, it tells me that there was an error establishing the update or delete routine due to not being able to identify the unique field for the record. I went into SQL server and was hoping, like in Access, where you can use an autonumber datatype and it would enumerate the blank fields for each record and add one to any new records from then on. I found a datatype of Uniqueidentifier (or something close to that) but it didn't work like that.

    Is there an autonumber equivillant in SQL Server 2K or how is it done?

  2. #2
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Redditch, Worcestershire, England
    Posts
    233
    Thanks
    0
    Thanked 22 Times in 21 Posts

    Re: Autonumber Data Type in SQL Server 2K

    I'm away from my MSDE / SQL info at present but I think you need to specify a column with the IDENTITY key word and optionally specify a seed (starting value) and increment (how much each value increases by if not the default of 1).

    Something like CREATE TABLE blah-blah-blah column-name IDENTITY(seed, increment) etc
    when creating a table

    or ALTER TABLE ADD column col-name IDENTITY(seed, increment) when altering an existing table.

    Look up IDENTITY in your documentation / books online and it should tell you everything you need to know.

    Jeremy

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Autonumber Data Type in SQL Server 2K

    Thanks Jeremy. I looked it up and figured it out. All I had to do (and I'm posting this more for others in case they have the same issue) was go into design view of the table, right click on the column and select Properties, then under the Table Identity Column field of the property box I selected the column. It is required that the column be of int or numeric type (other numeric types I'm sure work too) and it immediately autonumbered my existing records and will increment for new records.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •