15
I am trying to add a new column to an SQL Server table, and I want to know if it already exists or not. I have tried something like this:
IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'minhaTabela'
AND COLUMN_NAME = 'minhaColuna')
But it always resolves as false.
How can I know if a column already exists in an SQL Server table?
You can just try to enter, if it already exists it will simply give an error.
– Havenard
@Havenard is true, but I want a way to add it if it’s not there, but if it is, do nothing. So it will not give error, and I can apply the script several times and always exit in the same way (with the column).
– brazilianldsjaguar