June 17, 2014 at 4:23 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:28 am
You can use INFORMATION_SCHEMA.columns for the same purpose. Filter on the table and check if the column exists.
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:35 am
I have both realities:
Some databases are in SQL Server 2000 na others in SQL server 2005.
Can you show me the commands to do this?
Thank you
June 17, 2014 at 4:47 am
river1 (6/17/2014)
Can you show me the commands to do this?
Koen already did.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 17, 2014 at 4:50 am
Koen Verbeeck (6/17/2014)
You can use INFORMATION_SCHEMA.columns for the same purpose. Filter on the table and check if the column exists.
It is applicable to both.
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
June 17, 2014 at 4:58 am
rhythmk (6/17/2014)
Koen Verbeeck (6/17/2014)
You can use INFORMATION_SCHEMA.columns for the same purpose. Filter on the table and check if the column exists.It is applicable to both.
And that is why, ladies and gentlemen, we do not crosspost or duplicate post on these forums. 😀
http://www.sqlservercentral.com/Forums/Topic1582200-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 5:32 am
Koen Verbeeck (6/17/2014)
rhythmk (6/17/2014)
Koen Verbeeck (6/17/2014)
You can use INFORMATION_SCHEMA.columns for the same purpose. Filter on the table and check if the column exists.It is applicable to both.
And that is why, ladies and gentlemen, we do not crosspost or duplicate post on these forums. 😀
http://www.sqlservercentral.com/Forums/Topic1582200-146-1.aspx
My bad...did notice that it is a duplicate post 🙁
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply