qbjgqbjg
asked on
Rename multiple tables based on create_date
I have multiple tables that were created on a specific date. They are currently dbo.whatevername. I want them to be xxxlib.whatevername. How do I write sql code to accomplish this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can try the following script
--CREATE SCHEMA TestSchema
--USE Test01
--GO
DECLARE @SQL VARCHAR(MAX)
DECLARE @Change VARCHAR(MAX)
set @Change = 'ALTER SCHEMA TestSchema TRANSFER dbo.['
SELECT
@SQL = COALESCE(@SQL + @Change + [name] + '] ', @Change + [name] + '] ')
FROM
sys.tables
--WHERE
--create_date = Your condition
PRINT @SQL
EXEC (@SQL)
ASKER