Final answer:
To get the ID of the last inserted row in SQL, use LAST_INSERT_ID() in MySQL or SCOPE_IDENTITY() in SQL Server. These functions return the last auto_increment ID value inserted into a table.
Step-by-step explanation:
To get the ID of the last inserted row in SQL, you can use different methods depending on the SQL database management system you are using. For instance, in MySQL, you can retrieve the last inserted ID by using the function LAST_INSERT_ID(), which will return the ID of the last row that was inserted into a table with an auto_increment column. Similarly, in SQL Server, use the SCOPE_IDENTITY() function to accomplish this task.
T-SQL (SQL Server) example:
INSERT INTO YourTable (column1, column2, ...)
VALUES (value1, value2, ...);
SELECT SCOPE_IDENTITY();
MySQL example:
INSERT INTO YourTable (column1, column2, ...)
VALUES (value1, value2, ...);
SELECT LAST_INSERT_ID();