1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] When to use three-part column references in SQL 2014

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 3, 2024 às 08:42.

  1. Stack

    Stack Membro Participativo

    Firstly, apologies if this is in the wrong section, or the wrong style. Hunted for this answer for a while, to no avail.

    Imagine you have a (sample) SQL query in SQL 2014 -

    SELECT
    dbo.Users.Surname,
    dbo.Accounts.Type
    FROM
    dbo.Users
    INNER JOIN
    dbo.Accounts
    ON (dbo.Users.Id = dbo.Accounts.Id)


    Up until now, this is the format I've been using - fully qualifying the table objects with [schema].[tablename].[column].

    However, looking at the SQL 2014 Deprecated Database Engine Features, it says that this style is no longer standard -


    Two-part names is the standard-compliant behavior.

    After digging around for a while, I found the Transact-SQL Syntax Conventions, where it says -


    To avoid name resolution errors, we recommend specifying the schema name whenever you specify a schema-scoped object.

    So I'm a little confused as to how my little code snippet should be written. Should I only use the schema when referencing the tables, but when referring to columns, skip the schema and just use the table names? Or is it assuming all table objects should have an alias?

    Again, apologies for the potential subjectivity of this question. But essentially I'm asking about how to write SQL that does not use a deprecated feature of SQL 2014, but still reads well when joining multiple tables.

    Continue reading...

Compartilhe esta Página