tags:

views:

215

answers:

2

I have an script to update a database. That script create some columns in several tables. Some of that columns and so the message "Column names in each table must be unique." is shown. How can I disable this kind of message when running the script?

Thanks in advance. Rui

+3  A: 

It seems your database script is trying to create a column that already exists in your table.

Put in a check into your SQL script to add the column only if it doesn't already exist:

IF NOT EXISTS(SELECT * FROM sys.columns WHERE Name = 'ColumnName' 
              AND object_id = OBJECT_ID('YourTableName'))
BEGIN
   ALTER TABLE dbo.YourTableName
      ADD ColumnName INT    -- or whatever it is
END

Marc

marc_s
That's what I'm doing right now. The problem is that there are a lot of columns being created in the script. I was thinking in something like the "SET IDENTITY_INSERT OFF/ON" kind of thing...Rui
Rui
No, IDENTITY_INSERT has nothing to do with updating the table STRUCTURE - that's only for data insert.
marc_s
You need to check for each and every single column, sorry - no way around this.
marc_s
The SQK Server doesn't have any flag to prevnt these kind of messages from appearing?
Rui
No, and then **SHOULD** appear since you're doing something that's illegal! :-) Check first, only if not present create - no error messages then!
marc_s
You need to **fix the problem** - not suppress the resulting error messages.......
marc_s
Yes, I'm aware of that. It would be just a workaround to save me some work for a small time...Thanks anyway.
Rui
A: 

If I understand you correctly, you need to fix your database update script: the error is pretty clear, in that your SQL appears to specify updates to (or even creating) a column in a given table more than once.

Check the SQL you're using.

Ben Poole