ALTER COLUMN IF EXISTS

Viewed 15251

I would like to alter the table if the table has the column with same data type and number exists

Original tTable structure is

TableName

ColumnName NVARCHAR(100)

Code for altering column if ColumnName with NVARCHAR and length 100 exists

IF EXISTS(...)
BEGIN
    ALTER TABLE [dbo].[TableName]
    ALTER COLUMN [ColumnName] NVARCHAR(200) [NULL|NOT NULL]
END

What find query I need to insert at IF EXISTS(...)?

6 Answers

For some reason, if you try to rename a column that does not exist, PostgreSQL will issue an error. Unfortunately that PostgreSQL does not provide the IF EXISTS option for the RENAME clause.

Related