
ALTER TABLE students_address_table DROP COLUMN student_id Įrror Code: 1828. Observe the response after executing below query. Student_id column in the table students_address_table is a foreign key. To view all the columns of the table, lets execute: SHOW COLUMNS FROM students_address_table INSERT INTO students_address_table (student_id,student_address) CREATE TABLE students_address_table (įOREIGN KEY (student_id) REFERENCES students_data(student_id), To better understand the concept, let us create a table with a foreign key constraint and insert rows into it.
Mysql delete column field from table how to#
This section lets us see how to drop a column from the table, which is a foreign key. Therefore other sessions will be allowed to read and write the table while we delete a column. ALTER TABLE students_data DROP COLUMN student_subject, ALGORITHM= INPLACE, LOCK=NONE Note – MySQL 5.6 onwards allows other sessions to read and write the table while we are deleting the column.

Let us view if the column the student_subject is deleted by executing: SHOW COLUMNS FROM students_data Īs shown in figure 2, the column named student_subject is not present in the column list for the table students_data. ALTER TABLE students_data DROP COLUMN student_subject Ġ row(s) affected Records: 0 Duplicates: 0 Warnings: 0 We will be deleting the column student_subject from table students_data. MySQL delete column from a table – example column_name – the name of the column which will get deleted.table_reference – the name of the table from which we will be deleting the column.ALTER TABLE table_reference DROP COLUMN column_name MySQL delete column from a table -syntaxĪLTER TABLE is used to drop/delete a column from a table. MySQL: get column names and datatypes of a table.DROP multiple columns in MySQL with single ALTER statement.

Let us see what went into the table students_data by executing: SELECT * FROM students_data INSERT INTO students_data (student_name, student_address, student_grade, student_subject) We will be creating a table students_data followed by adding some rows to it.

Looking for Something Search for: Search Recent Posts
