How to check if column exists in SQL Server table

The following queries may help you to check the existing column in SQL Server.

1- Using sys.columns


IF EXISTS( 
            SELECT Name 
            FROM sys.columns
            WHERE Name = N'Col_Name'  
            AND Object_ID = Object_ID(N'Tbl_Name')
)
BEGIN
    print 'true'
END


Note: It will return NULL if the user doesn't have permission to view the metadata because of sys.columns checks user access too.

2- INFORMATION_SCHEMA.columns

  if not exists (select
                     column_name
               from
                     INFORMATION_SCHEMA.columns
               where
                     table_name = 'MyTable'
                     and column_name = 'MyColumn')
    alter table MyTable add MyColumn int

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...