我正试图从表中删除一列.如何判断该列是否存在?
我查阅了https://www.postgresql.org/docs/9.2/static/sql-altertable.html页的文档,但没有找到任何示例.
甚至发现了How to check if a column exists in a SQL Server table?个,但似乎并不相关.
我正试图从表中删除一列.如何判断该列是否存在?
我查阅了https://www.postgresql.org/docs/9.2/static/sql-altertable.html页的文档,但没有找到任何示例.
甚至发现了How to check if a column exists in a SQL Server table?个,但似乎并不相关.
您只需在DROP COLUMN
语句中添加IF EXIST
即可:
ALTER TABLE tableName
DROP COLUMN IF EXISTS columnName;