Automation for Smart Rename
ggrater@hotmail.com
Posts: 3
I have a database constructed with acronyms. All tables and columns begin with a three character acronym followed by capitalized columns and table names. I have created a mapping table that maps all tables and columns from the acronym insantity to camel case.
Is there an API for Smart Rename that would allow me programmically roll through the mapping table and execute a Smart Rename for each table name and column name?
Of course, there are all sorts of caveats to this approach, but I'm hoping someone knows of an API (or some "send keys") method of doing this.
Is there an API for Smart Rename that would allow me programmically roll through the mapping table and execute a Smart Rename for each table name and column name?
Of course, there are all sorts of caveats to this approach, but I'm hoping someone knows of an API (or some "send keys") method of doing this.
Greg
Comments
I have added your suggestion to an existing feature request, reference SP-3057.
I cannot guarantee the success of the feature request but if approval is given, hopefully you will see it in a future version of SQL Prompt.
Many Thanks
Eddie
Senior Product Support Engineer
Redgate Software Ltd
Email: support@red-gate.com
As a suggestion, make the API callable via TSQL (maybe through the CLR via a function taking OldName, NewName and ObjectType) such that the API returns the SQL Script necessary to preform the Smart Rename. Then we can pull all that together and execute it as a large script (or set of scripts).
For Instance, I'd like to be able to do the following.
1) loop through each table and column from a source that provides the old and new name.
2) for each old value, call Red Gate's API to get the SQL required to perform the Smart Rename.
3) sp_executeSQL the returned SQL.
4) loop to the next old/new item.
Thanks!
I have updated the Feature Request, SP-3057, with your latest comments and suggestions.
Many Thanks
Eddie
Senior Product Support Engineer
Redgate Software Ltd
Email: support@red-gate.com
The Dependencies list from Smart Rename is perfect, except it takes way too long to manually check hundreds of columns.
Thank you,
Traci
SELECT object_name(object_id) AS 'Tablename', name AS 'ColumnName',
(
SELECT DISTINCT object_name(object_id) FROM sys.sql_dependencies
WHERE class IN (0, 1) AND referenced_minor_id > 0 AND referenced_major_id = C.object_id
FOR XML PATH('Object'), ROOT('Dependencies'), TYPE
) AS 'DependencyXML'
FROM sys.columns C
WHERE EXISTS
(
SELECT 1 FROM sys.sql_dependencies
WHERE class IN (0, 1) AND referenced_minor_id > 0 AND referenced_major_id = C.object_id
)
I'm sure this could be refined and written better, but I hope this may help as a starter...
Traci