{"id":3893,"date":"2015-10-30T19:09:56","date_gmt":"2015-10-31T03:09:56","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=3893"},"modified":"2024-01-05T03:25:20","modified_gmt":"2024-01-05T10:25:20","slug":"mysql-rename-table","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/","title":{"rendered":"MySQL RENAME TABLE Statement"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to rename tables using MySQL <code>RENAME TABLE<\/code> statement and <code>ALTER TABLE<\/code> statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL RENAME TABLE statement<\/h2>\n\n\n\n<p>Due to evolving business requirements, you need to rename the existing table to better align with the new situation. MySQL offers a valuable statement for renaming one or more tables.<\/p>\n\n\n\n<p>To rename one or more tables, you can use the <code>RENAME TABLE<\/code> statement as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name\n<span class=\"hljs-keyword\">TO<\/span> new_table_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>table_name<\/code>: This is the name of the table that you want to rename.<\/li>\n\n\n\n<li><code>new_table_name<\/code>: This is the new table name.<\/li>\n<\/ul>\n\n\n\n<p>The table with the <code>table_name<\/code> must exist or the <code>RENAME<\/code> statement will fail with an error.<\/p>\n\n\n\n<p>While executing the <code>RENAME TABLE<\/code> statement, you need to ensure that there are no active transactions or <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-table-locking\/\">locked tables<\/a>.<\/p>\n\n\n\n<p class=\"note\">Note that you cannot use the <code>RENAME TABLE<\/code> statement to rename a&nbsp;<a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-temporary-table\/\">temporary table<\/a>, but you can use the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-alter-table\/\">ALTER TABLE statement<\/a>&nbsp;to rename a temporary table.<\/p>\n\n\n\n<p>In terms of security, any existing <a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/\">privileges that you&nbsp;granted to the old table<\/a> must be manually migrated to the new table.<\/p>\n\n\n\n<p>Before renaming a table, it&#8217;s important to thoroughly evaluate the potential impact.<\/p>\n\n\n\n<p>For example, you should investigate which applications are currently using the table. Changing the table name would necessitate corresponding changes in the application code that references it. <\/p>\n\n\n\n<p>Additionally, you&#8217;ll need to manually adjust other database objects, including <a href=\"https:\/\/www.mysqltutorial.org\/mysql-views\/\">views<\/a>, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/\">stored procedures<\/a>, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-triggers\/\">triggers<\/a>, and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-foreign-key\/\">foreign key constraints<\/a> that reference the table. <\/p>\n\n\n\n<p>We will delve into this in more detail in the following examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL RENAME TABLE examples<\/h2>\n\n\n\n<p>First, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-database\/\">create a new database<\/a> named <code>hr<\/code> that includes two tables: <code>employees<\/code> and <code>departments<\/code> for the demonstration.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"432\" height=\"167\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database.png\" alt=\"HR Sample Database\" class=\"wp-image-3917\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database.png 432w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database-300x116.png 300w\" sizes=\"auto, (max-width: 432px) 100vw, 432px\" \/><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> <span class=\"hljs-keyword\">IF<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">EXISTS<\/span> hr;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> departments (\n    department_id <span class=\"hljs-built_in\">INT<\/span> AUTO_INCREMENT PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n    dept_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\n);\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> employees (\n    <span class=\"hljs-keyword\">id<\/span> <span class=\"hljs-built_in\">int<\/span> AUTO_INCREMENT primary <span class=\"hljs-keyword\">key<\/span>,\n    first_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">not<\/span> <span class=\"hljs-literal\">null<\/span>,\n    last_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">not<\/span> <span class=\"hljs-literal\">null<\/span>,\n    department_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">not<\/span> <span class=\"hljs-literal\">null<\/span>,\n    <span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (department_id)\n        <span class=\"hljs-keyword\">REFERENCES<\/span> departments (department_id)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-insert\/\">insert sample data<\/a> into both <code>employees<\/code> and <code>departments<\/code> tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> departments(dept_name) \n<span class=\"hljs-keyword\">VALUES<\/span> \n  (<span class=\"hljs-string\">'Sales'<\/span>), \n  (<span class=\"hljs-string\">'Markting'<\/span>), \n  (<span class=\"hljs-string\">'Finance'<\/span>), \n  (<span class=\"hljs-string\">'Accounting'<\/span>), \n  (<span class=\"hljs-string\">'Warehouses'<\/span>), \n  (<span class=\"hljs-string\">'Production'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">INSERT INTO employees(\n  first_name, last_name, department_id\n) \nVALUES \n  (<span class=\"hljs-string\">'John'<\/span>, <span class=\"hljs-string\">'Doe'<\/span>, <span class=\"hljs-number\">1<\/span>), \n  (<span class=\"hljs-string\">'Bush'<\/span>, <span class=\"hljs-string\">'Lily'<\/span>, <span class=\"hljs-number\">2<\/span>), \n  (<span class=\"hljs-string\">'David'<\/span>, <span class=\"hljs-string\">'Dave'<\/span>, <span class=\"hljs-number\">3<\/span>), \n  (<span class=\"hljs-string\">'Mary'<\/span>, <span class=\"hljs-string\">'Jane'<\/span>, <span class=\"hljs-number\">4<\/span>), \n  (<span class=\"hljs-string\">'Jonatha'<\/span>, <span class=\"hljs-string\">'Josh'<\/span>, <span class=\"hljs-number\">5<\/span>), \n  (<span class=\"hljs-string\">'Mateo'<\/span>, <span class=\"hljs-string\">'More'<\/span>, <span class=\"hljs-number\">1<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, query data from the <code>departments<\/code> and <code>employees<\/code> tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    department_id, dept_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    departments;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"211\" height=\"151\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-departments-Table.png\" alt=\"MySQL RENAME TABLE departments Table\" class=\"wp-image-3899\"\/><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-keyword\">id<\/span>, first_name, last_name, department_id\n<span class=\"hljs-keyword\">FROM<\/span>\n    employees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"307\" height=\"153\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-employees-table.png\" alt=\"MySQL RENAME TABLE employees table\" class=\"wp-image-3900\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-employees-table.png 307w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-employees-table-300x150.png 300w\" sizes=\"auto, (max-width: 307px) 100vw, 307px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">1) Renaming a table referenced by a view<\/h3>\n\n\n\n<p>If the table you are going to rename is referenced by a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-views\/\">view<\/a>, the view will become invalid, and you have to adjust the view manually.<\/p>\n\n\n\n<p>For example, we create a view named <code>v_employee_info<\/code> based on the <code>employees<\/code> and <code>departments<\/code> tables as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">VIEW<\/span> v_employee_info <span class=\"hljs-keyword\">as<\/span> \n<span class=\"hljs-keyword\">SELECT<\/span> \n  <span class=\"hljs-keyword\">id<\/span>, \n  first_name, \n  last_name, \n  dept_name \n<span class=\"hljs-keyword\">from<\/span> \n  employees \n  <span class=\"hljs-keyword\">inner<\/span> <span class=\"hljs-keyword\">join<\/span> departments <span class=\"hljs-keyword\">USING<\/span> (department_id);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The views use&nbsp;the&nbsp;<a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-inner-join\/\">inner join<\/a>&nbsp;clause to join <code>departments<\/code> and <code>employees<\/code> tables.<\/p>\n\n\n\n<p>The following <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-select-from\/\">SELECT statement<\/a> returns&nbsp;all data from the <code>v_employee_info<\/code> view.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> v_employee_info;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"311\" height=\"158\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-with-View-example.png\" alt=\"MySQL RENAME TABLE with View example\" class=\"wp-image-3901\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-with-View-example.png 311w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-with-View-example-300x152.png 300w\" sizes=\"auto, (max-width: 311px) 100vw, 311px\" \/><\/figure>\n\n\n\n<p>Now we rename the <code>employees<\/code> to <code>people<\/code> table and query data from the <code>v_employee_info<\/code> view again.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> employees <span class=\"hljs-keyword\">TO<\/span> people;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> v_employee_info;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>MySQL returns the following error message:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">Error Code: 1356. View 'hr.v_employee_info' references invalid table(s) or \ncolumn(s) or function(s) or definer\/invoker of view lack rights to <span class=\"hljs-keyword\">use<\/span> them<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>We can use the <code>CHECK TABLE<\/code> statement to check the status of&nbsp;the <code>v_employee_info<\/code> view as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CHECK<\/span> <span class=\"hljs-keyword\">TABLE<\/span> v_employee_info;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"846\" height=\"88\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-CHECK-TABLE.png\" alt=\"MySQL CHECK TABLE\" class=\"wp-image-3895\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-CHECK-TABLE.png 846w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-CHECK-TABLE-300x31.png 300w\" sizes=\"auto, (max-width: 846px) 100vw, 846px\" \/><\/figure>\n\n\n\n<p>We need to manually&nbsp;change the <code>v_employee_info<\/code>&nbsp;view so that it refers to the <code>people<\/code> table instead of the <code>employees<\/code> table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Renaming a table that is referenced by a stored procedure<\/h3>\n\n\n\n<p>In case the table that you are going to rename is referenced by a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/\">stored procedure<\/a>, you have to manually adjust it like you did with the view.<\/p>\n\n\n\n<p>First, rename the <code>people <\/code>table back to the&nbsp;<code>employees<\/code> table.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> people <span class=\"hljs-keyword\">TO<\/span> employees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Then, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/getting-started-with-mysql-stored-procedures\/\">create a new stored procedure<\/a> named <code>get_employee<\/code> that refers to the <code>employees<\/code> table.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">DELIMITER $$\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">PROCEDURE<\/span> get_employee(<span class=\"hljs-keyword\">IN<\/span> p_id <span class=\"hljs-built_in\">INT<\/span>)\n<span class=\"hljs-keyword\">BEGIN<\/span>\n\t<span class=\"hljs-keyword\">SELECT<\/span> first_name, last_name, dept_name\n\t<span class=\"hljs-keyword\">FROM<\/span> employees\n\t<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments <span class=\"hljs-keyword\">using<\/span> (department_id)\n\t<span class=\"hljs-keyword\">WHERE<\/span> <span class=\"hljs-keyword\">id<\/span> = p_id;\n<span class=\"hljs-keyword\">END<\/span>$$\n\nDELIMITER ;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Next, execute the <code>get_employee<\/code> table to get the data of the employee with ID 1 as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CALL<\/span> get_employee(<span class=\"hljs-number\">1<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"269\" height=\"46\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-RENAME-TABLE-with-Stored-Procedure.png\" alt=\"MySQL RENAME TABLE with Stored Procedure\" class=\"wp-image-3897\"\/><\/figure>\n\n\n\n<p>After that,&nbsp;rename the <code>employees<\/code> to the <code>people<\/code> table again.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> employees <span class=\"hljs-keyword\">TO<\/span> people;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, call the <code>get_employee<\/code> stored procedure to get the information of the employee with the ID 2:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CALL<\/span> get_employee(<span class=\"hljs-number\">2<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>MySQL returns the following error message:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">Error Code: 1146. Table 'hr.employees' doesn't exist<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To fix this, you need to manually change the <code>employees<\/code> table in the stored procedure&nbsp;to <code>people<\/code> table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3) Renaming a table that is referenced by foreign key constraints<\/h3>\n\n\n\n<p>The <code>departments<\/code> table links to the <code>employees<\/code> table using the <code>department_id<\/code> column. <\/p>\n\n\n\n<p>The <code>department_i<\/code>d column in the <code>employees <\/code>table is the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-foreign-key\/\">foreign key<\/a> that references to the <code>departments<\/code> table.<\/p>\n\n\n\n<p>If you rename the <code>departments<\/code> table, all the foreign keys that reference the <code>departments<\/code>&nbsp;table will not be automatically updated. In such cases, you must drop and recreate the foreign keys manually.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> departments <span class=\"hljs-keyword\">TO<\/span> depts;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>We delete a department with id 1, because of the foreign key constraint, all rows in the <code>people<\/code> table should&nbsp;be also deleted. <\/p>\n\n\n\n<p>However, we renamed the <code>departments<\/code> table to the <code>depts<\/code> table without updating the foreign key manually, MySQL returns an error as illustrated below:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">FROM<\/span> depts \n<span class=\"hljs-keyword\">WHERE<\/span>\n    department_id = <span class=\"hljs-number\">1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">Error<\/span> Code: <span class=\"hljs-number\">1451.<\/span> Cannot <span class=\"hljs-keyword\">delete<\/span> or update a parent row: a foreign key constraint fails (<span class=\"hljs-string\">`hr`<\/span>.<span class=\"hljs-string\">`people`<\/span>, CONSTRAINT <span class=\"hljs-string\">`people_ibfk_1`<\/span> FOREIGN KEY (<span class=\"hljs-string\">`department_id`<\/span>) REFERENCES <span class=\"hljs-string\">`depts`<\/span> (<span class=\"hljs-string\">`department_id`<\/span>))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Renaming multiple tables<\/h2>\n\n\n\n<p>We can also use the <code>RENAME TABLE<\/code> statement to rename multiple tables at a time. See the following statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-23\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> \n   table_name1 <span class=\"hljs-keyword\">TO<\/span> new_table_name1,\n   table_name2 <span class=\"hljs-keyword\">TO<\/span> new_table_name2,\n   ...;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-23\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following statement renames the <code>people<\/code> and <code>depts<\/code> tables to <code>employees<\/code> and <code>departments<\/code> tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-24\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> depts <span class=\"hljs-keyword\">TO<\/span> departments,\n             people <span class=\"hljs-keyword\">TO<\/span> employees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-24\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note the <code>RENAME TABLE<\/code>&nbsp;statement is not atomic.&nbsp;It means that if any errors occur, MySQL performs a rollback&nbsp;of all renamed tables to their old names.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Renaming tables using ALTER TABLE statement<\/h2>\n\n\n\n<p>You can rename a table using the <code>ALTER TABLE<\/code> statement as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-25\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> old_table_name\n<span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TO<\/span> new_table_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-25\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>ALTER TABLE<\/code> statement can rename a temporary table while the <code>RENAME TABLE<\/code> statement cannot.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Renaming temporary table example<\/h3>\n\n\n\n<p>First, create a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-temporary-table\/\">temporary table<\/a> that contains&nbsp;all unique last names that come from the <code>last_name<\/code> column of the <code>employees<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-26\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TEMPORARY<\/span> <span class=\"hljs-keyword\">TABLE<\/span> lastnames\n<span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">DISTINCT<\/span> last_name <span class=\"hljs-keyword\">from<\/span> employees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-26\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, use the <code>RENAME TABLE<\/code> to rename the <code>lastnames<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-27\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TABLE<\/span> lastnames <span class=\"hljs-keyword\">TO<\/span> unique_lastnames;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-27\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>MySQL returns the following error message:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-28\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">Error Code: 1017. Can't find file: '.\\hr\\lastnames.frm' (errno: 2 - No such file or directory)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-28\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, use the <code>ALTER TABLE<\/code>&nbsp;statement to rename the <code>lastnames<\/code> table.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-29\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> lastnames\n<span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TO<\/span> unique_lastnames;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-29\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fourth, query data from the <code>unique_lastnames<\/code> temporary table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-30\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    last_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    unique_lastnames;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-30\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"105\" height=\"154\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/MySQL-ALTER-TABLE-renames-temporary-table.png\" alt=\"MySQL ALTER TABLE renames temporary table\" class=\"wp-image-3902\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code>RENAME TABLE<\/code> or <code>ALTER TABLE<\/code> statement to rename a table.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3893\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/\"\n\t\t\t\tdata-post-title=\"MySQL RENAME TABLE Statement\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3893\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/\"\n\t\t\t\tdata-post-title=\"MySQL RENAME TABLE Statement\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you how to rename a table in MySQL using MySQL RENAME TABLE statement. We also give you examples of how to adjust views, stored procedures, etc. that reference to the renamed tables.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":174,"menu_order":39,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3893","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL RENAME TABLE Statement<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to rename a table in the database using the MySQL RENAME TABLE or ALTER TABLE statement.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL RENAME TABLE Statement\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to rename a table in the database using the MySQL RENAME TABLE or ALTER TABLE statement.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-05T10:25:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/\",\"name\":\"MySQL RENAME TABLE Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/10\\\/HR-Sample-Database.png\",\"datePublished\":\"2015-10-31T03:09:56+00:00\",\"dateModified\":\"2024-01-05T10:25:20+00:00\",\"description\":\"This tutorial shows you how to rename a table in the database using the MySQL RENAME TABLE or ALTER TABLE statement.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/10\\\/HR-Sample-Database.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/10\\\/HR-Sample-Database.png\",\"width\":432,\"height\":167},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-rename-table\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Basics\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL RENAME TABLE Statement\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL RENAME TABLE Statement","description":"This tutorial shows you how to rename a table in the database using the MySQL RENAME TABLE or ALTER TABLE statement.","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:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/","og_locale":"en_US","og_type":"article","og_title":"MySQL RENAME TABLE Statement","og_description":"This tutorial shows you how to rename a table in the database using the MySQL RENAME TABLE or ALTER TABLE statement.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-05T10:25:20+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/","url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/","name":"MySQL RENAME TABLE Statement","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database.png","datePublished":"2015-10-31T03:09:56+00:00","dateModified":"2024-01-05T10:25:20+00:00","description":"This tutorial shows you how to rename a table in the database using the MySQL RENAME TABLE or ALTER TABLE statement.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/10\/HR-Sample-Database.png","width":432,"height":167},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-rename-table\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Basics","item":"https:\/\/www.mysqltutorial.org\/mysql-basics\/"},{"@type":"ListItem","position":3,"name":"MySQL RENAME TABLE Statement"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=3893"}],"version-history":[{"count":5,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3893\/revisions"}],"predecessor-version":[{"id":14278,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3893\/revisions\/14278"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/174"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=3893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}