How to remove a column from an existing table?

前端 未结 11 1012
旧巷少年郎
旧巷少年郎 2020-12-12 11:22

How to remove a column from an existing table?

I have a table MEN with Fname and Lname

I need to remove the Lnam

11条回答
  •  佛祖请我去吃肉
    2020-12-12 11:49

    In SQL Server 2016 you can use new DIE statements.

    ALTER TABLE Table_name DROP COLUMN IF EXISTS Column_name
    

    The above query is re-runnable it drops the column only if it exists in the table else it will not throw error.

    Instead of using big IF wrappers to check the existence of column before dropping it you can just run the above DDL statement

提交回复
热议问题