How can I check if mysql table column even exists?

后端 未结 8 975
闹比i
闹比i 2020-12-30 08:44

How can I check if mysql table field even exists ?

The column name is \'price\' and I need to see if it exists.

Haven\'t understood really how the \'EXISTS\'

8条回答
  •  天涯浪人
    2020-12-30 08:54

    Try:

    IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'TEST' AND COLUMN_NAME = 'Price')
    BEGIN
        -- do something, e.g.
        -- ALTER TABLE TEST ADD PRICE DECIMAL
    END
    

提交回复
热议问题