DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    13

    Need advice/example autonumbering column in a table

    I've been assigned to do the data access layer for an existing SQL database created by someone else. Amazingly enough, the primary table, the one containing all of the records that are central to the db and the whole project, has over 3000 entries and no unique identifer (autonumbered ID) column. The data in all of the other columns is repetitious so none of them can be used as a primary key. I have added a column called TaskAssignmentID, designated as an int data type. The goal is to somehow autofill this column with sequential numbers and then designate that column as the primary key. (don't you just love fixing other people's mistakes?) Any suggestions/examples on how to accomplish this the easiest, most efficient way?

    For reference purposes, the table is called tbl_MCHS and the newly created column is called TaskAssignmentID. The data type of the column can be changed, if that would make it easier.

    Tools available include Visual Studio 2005 (very familiar) and SQL Server 2005's SQL Server Management Studio (less familiar).

    Things I am restricted from doing include blowing away the table and starting over or strangling the previous developer (I asked about both). :-)

    Any and all suggestions, steps, or examples will be appreciated.

    Thanks,

    Diverguy

  2. #2
    Join Date
    Sep 2006
    Posts
    13
    Please disregard. Someone provided me with code that worked. Ran this query in the SQL Server Management Studio:

    alter table tbl_MCHS
    add TaskAssignmentID int identity(1,1) primary key

    That did the trick.

Similar Threads

  1. Change a column name
    By Jawahar Rajan in forum Database
    Replies: 3
    Last Post: 04-24-2002, 09:54 AM
  2. JTable problem
    By satish in forum Java
    Replies: 1
    Last Post: 02-23-2002, 01:44 AM
  3. Replies: 1
    Last Post: 11-05-2001, 03:01 PM
  4. Replies: 2
    Last Post: 11-03-2001, 01:57 AM
  5. How can you INSERT (not APPEND) a column in a table?
    By Dani Sardà in forum Database
    Replies: 6
    Last Post: 03-13-2001, 02:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links