SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Belfast75's Avatar
    Join Date
    Oct 2005
    Location
    London, England
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert a record and retrieve the unique ID

    Hi,

    I am inserting a record into a table to hold information about photos and what to create a folder with the same name as the primary key value of the inserted record.

    Eg if I have a table (tblAlbum) with two fields (albumID, albumName) and run an insert statement 'INSERT INTO tblAlbum (albumName) VALUES ('test album')`

    I want to then create a folder with the new value for albumID.

    How do I retrieve this new value just created?

    Many thanks,
    Des

  2. #2
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    bill, both those articles recommend @@IDENTITY

    however, best practice is to use SCOPE_IDENTITY instead

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    best practice is to use SCOPE_IDENTITY instead
    i'll have to look that up then, thanks for the heads up...

  5. #5
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it doesn't look like scope_identity works with Access though and for some reason think that's probably what is being used here...

  6. #6
    SitePoint Addict Belfast75's Avatar
    Join Date
    Oct 2005
    Location
    London, England
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the help, I'll be looking at this over the weekend.


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
  •