How to delete a column of a MySQL View?

Perhpas the answer is obvious, but I’ve not figured it out. How do you delete a column of a MySQL View?

āœ… Answers

? Best Answer

  • You can either ALTER the view or can CREATE OR REPLACE (that’s the same as ALTER if the view already exists).

    As you rightly note, anyone dropping table columns to achieve this is going to have a lot of problems šŸ™‚

    http://dev.mysql.com/doc/refman/5.0/en/aā€¦

    http://dev.mysql.com/doc/refman/5.0/en/cā€¦

  • ALTER table [TABLENAME] DROP column [COLUMN NAME]

  • You don’t actually delete a column from a view, you simply don’t select that column in your SQL statement.

    Such as “SELECT <column1>, <column2>, <etc> FROM <table or view> WHERE <criteria>”

    Simply don’t include <column-x> in your SELECT statement.

    Edit:
    I just saw the other answer, and that answer is accurate, as far as it goes, but you were asking about a view, not a table. But what I said will work with either a view OR a table.

    My solution is only if you cannot access the actual table or view, and you have to use what you have.

  • To delete the column col_stuff from the table table_things, use the following SQL command:

    ALTER TABLE ‘table_things’ DROP ‘col_stuff’

  • Leave a Comment