-1

I have a before and after query which I'm currently looking at this is filled with Ambiguous Column Name Errors.

I'd like to be able to hover over certain columns in the query in the before query and see which table this was mapped to. When hovering at the moment, all I see is

column k(datatype, null)

Is there a way to achieve this on SQL Server Management 2012? I'd be happy with a third party plug in if there possible to be installed.

As an example,

SELECT * FROM TABLE1
WHERE column1 = "stack"

In the above example, I'd want to hover over "column1" and see it reference to "Table1" somehow.

1 Answer 1

1

I am able to effectively accomplish this by using a table alias on the column declarations in: SELECT, JOIN, WHERE, etc... clauses. Assuming the rest of my answer is not helpful for you, I have heard really good things about SQL Prompt from RedGate.

Assuming a simple SELECT statement like below you can fairly easily identify what table a column belongs to. (You should be able to include AS in between the table name and it's alias, I just typically don't).

SELECT CP.ClientID,
FAIFN.FaxNumber,
IFax.VendorJobNumber,
IFax.CreateDateTime
FROM ClientProgram CP
    INNER JOIN FaxAccountInboundFaxNumber FAIFN
        ON CP.Id = FAIFN.ClientProgramID
    INNER JOIN InboundFax IFax
        ON IFax.FaxAccountInboundFaxNumberID = FAIFN.ID
WHERE CP.ClientId = @ClientID

There is a smaller added benefit for more complicated queries like it sounds like you are working with. I am able to hover over table alias to identify what table the alias is referencing, and thus what table that column belongs to. (You can't tell but my mouse was hovering over the FAIFN in the SELECT)

Hover Over Table Alias for Alias Definition/Source

Hopefully that helps.

1
  • SQL Prompt done the trick. I installed the free version and this showed what I needed. Thank you for the recommendation.
    – Aiden
    Apr 8, 2020 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.