June 17, 2014 at 4:20 am
Hi,
I want to run this command over all my databases that don't have this column:
alter table CONFIGURACAO add [USA_RFORIGEM] [bit] NULL
If it was a table I could do like this:
if exists (select * from sysobjects where name ='...')
begin
drop table...
end
create table .....
But, how can I prevent this script from running if the column already exists on the table. I only know how to do this for objects like tables, views, etc...
June 17, 2014 at 4:29 am
Duplicate post.
Original question with replies can be found here:
http://www.sqlservercentral.com/Forums/Topic1582202-146-1.aspx
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 17, 2014 at 4:32 am
IF NOT EXISTS (
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'USA_RFORIGEM '
AND TABLE_NAME = 'CONFIGURACAO'
)
ALTER TABLE CONFIGURACAO
ADD USA_RFORIGEM bit NULL
John
June 17, 2014 at 4:36 am
But, I need to make only one script that can run over 2000 or 2005 databases.
That script is valid only for sql server 2005, correct?
June 17, 2014 at 4:41 am
Well, the best way to find out is to try it!
John
June 17, 2014 at 4:49 am
river1 (6/17/2014)
But, I need to make only one script that can run over 2000 or 2005 databases.That script is valid only for sql server 2005, correct?
The information schema views are also available for SQL Server 2000.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply