Retrieve inserted row ID in SQL

前端 未结 4 1227
感情败类
感情败类 2020-12-06 02:11

How do I retrieve the ID of an inserted row in SQL?

Users Table:

Column  | Type
--------|--------------------------------
ID      | * Auto-incremen         


        
4条回答
  •  星月不相逢
    2020-12-06 03:03

    In Oracle and PostgreSQL you can do this:

    INSERT INTO some_table (name, age)
    VALUES
    ('charuka', 12)
    RETURNING ID
    

    When doing this through JDBC you can also do that in a cross-DBMS manner (without the need for RETURNING) by calling getGeneratedKeys() after running the INSERT

提交回复
热议问题