Column Exists or not?

  • Comments posted to this topic are about the item Column Exists or not?

    Thanks,
    Shiva N
    Database Consultant

  • Interesting function, but I suggest to modify the code to add the schema to the existence check because you can have two tables with the same name, one for input and one for logging incorrect data. Also I would suggest to add a join to the INFORMATION_SCHEMA.TABLES in order to be know you are interested in a table not a view.

    So the select statement should be

    SELECT 1

    FROM INFORMATION_SCHEMA.Columns C

    JOIN INFORMATION_SCHEMA.TABLES T ON C.TABLE_NAME = T.TABLE_NAME

    WHERE T.TABLE_NAME = @TableName AND T.SCHEMA_NAME = @SchemaName AND

    AND COLUMN_NAME = @ColumnName and T.TABLE_TYPE = 'BASE TABLE'

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply