How do I check if a column exists in SQL Server 2000?
In a query editor, if you highlight the text of table name (ex dbo. MyTable) and hit ALT + F1 , you'll get a list of column names, type, length, etc.
Change equal operator to IN operator then Name, some like this: SELECT * FROM sys. columns WHERE Name IN ('columnName_1','columnName_2') AND OBJECT_ID = OBJECT_ID('tableName').
In SQL Server, you can select COLUMN_NAME from INFORMATION_SCHEMA. COLUMNS .
To test whether a row exists in a MySQL table or not, use exists condition. The exists condition can be used with subquery. It returns true when row exists in the table, otherwise false is returned. True is represented in the form of 1 and false is represented as 0.
IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='tablename' AND COLUMN_NAME='columname' )
If col_length('table_name','column_name') is null select 0 as Present ELSE select 1 as Present
Present will be 0, is there is no column_name present in table_name , otherwise 1
@CMS: I don't think that 'INFORMATION_SCHEMA.COLUMNS' have information about every table in DB. Because this didn't worked for me. But my answer did worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With