Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check whether column exist or not in a table.

Status
Not open for further replies.

umeshs79

Programmer
Aug 7, 2002
42
DE
Hi,
I want to check whether a particular column exist or not in a given table. This i want to check before dropping the column so no error comes if column is not present.

So please can anybody tell me how i do this?
Exmple:
--How to do: check if column exist
-- if exist
ALTER table table_name DROP COLUMN column_name

Thanks Umesh Sharma,MCSD
India
 
You can use the information schema views as so:

if exists(select 'x'
from information_schema.columns
where table_name = 'test5'
and column_name = 'col2')
begin
alter table test5 drop column col2
end


Chris.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top