Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 if condition using alter command to add field

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2006-06-09 : 12:12:42
I have the following alter command:

Can you please tell me, i want to add an if condition on the top to check if the field exists then ignore otherwise run the alter command:

*******************************
ALTER TABLE premlist_montserrat

ADD filetype nvarchar(50)

GO
*******************************

Thank you very much for the info.

sanjnep
Posting Yak Master

191 Posts

Posted - 2006-06-09 : 12:29:48
if not exists (select * from syscolumns where object_id('premlist_montserrat')= id and name = 'filetype')
begin
ALTER TABLE premlist_montserrat

ADD filetype nvarchar(50)
end
else
begin
print 'column alredy::::::'
end


--some thing like this ............

Sanjeev Shrestha
12/17/1963
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-10 : 03:35:38
or


if col_length('TableName', 'ColumnName') is null
Alter table ...





Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -