a list of useful functions to rename or massively create tables in a Microsoft SQL sever database (Transact-SQL)

–-Create scripts for All Procs
SELECT SM.definition
FROM sys.sql_modules SM
INNER JOIN sys.Objects SO
ON SM.Object_id = SO.Object_id
WHERE SO.type = ‘p’
 
-–Create scripts for All Views
SELECT SM.definition
FROM sys.sql_modules SM
INNER JOIN sys.Objects SO
ON SM.Object_id = SO.Object_id
WHERE SO.type = ‘v’
   
-–Create scripts for All Functions
SELECT SM.definition
FROM sys.sql_modules SM
INNER JOIN sys.Objects SO
ON SM.Object_id = SO.Object_id
WHERE SO.type = ‘FN’

to mass-rename all tables for one database, in this example rename tables that contains the substring ‘tbc’

Declare @char varchar(3)
Set @char='tbc'
SELECT 'EXEC sp_rename ''' + NAME +  ''', ' + '''' + Substring(name ,CharIndex(@char,name)+3,LEN(name)) + ''''
As [Script]
FROM dbo.sysobjects 
WHERE xtype = 'U' And CharIndex(@char,name)>0
Order By [Name]
--OUTPUT
Facebooktwitterredditpinterestlinkedinmail