Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003

    Unanswered: Default Record ID's

    There has to be somehow the SQL server uniquely identify each record in a db.

    I am developing a web app to interface with an MsSQL Server. But in order to delete and update records I need to uniquely identify each record. I know you can do this with int IDENTITY columns, but not every DB table has a int IDENTITY column, so, what I am asking is, is there anyplace where I can query to find out an ID or something of the sort for a record in a db.


  2. #2
    Join Date
    Jun 2003
    Provided Answers: 1
    No, records have no inherant or permanent ID in SQL server unless the database designer specifies one, either through a surrogate key or a natural unique key.

    For example, a table with no primary key is called a "heap", and new SQL developers frequently make the mistake of assuming that the data in a heap is in a reliable, predicatable, and fixed order. It is not. While data is appended to a heap in the order it is inserted, the order can be shuffled over time by updates to the table, which cause rewrites to portions and thus change their location.

    A well designed database will have a unique way of identifying each record. If the database you are working with does not have one, then you will need to add either an autoincrement field or a GUID field to each table. Autoincrements are integers and thus take up less space and sort/search very quickly. GUIDs have the advantage of being unique not just within a table, but across the entire database and even between databases.


  3. #3
    Join Date
    Feb 2002
    If your table has no primary key,unique constraint... then your entire table could have identical records. So unless your table was created with the proper constraints, you have no way of knowing. As already mentioned, if no unique identifier exists you can create one - but you still have to decide which data is valid and which you can delete - but in your case if you have identical information how are you distinguishing now ?

Posting Permissions

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