How to check if a column exists in MSSQL

To check if a column exists in MSSQL you can use the following snippet.

Sample MSSQL

SELECT name FROM sys.columns WHERE object_id = OBJECT_ID('Pricetable') AND name='Price'

Please rate this snippet

How to list all columns from a table in MSSQL

To list all columns from a table in MSSQL you can use the following snippet.

Sample MSSQL

SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('TABLENAME') ORDER BY name ASC

If you are using Oracle, take a look at this snippet -> How to get all column names of a Table in Oracle

Please rate this snippet