Insert into MySQL problem

Is there a way to make the insert statement return the ID of the inserted record?

Comments

  • : Is there a way to make the insert statement return the ID of the inserted record?


    No, you will have to write a second sql statement to check which ID is the last in the table. (sql statement is void)
  • : : Is there a way to make the insert statement return the ID of the inserted record?
    :
    :
    : No, you will have to write a second sql statement to check which ID is the last in the table. (sql statement is void)
    :
    It IS possible. After the insert statement, use the mysql function sql_insert_id() (not sure if I spelled it correctly, look in the MySQL manual). That will return the latest value of an inserted auto-increment field.
    But this is not really the right board for this.

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


  • : : : Is there a way to make the insert statement return the ID of the inserted record?
    : :
    : :
    : : No, you will have to write a second sql statement to check which ID is the last in the table. (sql statement is void)
    : :
    : It IS possible. After the insert statement, use the mysql function sql_insert_id() (not sure if I spelled it correctly, look in the MySQL manual). That will return the latest value of an inserted auto-increment field.
    : But this is not really the right board for this.
    :
    : Greets,
    : Eric Goldstein
    : http://www.gvh-maatwerk.nl
    :
    :
    :
    It is possible! After the insert statement you execute "select last_insert_id()" and it returns just that. For more info:

    http://dev.mysql.com/doc/refman/5.0/en/information-functions.html

    Thanks Eric!
  • : : Is there a way to make the insert statement return the ID of the inserted record?
    :
    :
    :Yes. you can function SCOPE_IDENTITY() this function Returns the last identity value inserted into an identity column in the same scope.
    for exampe to insert you can use this code
    [code]
    INSERT INTO customer (name, last_name) VALUES ('amigo','amigo')
    SELECT "ID inserted" = SCOPE_IDENTITY()
    [/code]
    bye.
  • : : : Is there a way to make the insert statement return the ID of the inserted record?
    : :
    : :
    : :Yes. you can function SCOPE_IDENTITY() this function Returns the last identity value inserted into an identity column in the same scope.
    : for exampe to insert you can use this code
    : [code]
    : INSERT INTO customer (name, last_name) VALUES ('amigo','amigo')
    : SELECT "ID inserted" = SCOPE_IDENTITY()
    : [/code]
    : bye.
    :
    SCOPE_IDENTITY() ?? Is that MySQL?

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories