{"id":235423,"date":"2024-07-04T06:18:04","date_gmt":"2024-07-04T06:18:04","guid":{"rendered":"https:\/\/namso-gen.co\/blog\/?p=235423"},"modified":"2024-07-04T06:18:04","modified_gmt":"2024-07-04T06:18:04","slug":"how-to-get-primary-key-value-after-insert-in-sql","status":"publish","type":"post","link":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/","title":{"rendered":"How to get primary key value after insert in SQL?"},"content":{"rendered":"<p>When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that was generated for the inserted record. This primary key can be useful for further operations or for displaying to the user. Here&#8217;s how you can get the primary key value after an insert operation in SQL:<\/p>\n<p>**Use the LAST_INSERT_ID() function to retrieve the primary key value after an insert operation. This function returns the last automatically generated value that was set for an AUTO_INCREMENT column in the current session.**<\/p>\n<p>Here&#8217;s an example of how you can use the LAST_INSERT_ID() function after an insert operation:<\/p>\n<p>&#8220;`sql<br \/>\nINSERT INTO users (name, email) VALUES (&#8216;John Doe&#8217;, &#8216;john.doe@example.com&#8217;);<br \/>\nSELECT LAST_INSERT_ID();<br \/>\n&#8220;`<\/p>\n<p>In this example, after inserting a new record into the &#8220;users&#8221; table, the SELECT statement will return the primary key value that was generated for the inserted record.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#FAQs\" title=\"FAQs\">FAQs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#1_Can_I_use_the_MAX_function_to_get_the_primary_key_value_after_an_insert_operation\" title=\"1. Can I use the MAX() function to get the primary key value after an insert operation?\">1. Can I use the MAX() function to get the primary key value after an insert operation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#2_Is_it_possible_to_retrieve_the_primary_key_value_using_a_subquery\" title=\"2. Is it possible to retrieve the primary key value using a subquery?\">2. Is it possible to retrieve the primary key value using a subquery?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#3_What_happens_if_I_try_to_retrieve_the_primary_key_value_before_an_insert_operation\" title=\"3. What happens if I try to retrieve the primary key value before an insert operation?\">3. What happens if I try to retrieve the primary key value before an insert operation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#4_Can_I_get_the_primary_key_value_using_the_SCOPE_IDENTITY_function\" title=\"4. Can I get the primary key value using the SCOPE_IDENTITY() function?\">4. Can I get the primary key value using the SCOPE_IDENTITY() function?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#5_Is_it_possible_to_retrieve_the_primary_key_value_using_a_stored_procedure\" title=\"5. Is it possible to retrieve the primary key value using a stored procedure?\">5. Is it possible to retrieve the primary key value using a stored procedure?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#6_What_should_I_do_if_the_primary_key_is_not_an_auto-incrementing_column\" title=\"6. What should I do if the primary key is not an auto-incrementing column?\">6. What should I do if the primary key is not an auto-incrementing column?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#7_Can_I_get_the_primary_key_value_using_the_ROWCOUNT_function\" title=\"7. Can I get the primary key value using the ROWCOUNT function?\">7. Can I get the primary key value using the ROWCOUNT function?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#8_Is_there_a_way_to_retrieve_the_primary_key_value_without_executing_a_separate_SELECT_statement\" title=\"8. Is there a way to retrieve the primary key value without executing a separate SELECT statement?\">8. Is there a way to retrieve the primary key value without executing a separate SELECT statement?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#9_Can_I_use_the_OUTPUT_clause_in_SQL_Server_to_get_the_primary_key_value\" title=\"9. Can I use the OUTPUT clause in SQL Server to get the primary key value?\">9. Can I use the OUTPUT clause in SQL Server to get the primary key value?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#10_Are_there_any_limitations_to_using_the_LAST_INSERT_ID_function\" title=\"10. Are there any limitations to using the LAST_INSERT_ID() function?\">10. Are there any limitations to using the LAST_INSERT_ID() function?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#11_How_can_I_ensure_the_primary_key_value_is_unique_after_an_insert_operation\" title=\"11. How can I ensure the primary key value is unique after an insert operation?\">11. How can I ensure the primary key value is unique after an insert operation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#12_Can_I_retrieve_the_primary_key_value_using_a_trigger_after_an_insert_operation\" title=\"12. Can I retrieve the primary key value using a trigger after an insert operation?\">12. Can I retrieve the primary key value using a trigger after an insert operation?<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h3><span class=\"ez-toc-section\" id=\"1_Can_I_use_the_MAX_function_to_get_the_primary_key_value_after_an_insert_operation\"><\/span>1. Can I use the MAX() function to get the primary key value after an insert operation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nNo, the MAX() function retrieves the maximum value of a column, but it does not guarantee that it will return the primary key value generated by the insert operation.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Is_it_possible_to_retrieve_the_primary_key_value_using_a_subquery\"><\/span>2. Is it possible to retrieve the primary key value using a subquery?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, you can use a subquery to retrieve the primary key value after an insert operation, but it may not be as efficient as using the LAST_INSERT_ID() function.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_What_happens_if_I_try_to_retrieve_the_primary_key_value_before_an_insert_operation\"><\/span>3. What happens if I try to retrieve the primary key value before an insert operation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nIf you try to retrieve the primary key value before an insert operation, the result will be NULL or an error, as the primary key value is only generated after the insert operation.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Can_I_get_the_primary_key_value_using_the_SCOPE_IDENTITY_function\"><\/span>4. Can I get the primary key value using the SCOPE_IDENTITY() function?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nSCOPE_IDENTITY() is a function specific to Microsoft SQL Server and is used to retrieve the last identity value generated in the current scope. It can be used in a similar way to LAST_INSERT_ID() in MySQL.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_Is_it_possible_to_retrieve_the_primary_key_value_using_a_stored_procedure\"><\/span>5. Is it possible to retrieve the primary key value using a stored procedure?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, you can create a stored procedure that inserts a record into a table and then returns the primary key value using an OUTPUT parameter or a SELECT statement.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6_What_should_I_do_if_the_primary_key_is_not_an_auto-incrementing_column\"><\/span>6. What should I do if the primary key is not an auto-incrementing column?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nIf the primary key is not auto-incrementing, you will need to specify the primary key value explicitly during the insert operation and retrieve it using the appropriate method.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"7_Can_I_get_the_primary_key_value_using_the_ROWCOUNT_function\"><\/span>7. Can I get the primary key value using the ROWCOUNT function?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nROWCOUNT is a function that returns the number of rows affected by the last statement, not the primary key value generated by an insert operation.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"8_Is_there_a_way_to_retrieve_the_primary_key_value_without_executing_a_separate_SELECT_statement\"><\/span>8. Is there a way to retrieve the primary key value without executing a separate SELECT statement?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nNo, in most cases, you will need to execute a separate SELECT statement to retrieve the primary key value after an insert operation.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"9_Can_I_use_the_OUTPUT_clause_in_SQL_Server_to_get_the_primary_key_value\"><\/span>9. Can I use the OUTPUT clause in SQL Server to get the primary key value?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, you can use the OUTPUT clause in SQL Server to retrieve the primary key value after an insert operation, along with other columns that were inserted.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"10_Are_there_any_limitations_to_using_the_LAST_INSERT_ID_function\"><\/span>10. Are there any limitations to using the LAST_INSERT_ID() function?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nThe LAST_INSERT_ID() function is specific to MySQL and may not be available in other database management systems. You should check the documentation of your database system for an equivalent function.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"11_How_can_I_ensure_the_primary_key_value_is_unique_after_an_insert_operation\"><\/span>11. How can I ensure the primary key value is unique after an insert operation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nBy using a primary key constraint on the column, the database system will automatically generate a unique value for each inserted record, ensuring data integrity.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"12_Can_I_retrieve_the_primary_key_value_using_a_trigger_after_an_insert_operation\"><\/span>12. Can I retrieve the primary key value using a trigger after an insert operation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, you can create a trigger in the database that fires after an insert operation and captures the primary key value for further processing or logging.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that was generated for the inserted record. This primary key can be useful for further operations or for displaying to the user. Here&#8217;s how you can get the primary &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to get primary key value after insert in SQL?\" class=\"read-more button\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#more-235423\">Read more<span class=\"screen-reader-text\">How to get primary key value after insert in SQL?<\/span><\/a><\/p>\n","protected":false},"author":59,"featured_media":107420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86279],"tags":[],"class_list":["post-235423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","no-featured-image-padding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get primary key value after insert in SQL?<\/title>\n<meta name=\"description\" content=\"When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get primary key value after insert in SQL?\" \/>\n<meta property=\"og:description\" content=\"When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that\" \/>\n<meta property=\"og:url\" content=\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/\" \/>\n<meta property=\"og:site_name\" content=\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/synchronyfinancial\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-04T06:18:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Francis French\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@synchrony\" \/>\n<meta name=\"twitter:site\" content=\"@synchrony\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Francis French\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/\"},\"author\":{\"name\":\"Francis French\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/1622769be52c41a10d83bee2c48a8c48\"},\"headline\":\"How to get primary key value after insert in SQL?\",\"datePublished\":\"2024-07-04T06:18:04+00:00\",\"dateModified\":\"2024-07-04T06:18:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/\"},\"wordCount\":679,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"articleSection\":[\"Learn\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/\",\"name\":\"How to get primary key value after insert in SQL?\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\"},\"datePublished\":\"2024-07-04T06:18:04+00:00\",\"dateModified\":\"2024-07-04T06:18:04+00:00\",\"description\":\"When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that\",\"breadcrumb\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/namso-gen.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get primary key value after insert in SQL?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"description\":\"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co\",\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/namso-gen.co\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"contentUrl\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"width\":500,\"height\":164,\"caption\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\"},\"image\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/synchronyfinancial\",\"https:\/\/twitter.com\/synchrony\",\"https:\/\/www.youtube.com\/synchronyfinancial\",\"https:\/\/www.instagram.com\/synchrony\",\"https:\/\/www.linkedin.com\/company\/synchrony-financial\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/1622769be52c41a10d83bee2c48a8c48\",\"name\":\"Francis French\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"Francis French\"},\"description\":\"Guest author Francis French has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get primary key value after insert in SQL?","description":"When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/","og_locale":"en_US","og_type":"article","og_title":"How to get primary key value after insert in SQL?","og_description":"When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that","og_url":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/","og_site_name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","article_publisher":"https:\/\/www.facebook.com\/synchronyfinancial","article_published_time":"2024-07-04T06:18:04+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png","type":"image\/png"}],"author":"Francis French","twitter_card":"summary_large_image","twitter_creator":"@synchrony","twitter_site":"@synchrony","twitter_misc":{"Written by":"Francis French","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#article","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/"},"author":{"name":"Francis French","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/1622769be52c41a10d83bee2c48a8c48"},"headline":"How to get primary key value after insert in SQL?","datePublished":"2024-07-04T06:18:04+00:00","dateModified":"2024-07-04T06:18:04+00:00","mainEntityOfPage":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/"},"wordCount":679,"commentCount":0,"publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"articleSection":["Learn"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/","url":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/","name":"How to get primary key value after insert in SQL?","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/#website"},"datePublished":"2024-07-04T06:18:04+00:00","dateModified":"2024-07-04T06:18:04+00:00","description":"When inserting a new record into a database table that has an auto-incrementing primary key, you may need to retrieve the value of the primary key that","breadcrumb":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/namso-gen.co\/blog\/how-to-get-primary-key-value-after-insert-in-sql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/namso-gen.co\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get primary key value after insert in SQL?"}]},{"@type":"WebSite","@id":"https:\/\/namso-gen.co\/blog\/#website","url":"https:\/\/namso-gen.co\/blog\/","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","description":"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co","publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/namso-gen.co\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/namso-gen.co\/blog\/#organization","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","url":"https:\/\/namso-gen.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","contentUrl":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","width":500,"height":164,"caption":"Namso Gen Blog - Free Credit Card Generator [100% Valid]"},"image":{"@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/synchronyfinancial","https:\/\/twitter.com\/synchrony","https:\/\/www.youtube.com\/synchronyfinancial","https:\/\/www.instagram.com\/synchrony","https:\/\/www.linkedin.com\/company\/synchrony-financial"]},{"@type":"Person","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/1622769be52c41a10d83bee2c48a8c48","name":"Francis French","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"Francis French"},"description":"Guest author Francis French has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here."}]}},"_links":{"self":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/235423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/users\/59"}],"replies":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/comments?post=235423"}],"version-history":[{"count":0,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/235423\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media\/107420"}],"wp:attachment":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media?parent=235423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/categories?post=235423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/tags?post=235423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}