Results 1 to 5 of 5

Thread: [RESOLVED] SQL Server CE autoIncrement???

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Resolved [RESOLVED] SQL Server CE autoIncrement???

    Hi guys,

    How do i get a column in one of my tables to auto increment everytime i add a new row???

    I am using Sql Server CE and am fairly new to databases and sql.

    Thanks in advance for any help
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: SQL Server CE autoIncrement???

    When your create the table use the identity keyword.
    Code:
    key decimal(18, 0) IDENTITY (1, 1) NOT NULL
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: SQL Server CE autoIncrement???

    Works perfectly. Thanks

    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Member
    Join Date
    May 2005
    Posts
    53

    Re: [RESOLVED] SQL Server CE autoIncrement???

    You could just take care of this yourself.

    Just run a sql statement to see what the max value for that column is and then add one to it then run the insert statement using this new value for one of the columns.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [RESOLVED] SQL Server CE autoIncrement???

    I knew i could've done that but i also knew there was an easier way to do it which is why i asked.
    Its a lot neater and its one line of code whereas if i'd did it the way you suggest then it would've been a lot more!
    Thanks anyways
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

Posting Permissions

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



Click Here to Expand Forum to Full Width