Change Table Prefix for Magento 2 DB (After Installation)

During installation, Magento provides the option to configure the table prefix for your database. That’s great.

What if you missed it or realized later that you needed to configure it when you already have real data (catalog, customer, sales, etc.) in your database?

Don’t worry, we have got you covered. You just need to follow the steps described below:

1. Prepare SQL statements for renaming

SET @TABLE_PREFIX = 'uat_';
SET @DATABASE = 'magento242';
SELECT CONCAT('ALTER TABLE ', TABLE_NAME, ' RENAME TO ', @TABLE_PREFIX, TABLE_NAME, ';') AS 'SQL' FROM information_schema.tables WHERE table_schema = @DATABASE;

You need to change the values of @TABLE_PREFIX & @DATABASEvariables.

2. Execute the SQL statements

If you run the above SQL, it will generate a list of SQL statements ready to be executed.

For instance, below is a list of statements generated for vanilla Magento v2.4.2:

ALTER TABLE admin_analytics_usage_version_log RENAME TO uat_admin_analytics_usage_version_log;
ALTER TABLE admin_passwords RENAME TO uat_admin_passwords;
ALTER TABLE admin_system_messages RENAME TO uat_admin_system_messages;
ALTER TABLE admin_user RENAME TO uat_admin_user;
ALTER TABLE admin_user_expiration RENAME TO uat_admin_user_expiration;
ALTER TABLE admin_user_session RENAME TO uat_admin_user_session;
ALTER TABLE adminnotification_inbox RENAME TO uat_adminnotification_inbox;
ALTER TABLE authorization_role RENAME TO uat_authorization_role;
ALTER TABLE authorization_rule RENAME TO uat_authorization_rule;
ALTER TABLE cache RENAME TO uat_cache;
ALTER TABLE cache_tag RENAME TO uat_cache_tag;
ALTER TABLE captcha_log RENAME TO uat_captcha_log;
ALTER TABLE catalog_category_entity RENAME TO uat_catalog_category_entity;
ALTER TABLE catalog_category_entity_datetime RENAME TO uat_catalog_category_entity_datetime;
ALTER TABLE catalog_category_entity_decimal RENAME TO uat_catalog_category_entity_decimal;
ALTER TABLE catalog_category_entity_int RENAME TO uat_catalog_category_entity_int;
ALTER TABLE catalog_category_entity_text RENAME TO uat_catalog_category_entity_text;
ALTER TABLE catalog_category_entity_varchar RENAME TO uat_catalog_category_entity_varchar;
ALTER TABLE catalog_category_product RENAME TO uat_catalog_category_product;
ALTER TABLE catalog_category_product_index RENAME TO uat_catalog_category_product_index;
ALTER TABLE catalog_category_product_index_replica RENAME TO uat_catalog_category_product_index_replica;
ALTER TABLE catalog_category_product_index_store1 RENAME TO uat_catalog_category_product_index_store1;
ALTER TABLE catalog_category_product_index_store1_replica RENAME TO uat_catalog_category_product_index_store1_replica;
ALTER TABLE catalog_category_product_index_tmp RENAME TO uat_catalog_category_product_index_tmp;
ALTER TABLE catalog_compare_item RENAME TO uat_catalog_compare_item;
ALTER TABLE catalog_compare_list RENAME TO uat_catalog_compare_list;
ALTER TABLE catalog_eav_attribute RENAME TO uat_catalog_eav_attribute;
ALTER TABLE catalog_product_bundle_option RENAME TO uat_catalog_product_bundle_option;
ALTER TABLE catalog_product_bundle_option_value RENAME TO uat_catalog_product_bundle_option_value;
ALTER TABLE catalog_product_bundle_price_index RENAME TO uat_catalog_product_bundle_price_index;
ALTER TABLE catalog_product_bundle_selection RENAME TO uat_catalog_product_bundle_selection;
ALTER TABLE catalog_product_bundle_selection_price RENAME TO uat_catalog_product_bundle_selection_price;
ALTER TABLE catalog_product_bundle_stock_index RENAME TO uat_catalog_product_bundle_stock_index;
ALTER TABLE catalog_product_entity RENAME TO uat_catalog_product_entity;
ALTER TABLE catalog_product_entity_datetime RENAME TO uat_catalog_product_entity_datetime;
ALTER TABLE catalog_product_entity_decimal RENAME TO uat_catalog_product_entity_decimal;
ALTER TABLE catalog_product_entity_gallery RENAME TO uat_catalog_product_entity_gallery;
ALTER TABLE catalog_product_entity_int RENAME TO uat_catalog_product_entity_int;
ALTER TABLE catalog_product_entity_media_gallery RENAME TO uat_catalog_product_entity_media_gallery;
ALTER TABLE catalog_product_entity_media_gallery_value RENAME TO uat_catalog_product_entity_media_gallery_value;
ALTER TABLE catalog_product_entity_media_gallery_value_to_entity RENAME TO uat_catalog_product_entity_media_gallery_value_to_entity;
ALTER TABLE catalog_product_entity_media_gallery_value_video RENAME TO uat_catalog_product_entity_media_gallery_value_video;
ALTER TABLE catalog_product_entity_text RENAME TO uat_catalog_product_entity_text;
ALTER TABLE catalog_product_entity_tier_price RENAME TO uat_catalog_product_entity_tier_price;
ALTER TABLE catalog_product_entity_varchar RENAME TO uat_catalog_product_entity_varchar;
ALTER TABLE catalog_product_frontend_action RENAME TO uat_catalog_product_frontend_action;
ALTER TABLE catalog_product_index_eav RENAME TO uat_catalog_product_index_eav;
ALTER TABLE catalog_product_index_eav_decimal RENAME TO uat_catalog_product_index_eav_decimal;
ALTER TABLE catalog_product_index_eav_decimal_idx RENAME TO uat_catalog_product_index_eav_decimal_idx;
ALTER TABLE catalog_product_index_eav_decimal_replica RENAME TO uat_catalog_product_index_eav_decimal_replica;
ALTER TABLE catalog_product_index_eav_decimal_tmp RENAME TO uat_catalog_product_index_eav_decimal_tmp;
ALTER TABLE catalog_product_index_eav_idx RENAME TO uat_catalog_product_index_eav_idx;
ALTER TABLE catalog_product_index_eav_replica RENAME TO uat_catalog_product_index_eav_replica;
ALTER TABLE catalog_product_index_eav_tmp RENAME TO uat_catalog_product_index_eav_tmp;
ALTER TABLE catalog_product_index_price RENAME TO uat_catalog_product_index_price;
ALTER TABLE catalog_product_index_price_bundle_idx RENAME TO uat_catalog_product_index_price_bundle_idx;
ALTER TABLE catalog_product_index_price_bundle_opt_idx RENAME TO uat_catalog_product_index_price_bundle_opt_idx;
ALTER TABLE catalog_product_index_price_bundle_opt_tmp RENAME TO uat_catalog_product_index_price_bundle_opt_tmp;
ALTER TABLE catalog_product_index_price_bundle_sel_idx RENAME TO uat_catalog_product_index_price_bundle_sel_idx;
ALTER TABLE catalog_product_index_price_bundle_sel_tmp RENAME TO uat_catalog_product_index_price_bundle_sel_tmp;
ALTER TABLE catalog_product_index_price_bundle_tmp RENAME TO uat_catalog_product_index_price_bundle_tmp;
ALTER TABLE catalog_product_index_price_cfg_opt_agr_idx RENAME TO uat_catalog_product_index_price_cfg_opt_agr_idx;
ALTER TABLE catalog_product_index_price_cfg_opt_agr_tmp RENAME TO uat_catalog_product_index_price_cfg_opt_agr_tmp;
ALTER TABLE catalog_product_index_price_cfg_opt_idx RENAME TO uat_catalog_product_index_price_cfg_opt_idx;
ALTER TABLE catalog_product_index_price_cfg_opt_tmp RENAME TO uat_catalog_product_index_price_cfg_opt_tmp;
ALTER TABLE catalog_product_index_price_downlod_idx RENAME TO uat_catalog_product_index_price_downlod_idx;
ALTER TABLE catalog_product_index_price_downlod_tmp RENAME TO uat_catalog_product_index_price_downlod_tmp;
ALTER TABLE catalog_product_index_price_final_idx RENAME TO uat_catalog_product_index_price_final_idx;
ALTER TABLE catalog_product_index_price_final_tmp RENAME TO uat_catalog_product_index_price_final_tmp;
ALTER TABLE catalog_product_index_price_idx RENAME TO uat_catalog_product_index_price_idx;
ALTER TABLE catalog_product_index_price_opt_agr_idx RENAME TO uat_catalog_product_index_price_opt_agr_idx;
ALTER TABLE catalog_product_index_price_opt_agr_tmp RENAME TO uat_catalog_product_index_price_opt_agr_tmp;
ALTER TABLE catalog_product_index_price_opt_idx RENAME TO uat_catalog_product_index_price_opt_idx;
ALTER TABLE catalog_product_index_price_opt_tmp RENAME TO uat_catalog_product_index_price_opt_tmp;
ALTER TABLE catalog_product_index_price_replica RENAME TO uat_catalog_product_index_price_replica;
ALTER TABLE catalog_product_index_price_tmp RENAME TO uat_catalog_product_index_price_tmp;
ALTER TABLE catalog_product_index_tier_price RENAME TO uat_catalog_product_index_tier_price;
ALTER TABLE catalog_product_index_website RENAME TO uat_catalog_product_index_website;
ALTER TABLE catalog_product_link RENAME TO uat_catalog_product_link;
ALTER TABLE catalog_product_link_attribute RENAME TO uat_catalog_product_link_attribute;
ALTER TABLE catalog_product_link_attribute_decimal RENAME TO uat_catalog_product_link_attribute_decimal;
ALTER TABLE catalog_product_link_attribute_int RENAME TO uat_catalog_product_link_attribute_int;
ALTER TABLE catalog_product_link_attribute_varchar RENAME TO uat_catalog_product_link_attribute_varchar;
ALTER TABLE catalog_product_link_type RENAME TO uat_catalog_product_link_type;
ALTER TABLE catalog_product_option RENAME TO uat_catalog_product_option;
ALTER TABLE catalog_product_option_price RENAME TO uat_catalog_product_option_price;
ALTER TABLE catalog_product_option_title RENAME TO uat_catalog_product_option_title;
ALTER TABLE catalog_product_option_type_price RENAME TO uat_catalog_product_option_type_price;
ALTER TABLE catalog_product_option_type_title RENAME TO uat_catalog_product_option_type_title;
ALTER TABLE catalog_product_option_type_value RENAME TO uat_catalog_product_option_type_value;
ALTER TABLE catalog_product_relation RENAME TO uat_catalog_product_relation;
ALTER TABLE catalog_product_super_attribute RENAME TO uat_catalog_product_super_attribute;
ALTER TABLE catalog_product_super_attribute_label RENAME TO uat_catalog_product_super_attribute_label;
ALTER TABLE catalog_product_super_link RENAME TO uat_catalog_product_super_link;
ALTER TABLE catalog_product_website RENAME TO uat_catalog_product_website;
ALTER TABLE catalog_url_rewrite_product_category RENAME TO uat_catalog_url_rewrite_product_category;
ALTER TABLE cataloginventory_stock RENAME TO uat_cataloginventory_stock;
ALTER TABLE cataloginventory_stock_item RENAME TO uat_cataloginventory_stock_item;
ALTER TABLE cataloginventory_stock_status RENAME TO uat_cataloginventory_stock_status;
ALTER TABLE cataloginventory_stock_status_idx RENAME TO uat_cataloginventory_stock_status_idx;
ALTER TABLE cataloginventory_stock_status_replica RENAME TO uat_cataloginventory_stock_status_replica;
ALTER TABLE cataloginventory_stock_status_tmp RENAME TO uat_cataloginventory_stock_status_tmp;
ALTER TABLE catalogrule RENAME TO uat_catalogrule;
ALTER TABLE catalogrule_customer_group RENAME TO uat_catalogrule_customer_group;
ALTER TABLE catalogrule_group_website RENAME TO uat_catalogrule_group_website;
ALTER TABLE catalogrule_group_website_replica RENAME TO uat_catalogrule_group_website_replica;
ALTER TABLE catalogrule_product RENAME TO uat_catalogrule_product;
ALTER TABLE catalogrule_product_price RENAME TO uat_catalogrule_product_price;
ALTER TABLE catalogrule_product_price_replica RENAME TO uat_catalogrule_product_price_replica;
ALTER TABLE catalogrule_product_replica RENAME TO uat_catalogrule_product_replica;
ALTER TABLE catalogrule_website RENAME TO uat_catalogrule_website;
ALTER TABLE catalogsearch_recommendations RENAME TO uat_catalogsearch_recommendations;
ALTER TABLE checkout_agreement RENAME TO uat_checkout_agreement;
ALTER TABLE checkout_agreement_store RENAME TO uat_checkout_agreement_store;
ALTER TABLE cms_block RENAME TO uat_cms_block;
ALTER TABLE cms_block_store RENAME TO uat_cms_block_store;
ALTER TABLE cms_page RENAME TO uat_cms_page;
ALTER TABLE cms_page_store RENAME TO uat_cms_page_store;
ALTER TABLE core_config_data RENAME TO uat_core_config_data;
ALTER TABLE cron_schedule RENAME TO uat_cron_schedule;
ALTER TABLE customer_address_entity RENAME TO uat_customer_address_entity;
ALTER TABLE customer_address_entity_datetime RENAME TO uat_customer_address_entity_datetime;
ALTER TABLE customer_address_entity_decimal RENAME TO uat_customer_address_entity_decimal;
ALTER TABLE customer_address_entity_int RENAME TO uat_customer_address_entity_int;
ALTER TABLE customer_address_entity_text RENAME TO uat_customer_address_entity_text;
ALTER TABLE customer_address_entity_varchar RENAME TO uat_customer_address_entity_varchar;
ALTER TABLE customer_eav_attribute RENAME TO uat_customer_eav_attribute;
ALTER TABLE customer_eav_attribute_website RENAME TO uat_customer_eav_attribute_website;
ALTER TABLE customer_entity RENAME TO uat_customer_entity;
ALTER TABLE customer_entity_datetime RENAME TO uat_customer_entity_datetime;
ALTER TABLE customer_entity_decimal RENAME TO uat_customer_entity_decimal;
ALTER TABLE customer_entity_int RENAME TO uat_customer_entity_int;
ALTER TABLE customer_entity_text RENAME TO uat_customer_entity_text;
ALTER TABLE customer_entity_varchar RENAME TO uat_customer_entity_varchar;
ALTER TABLE customer_form_attribute RENAME TO uat_customer_form_attribute;
ALTER TABLE customer_grid_flat RENAME TO uat_customer_grid_flat;
ALTER TABLE customer_group RENAME TO uat_customer_group;
ALTER TABLE customer_log RENAME TO uat_customer_log;
ALTER TABLE customer_visitor RENAME TO uat_customer_visitor;
ALTER TABLE design_change RENAME TO uat_design_change;
ALTER TABLE design_config_grid_flat RENAME TO uat_design_config_grid_flat;
ALTER TABLE directory_country RENAME TO uat_directory_country;
ALTER TABLE directory_country_format RENAME TO uat_directory_country_format;
ALTER TABLE directory_country_region RENAME TO uat_directory_country_region;
ALTER TABLE directory_country_region_city RENAME TO uat_directory_country_region_city;
ALTER TABLE directory_country_region_city_name RENAME TO uat_directory_country_region_city_name;
ALTER TABLE directory_country_region_name RENAME TO uat_directory_country_region_name;
ALTER TABLE directory_currency_rate RENAME TO uat_directory_currency_rate;
ALTER TABLE downloadable_link RENAME TO uat_downloadable_link;
ALTER TABLE downloadable_link_price RENAME TO uat_downloadable_link_price;
ALTER TABLE downloadable_link_purchased RENAME TO uat_downloadable_link_purchased;
ALTER TABLE downloadable_link_purchased_item RENAME TO uat_downloadable_link_purchased_item;
ALTER TABLE downloadable_link_title RENAME TO uat_downloadable_link_title;
ALTER TABLE downloadable_sample RENAME TO uat_downloadable_sample;
ALTER TABLE downloadable_sample_title RENAME TO uat_downloadable_sample_title;
ALTER TABLE eav_attribute RENAME TO uat_eav_attribute;
ALTER TABLE eav_attribute_group RENAME TO uat_eav_attribute_group;
ALTER TABLE eav_attribute_label RENAME TO uat_eav_attribute_label;
ALTER TABLE eav_attribute_option RENAME TO uat_eav_attribute_option;
ALTER TABLE eav_attribute_option_swatch RENAME TO uat_eav_attribute_option_swatch;
ALTER TABLE eav_attribute_option_value RENAME TO uat_eav_attribute_option_value;
ALTER TABLE eav_attribute_set RENAME TO uat_eav_attribute_set;
ALTER TABLE eav_entity RENAME TO uat_eav_entity;
ALTER TABLE eav_entity_attribute RENAME TO uat_eav_entity_attribute;
ALTER TABLE eav_entity_datetime RENAME TO uat_eav_entity_datetime;
ALTER TABLE eav_entity_decimal RENAME TO uat_eav_entity_decimal;
ALTER TABLE eav_entity_int RENAME TO uat_eav_entity_int;
ALTER TABLE eav_entity_store RENAME TO uat_eav_entity_store;
ALTER TABLE eav_entity_text RENAME TO uat_eav_entity_text;
ALTER TABLE eav_entity_type RENAME TO uat_eav_entity_type;
ALTER TABLE eav_entity_varchar RENAME TO uat_eav_entity_varchar;
ALTER TABLE eav_form_element RENAME TO uat_eav_form_element;
ALTER TABLE eav_form_fieldset RENAME TO uat_eav_form_fieldset;
ALTER TABLE eav_form_fieldset_label RENAME TO uat_eav_form_fieldset_label;
ALTER TABLE eav_form_type RENAME TO uat_eav_form_type;
ALTER TABLE eav_form_type_entity RENAME TO uat_eav_form_type_entity;
ALTER TABLE email_template RENAME TO uat_email_template;
ALTER TABLE flag RENAME TO uat_flag;
ALTER TABLE gift_message RENAME TO uat_gift_message;
ALTER TABLE googleoptimizer_code RENAME TO uat_googleoptimizer_code;
ALTER TABLE import_history RENAME TO uat_import_history;
ALTER TABLE importexport_importdata RENAME TO uat_importexport_importdata;
ALTER TABLE indexer_state RENAME TO uat_indexer_state;
ALTER TABLE integration RENAME TO uat_integration;
ALTER TABLE layout_link RENAME TO uat_layout_link;
ALTER TABLE layout_update RENAME TO uat_layout_update;
ALTER TABLE login_as_customer RENAME TO uat_login_as_customer;
ALTER TABLE login_as_customer_assistance_allowed RENAME TO uat_login_as_customer_assistance_allowed;
ALTER TABLE magento_acknowledged_bulk RENAME TO uat_magento_acknowledged_bulk;
ALTER TABLE magento_bulk RENAME TO uat_magento_bulk;
ALTER TABLE magento_login_as_customer_log RENAME TO uat_magento_login_as_customer_log;
ALTER TABLE magento_operation RENAME TO uat_magento_operation;
ALTER TABLE media_content_asset RENAME TO uat_media_content_asset;
ALTER TABLE media_gallery_asset RENAME TO uat_media_gallery_asset;
ALTER TABLE media_gallery_asset_keyword RENAME TO uat_media_gallery_asset_keyword;
ALTER TABLE media_gallery_keyword RENAME TO uat_media_gallery_keyword;
ALTER TABLE mview_state RENAME TO uat_mview_state;
ALTER TABLE newsletter_problem RENAME TO uat_newsletter_problem;
ALTER TABLE newsletter_queue RENAME TO uat_newsletter_queue;
ALTER TABLE newsletter_queue_link RENAME TO uat_newsletter_queue_link;
ALTER TABLE newsletter_queue_store_link RENAME TO uat_newsletter_queue_store_link;
ALTER TABLE newsletter_subscriber RENAME TO uat_newsletter_subscriber;
ALTER TABLE newsletter_template RENAME TO uat_newsletter_template;
ALTER TABLE oauth_consumer RENAME TO uat_oauth_consumer;
ALTER TABLE oauth_nonce RENAME TO uat_oauth_nonce;
ALTER TABLE oauth_token RENAME TO uat_oauth_token;
ALTER TABLE oauth_token_request_log RENAME TO uat_oauth_token_request_log;
ALTER TABLE password_reset_request_event RENAME TO uat_password_reset_request_event;
ALTER TABLE patch_list RENAME TO uat_patch_list;
ALTER TABLE paypal_billing_agreement RENAME TO uat_paypal_billing_agreement;
ALTER TABLE paypal_billing_agreement_order RENAME TO uat_paypal_billing_agreement_order;
ALTER TABLE paypal_cert RENAME TO uat_paypal_cert;
ALTER TABLE paypal_payment_transaction RENAME TO uat_paypal_payment_transaction;
ALTER TABLE paypal_settlement_report RENAME TO uat_paypal_settlement_report;
ALTER TABLE paypal_settlement_report_row RENAME TO uat_paypal_settlement_report_row;
ALTER TABLE persistent_session RENAME TO uat_persistent_session;
ALTER TABLE product_alert_price RENAME TO uat_product_alert_price;
ALTER TABLE product_alert_stock RENAME TO uat_product_alert_stock;
ALTER TABLE queue RENAME TO uat_queue;
ALTER TABLE queue_lock RENAME TO uat_queue_lock;
ALTER TABLE queue_message RENAME TO uat_queue_message;
ALTER TABLE queue_message_status RENAME TO uat_queue_message_status;
ALTER TABLE queue_poison_pill RENAME TO uat_queue_poison_pill;
ALTER TABLE quote RENAME TO uat_quote;
ALTER TABLE quote_address RENAME TO uat_quote_address;
ALTER TABLE quote_address_item RENAME TO uat_quote_address_item;
ALTER TABLE quote_id_mask RENAME TO uat_quote_id_mask;
ALTER TABLE quote_item RENAME TO uat_quote_item;
ALTER TABLE quote_item_option RENAME TO uat_quote_item_option;
ALTER TABLE quote_payment RENAME TO uat_quote_payment;
ALTER TABLE quote_shipping_rate RENAME TO uat_quote_shipping_rate;
ALTER TABLE rating RENAME TO uat_rating;
ALTER TABLE rating_entity RENAME TO uat_rating_entity;
ALTER TABLE rating_option RENAME TO uat_rating_option;
ALTER TABLE rating_option_vote RENAME TO uat_rating_option_vote;
ALTER TABLE rating_option_vote_aggregated RENAME TO uat_rating_option_vote_aggregated;
ALTER TABLE rating_store RENAME TO uat_rating_store;
ALTER TABLE rating_title RENAME TO uat_rating_title;
ALTER TABLE release_notification_viewer_log RENAME TO uat_release_notification_viewer_log;
ALTER TABLE report_compared_product_index RENAME TO uat_report_compared_product_index;
ALTER TABLE report_event RENAME TO uat_report_event;
ALTER TABLE report_event_types RENAME TO uat_report_event_types;
ALTER TABLE report_viewed_product_aggregated_daily RENAME TO uat_report_viewed_product_aggregated_daily;
ALTER TABLE report_viewed_product_aggregated_monthly RENAME TO uat_report_viewed_product_aggregated_monthly;
ALTER TABLE report_viewed_product_aggregated_yearly RENAME TO uat_report_viewed_product_aggregated_yearly;
ALTER TABLE report_viewed_product_index RENAME TO uat_report_viewed_product_index;
ALTER TABLE reporting_counts RENAME TO uat_reporting_counts;
ALTER TABLE reporting_module_status RENAME TO uat_reporting_module_status;
ALTER TABLE reporting_orders RENAME TO uat_reporting_orders;
ALTER TABLE reporting_system_updates RENAME TO uat_reporting_system_updates;
ALTER TABLE reporting_users RENAME TO uat_reporting_users;
ALTER TABLE review RENAME TO uat_review;
ALTER TABLE review_detail RENAME TO uat_review_detail;
ALTER TABLE review_entity RENAME TO uat_review_entity;
ALTER TABLE review_entity_summary RENAME TO uat_review_entity_summary;
ALTER TABLE review_status RENAME TO uat_review_status;
ALTER TABLE review_store RENAME TO uat_review_store;
ALTER TABLE sales_bestsellers_aggregated_daily RENAME TO uat_sales_bestsellers_aggregated_daily;
ALTER TABLE sales_bestsellers_aggregated_monthly RENAME TO uat_sales_bestsellers_aggregated_monthly;
ALTER TABLE sales_bestsellers_aggregated_yearly RENAME TO uat_sales_bestsellers_aggregated_yearly;
ALTER TABLE sales_creditmemo RENAME TO uat_sales_creditmemo;
ALTER TABLE sales_creditmemo_comment RENAME TO uat_sales_creditmemo_comment;
ALTER TABLE sales_creditmemo_grid RENAME TO uat_sales_creditmemo_grid;
ALTER TABLE sales_creditmemo_item RENAME TO uat_sales_creditmemo_item;
ALTER TABLE sales_invoice RENAME TO uat_sales_invoice;
ALTER TABLE sales_invoice_comment RENAME TO uat_sales_invoice_comment;
ALTER TABLE sales_invoice_grid RENAME TO uat_sales_invoice_grid;
ALTER TABLE sales_invoice_item RENAME TO uat_sales_invoice_item;
ALTER TABLE sales_invoiced_aggregated RENAME TO uat_sales_invoiced_aggregated;
ALTER TABLE sales_invoiced_aggregated_order RENAME TO uat_sales_invoiced_aggregated_order;
ALTER TABLE sales_order RENAME TO uat_sales_order;
ALTER TABLE sales_order_address RENAME TO uat_sales_order_address;
ALTER TABLE sales_order_aggregated_created RENAME TO uat_sales_order_aggregated_created;
ALTER TABLE sales_order_aggregated_updated RENAME TO uat_sales_order_aggregated_updated;
ALTER TABLE sales_order_grid RENAME TO uat_sales_order_grid;
ALTER TABLE sales_order_item RENAME TO uat_sales_order_item;
ALTER TABLE sales_order_payment RENAME TO uat_sales_order_payment;
ALTER TABLE sales_order_status RENAME TO uat_sales_order_status;
ALTER TABLE sales_order_status_history RENAME TO uat_sales_order_status_history;
ALTER TABLE sales_order_status_label RENAME TO uat_sales_order_status_label;
ALTER TABLE sales_order_status_state RENAME TO uat_sales_order_status_state;
ALTER TABLE sales_order_tax RENAME TO uat_sales_order_tax;
ALTER TABLE sales_order_tax_item RENAME TO uat_sales_order_tax_item;
ALTER TABLE sales_payment_transaction RENAME TO uat_sales_payment_transaction;
ALTER TABLE sales_refunded_aggregated RENAME TO uat_sales_refunded_aggregated;
ALTER TABLE sales_refunded_aggregated_order RENAME TO uat_sales_refunded_aggregated_order;
ALTER TABLE sales_sequence_meta RENAME TO uat_sales_sequence_meta;
ALTER TABLE sales_sequence_profile RENAME TO uat_sales_sequence_profile;
ALTER TABLE sales_shipment RENAME TO uat_sales_shipment;
ALTER TABLE sales_shipment_comment RENAME TO uat_sales_shipment_comment;
ALTER TABLE sales_shipment_grid RENAME TO uat_sales_shipment_grid;
ALTER TABLE sales_shipment_item RENAME TO uat_sales_shipment_item;
ALTER TABLE sales_shipment_track RENAME TO uat_sales_shipment_track;
ALTER TABLE sales_shipping_aggregated RENAME TO uat_sales_shipping_aggregated;
ALTER TABLE sales_shipping_aggregated_order RENAME TO uat_sales_shipping_aggregated_order;
ALTER TABLE salesrule RENAME TO uat_salesrule;
ALTER TABLE salesrule_coupon RENAME TO uat_salesrule_coupon;
ALTER TABLE salesrule_coupon_aggregated RENAME TO uat_salesrule_coupon_aggregated;
ALTER TABLE salesrule_coupon_aggregated_order RENAME TO uat_salesrule_coupon_aggregated_order;
ALTER TABLE salesrule_coupon_aggregated_updated RENAME TO uat_salesrule_coupon_aggregated_updated;
ALTER TABLE salesrule_coupon_usage RENAME TO uat_salesrule_coupon_usage;
ALTER TABLE salesrule_customer RENAME TO uat_salesrule_customer;
ALTER TABLE salesrule_customer_group RENAME TO uat_salesrule_customer_group;
ALTER TABLE salesrule_label RENAME TO uat_salesrule_label;
ALTER TABLE salesrule_product_attribute RENAME TO uat_salesrule_product_attribute;
ALTER TABLE salesrule_website RENAME TO uat_salesrule_website;
ALTER TABLE search_query RENAME TO uat_search_query;
ALTER TABLE search_synonyms RENAME TO uat_search_synonyms;
ALTER TABLE sendfriend_log RENAME TO uat_sendfriend_log;
ALTER TABLE sequence_creditmemo_0 RENAME TO uat_sequence_creditmemo_0;
ALTER TABLE sequence_creditmemo_1 RENAME TO uat_sequence_creditmemo_1;
ALTER TABLE sequence_invoice_0 RENAME TO uat_sequence_invoice_0;
ALTER TABLE sequence_invoice_1 RENAME TO uat_sequence_invoice_1;
ALTER TABLE sequence_order_0 RENAME TO uat_sequence_order_0;
ALTER TABLE sequence_order_1 RENAME TO uat_sequence_order_1;
ALTER TABLE sequence_shipment_0 RENAME TO uat_sequence_shipment_0;
ALTER TABLE sequence_shipment_1 RENAME TO uat_sequence_shipment_1;
ALTER TABLE session RENAME TO uat_session;
ALTER TABLE setup_module RENAME TO uat_setup_module;
ALTER TABLE shipping_tablerate RENAME TO uat_shipping_tablerate;
ALTER TABLE sitemap RENAME TO uat_sitemap;
ALTER TABLE store RENAME TO uat_store;
ALTER TABLE store_group RENAME TO uat_store_group;
ALTER TABLE store_website RENAME TO uat_store_website;
ALTER TABLE tax_calculation RENAME TO uat_tax_calculation;
ALTER TABLE tax_calculation_rate RENAME TO uat_tax_calculation_rate;
ALTER TABLE tax_calculation_rate_title RENAME TO uat_tax_calculation_rate_title;
ALTER TABLE tax_calculation_rule RENAME TO uat_tax_calculation_rule;
ALTER TABLE tax_class RENAME TO uat_tax_class;
ALTER TABLE tax_order_aggregated_created RENAME TO uat_tax_order_aggregated_created;
ALTER TABLE tax_order_aggregated_updated RENAME TO uat_tax_order_aggregated_updated;
ALTER TABLE theme RENAME TO uat_theme;
ALTER TABLE theme_file RENAME TO uat_theme_file;
ALTER TABLE translation RENAME TO uat_translation;
ALTER TABLE ui_bookmark RENAME TO uat_ui_bookmark;
ALTER TABLE url_rewrite RENAME TO uat_url_rewrite;
ALTER TABLE variable RENAME TO uat_variable;
ALTER TABLE variable_value RENAME TO uat_variable_value;
ALTER TABLE vault_payment_token RENAME TO uat_vault_payment_token;
ALTER TABLE vault_payment_token_order_payment_link RENAME TO uat_vault_payment_token_order_payment_link;
ALTER TABLE weee_tax RENAME TO uat_weee_tax;
ALTER TABLE widget RENAME TO uat_widget;
ALTER TABLE widget_instance RENAME TO uat_widget_instance;
ALTER TABLE widget_instance_page RENAME TO uat_widget_instance_page;
ALTER TABLE widget_instance_page_layout RENAME TO uat_widget_instance_page_layout;
ALTER TABLE wishlist RENAME TO uat_wishlist;
ALTER TABLE wishlist_item RENAME TO uat_wishlist_item;
ALTER TABLE wishlist_item_option RENAME TO uat_wishlist_item_option;

3. Change the table prefix in app/etc/env.php

Open the file app/etc/env.php and change the value for the key table_prefix under db node.
For example:

    'db' => [
        'table_prefix' => 'uat_',
        'connection' => [
            'default' => [
                'host' => 'localhost',
                'dbname' => 'magento242',
                'username' => 'dbuser',
                'password' => 'dbpass',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8;',
                'active' => '1',
            ]
        ]
    ],

You can run setup:upgrade command if required.

4. Clear Cache

After executing SQL statements generated in step 2 and configuring the table prefix as in step 3, we are ready to go after clearing the cache.

Let us know in the comment below if this solution has helped you in any way or has some alternative/better approach.