user212029
user212029

Reputation:

Column names in each table must be unique

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

Upvotes: 2

Views: 50966

Answers (2)

Ben
Ben

Reputation: 7597

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.

Upvotes: 0

marc_s
marc_s

Reputation: 754578

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

Upvotes: 9

Related Questions