Home Forums SQL Server 2008 SQL Server 2008 - General how to differentiate between two tables sharing the same name but belonging to different databases RE: how to differentiate between two tables sharing the same name but belonging to different databases

  • Jeff Moden (1/12/2014)


    GilaMonster (1/12/2014)


    Use three-part naming for your queries

    SELECT <column list> FROM Sims.dbo.Students

    SELECT <column list> FROM SimsCopy.dbo.Students

    I agree that works great for ad hoc queries (and you already know this... just saying it for others that may read this) but I'd stick with the 2 part naming convention in any stored T-SQL and use differently named synonyms to point to other database just in case they rename or even move that other database. It keeps you from having to find all occurances of 3 part naming in all of the code and changing it. It's much easier to just change the synonym.

    Sorry Jeff I have to agree with Gail here. ALWAYS use the three-part naming. It's going to make the query easier to read and you won't run into an issue of connecting/using the wrong table. I've seen it happen here time and time again.

    -------------------------------------------------------------
    we travel not to escape life but for life not to escape us
    Don't fear failure, fear regret.