Can someone explain this code for me pls!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    Can someone explain this code for me pls!

    Hi Folks,

    this may seem very lazy, but can someone exaplin this bit of code for me?

    regID int IDENTITY(0,1)

    It is part of an SQL CE command in a VB app, but I just don't get what the regID in IDENTITY (0,1) is in there for.

    the full code is

    Code:
     'Create SQL command to create the tblDetails table
    
    Dim cmdTabla As New SqlCeCommand("CREATE TABLE tblDetails(regID int IDENTITY(0,1) PRIMARY KEY, Flower_ID NTEXT, Name_Eng NTEXT, Name_Lat NTEXT, Location_ID NTEXT, Habitat_ID NTEXT, Season_ID NTEXT, Family_ID NTEXT, Size NTEXT, Description NTEXT)", conn)
    Sorry I havent trimmed the code for the window, don't really think it matters here.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. This statement is using CREATE TABLE and refers to one of the columns in the new table, tblDetails
    regID int IDENTITY(0,1)

    regID is the name of the column
    int is the data type
    IDENTITY means this is an autonumber or auto-increment field
    (0,1) the zero is the seed or starting number. The one is the increment, i.e. each new record will increment by one.

    Comment

    • markmcgookin
      Recognized Expert Contributor
      • Dec 2006
      • 648

      #3
      Originally posted by willakawill
      regID is the name of the column
      int is the data type
      IDENTITY means this is an autonumber or auto-increment field
      (0,1) the zero is the seed or starting number. The one is the increment, i.e. each new record will increment by one.
      Hi, I understand the create etc.. However when I open the table in SQL Server CE the Reg "column" that it appears the code creates does not appear as a standard column, I created multiple tables and from what I gather the

      CREATE TABLE **TABLENAME** (regID int IDENTITY(0,1) stays the same for each one. However it seems to produce different values for the Identity/reg in SQL viewer.

      I am not even sure if this is important to my system design, I just like to understand all my code, and don't see why I am including this. Just wanted to know why it was there.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        An identity column is not a standard column. You cannot update it. It is controlled by the database.

        Comment

        • markmcgookin
          Recognized Expert Contributor
          • Dec 2006
          • 648

          #5
          Originally posted by willakawill
          An identity column is not a standard column. You cannot update it. It is controlled by the database.
          Ah so is it just one of those things thats there that you shouldn't ask about? It works .. so don't touch?

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by markmcgookin
            Ah so is it just one of those things thats there that you shouldn't ask about? It works .. so don't touch?
            Not at all. You should understand the tools you're working with. It's just that in this case you are defining a field with parameters that indicate the database software should provide the values automatically, so you cannot update the field.

            Comment

            Working...