I need to obtain the id of the last record inserted in my table (SQL database). I believe I need to use SCOPE_IDENTITY().
My code looks like this:
my $dbh = DBI -> connect("$dsn; server=$host; Database=$database", $us
+er, $auth, \%attr) || die "database connection not made: $DBI::errstr
my $sth = $dbh -> prepare("INSERT INTO ocr_main (project_number, lead_
+order, employee_id, due_date, ocr_type, line_item, mech_rnr, mech_rfd
+, mech_rfa, mech_dre, ctrl_rnr, ctrl_rfd, ctrl_rfa, ctrl_dre) VALUES
+(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") || die "unable to prepar
$sth -> execute($project_number, $lead_order, $employee_id, $due_date,
+ $ocr_type, $line_item, $mech_rnr, $mech_rfd, $mech_rfa, $mech_dre, $
+ctrl_rnr, $ctrl_rfd, $ctrl_rfa, $ctrl_dre);
$sth -> finish();
$dbh -> disconnect();
I'd like to save the last inserted id in the variable 'id'. This is very straight forward in mySQL, but I'm having difficulty doing it in SQL. Can someone show me the proper syntax please? Thank you so much.