Monday, 20 October 2014

Check for a column exists in SQL Table

Check for a column exists in SQL Table

select * from Information_SCHEMA.columns
where Table_name='Your Table Name' and column_name='Your Column Name'

2 comments:

  1. What will be returned? Is it Boolean type or something else? I cannot access SQL query window right now. Please clarify.

    ReplyDelete
    Replies
    1. Above Query will return
      TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,
      COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,
      CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_PRECISION_RADIX,
      NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_CATALOG,CHARACTER_SET_SCHEMA,
      CHARACTER_SET_NAME,COLLATION_CATALOG,COLLATION_SCHEMA,COLLATION_NAME,
      DOMAIN_CATALOG,DOMAIN_SCHEMA,DOMAIN_NAME

      Delete