How to deal with SQL column names that look like SQL keywords?

后端 未结 14 1104
温柔的废话
温柔的废话 2020-11-22 13:24

One of my columns is called from. I can\'t change the name because I didn\'t make it. Am I allowed to do something like SELECT from FROM TableName

相关标签:
14条回答
  • 2020-11-22 13:55

    While you are doing it - alias it as something else (or better yet, use a view or an SP and deprecate the old direct access method).

    SELECT [from] AS TransferFrom -- Or something else more suitable
    FROM TableName
    
    0 讨论(0)
  • 2020-11-22 13:57

    Hi I work on Teradata systems that is completely ANSI compliant. Use double quotes " " to name such columns.

    E.g. type is a SQL reserved keyword, and when used within quotes, type is treated as a user specified name.

    See below code example:

    CREATE TABLE alpha1
    AS
    (
    SEL
    product1
    type_of_product AS "type"
    FROM beta1
    ) WITH DATA
    PRIMARY INDEX (product1)
    
    --type is a SQL reserved keyword
    
    TYPE
    
    --see? now to retrieve the column you would use:
    
    SEL "type" FROM alpha1
    
    0 讨论(0)
提交回复
热议问题