# Miscellaneous > Ask an Expert >  IF EXISTS Column  (for MS SQL 2000)

## qwer

Hello

How do you check if a column exist for MS SQL 2000 ?

for a table :

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[myTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[myTable]
GO

but I dont find it for a column 

Thank you

----------


## rmiao

Can query information_schema.columns.

----------


## qwer

? I dont understand the meaning of your answer
I got this code on another forum :

if exists ( select * from INFORMATION_SCHEMA.COLUMNS 
where TABLE_NAME='tablename' 
and COLUMN_NAME='columname' )
drop table [dbo].[myTable]

but I want to drop the column not the table ?

then maybe :

if exists ( select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tablename'
and COLUMN_NAME='columname' )
drop COLUMN 'columname' 

thank you for helping

----------


## rmiao

You can use 'alter table' to drop column. By the way, you original question is 'How do you check if a column exist for MS SQL 2000'.

----------


## qwer

oops ! yessorry !

then is that correct to drop a column if this colum exists ?

if exists ( select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tablename'
and COLUMN_NAME='columname' )
drop COLUMN 'columname'

----------


## rmiao

You have to use 'alter table table_name drop column column_name'.

----------


## qwer

thank you rmiao

----------

