Automatically alias tables and columns in existing scripts
Please could you add a feature that parses a query that has already been written, adds aliases for tables that don't already have them and update columns to use those aliases.
This is because I often get pieces of code which are partially aliased and I have to go through updating the missing ones. Thanks.
Eric Isaacs commented
If we could select an unaliased table and click F2 at that point, it would be great if SQL Prompt could create the alias at that point.
For a query like this below, clicking on the table name anywhere it's referenced and clicking F2 should 1) create the alias and 2) allow it to be named at that point.
INNER JOIN dbo.Category ON Category.CategoryID = Product.CategoryID
INNER JOIN dbo.CategoryGroup ON CategoryGroup.CategoryGroupId = Category.CategoryGroupId
Product.ProductId = 123456;
Right now the only way to create an alias for this type of existing SQL is to copy the table name, add AS table name next to the table, then use F2 on the new alias to rename the tables. It's cumbersome and slow for a query with multiple tables. Making it so that we can just click F2 on each table name would be so much easier and I assume it's much easier to implement in SQL Prompt than other options.
Eric Isaacs commented
This would be extremely helpful for me. This feature doesn't have to be an automatic format option (which I could see as a challenge.) It could simply be an option in the "Action List" that you can run on the selected code only.
is feature would be a huge time saver. I use automatic aliases for the code I write and it works great, but for existing code, we need a feature that would append the aliases even if it just appended the current table names.
EX: FROM dbo.TableName1 AS TableName1
From there it's easy enough to use F2 to rename the tables.
But an even better feature would be to use the default configured alias names
EX: FROM dbo.TableName1 AS tn1.
Either of those options or both would be a huge improvement.
Having both these options in the action list would be cool because there are times when one or the other is applicable to existing code, but having it configurable in options is also reasonable as to which type of aliasing would be preferred for each user/case.
Gert Hauan commented
What is the status of this request? Has it been implemented? If not, will it? If yes, how can we apply it?
This would be very helpful! I always have aliases for all columns
Nihar Bhalerao commented
I would like to take this a step further and also suggest that it would be better if SQL Prompt could schema qualify execution calls to child procs if it detects a missing schema name. This is particularly useful fro SQL 2017 where the optimizer is generating a CacheMiss event when schema name is not used in proc name.