Dynamiclly rename table name

Dynamiclly rename table name.

Last updated:

Warning: Review and test in a non-production environment before running.

Back to results

select 'EXEC sp_rename ''' + table_name + ''',' + '''' + 'Z_'+table_name + ''';'
  from INFORMATION_SCHEMA.tables
 where table_name like 'Product%'

EXEC sp_rename 'Product','Z_Product';
EXEC sp_rename 'Product_inmem','Z_Product_inmem';
EXEC sp_rename 'Product_ondisk','Z_Product_ondisk';
EXEC sp_rename 'ProductCategory','Z_ProductCategory';
EXEC sp_rename 'ProductCostHistory','Z_ProductCostHistory';
EXEC sp_rename 'ProductDescription','Z_ProductDescription';
EXEC sp_rename 'ProductDocument','Z_ProductDocument';
EXEC sp_rename 'ProductInventory','Z_ProductInventory';
EXEC sp_rename 'ProductListPriceHistory','Z_ProductListPriceHistory';
EXEC sp_rename 'ProductModel','Z_ProductModel';
EXEC sp_rename 'ProductModelIllustration','Z_ProductModelIllustration';
EXEC sp_rename 'ProductModelProductDescriptionCulture','Z_ProductModelProductDescriptionCulture';
EXEC sp_rename 'ProductPhoto','Z_ProductPhoto';
EXEC sp_rename 'ProductProductPhoto','Z_ProductProductPhoto';
EXEC sp_rename 'ProductReview','Z_ProductReview';
EXEC sp_rename 'ProductSubcategory','Z_ProductSubcategory';
EXEC sp_rename 'ProductVendor','Z_ProductVendor';