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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for the exsistance of a column.

Status
Not open for further replies.

jeffmoore64

Programmer
Mar 23, 2005
207
US
How do I check for the exsistance of a column in a table and if it is not there add it.
TIA
Jeff
 
Code:
If Not Exists(Select * 
              From   Information_Schema.Columns 
              Where  Table_Name = '[!]YourTableName[/!]'
                     And Column_Name = '[!]YourColumnName[/!]')
  Alter Table [!]YourTableName[/!] Add [!]YourColumnName[/!] int

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
IF NOT EXISTS(
select *
from information_schema.columns
where TABLE_NAME = 'YourTableHere'
AND COLUMN_NAME = 'YourColumnHere')
BEGIN
ALTER TABLE ---
END

- Paul
- Database performance looks fine, it must be the Network!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top