AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Alter table drop column mysql11/29/2023 ![]() ALTER TABLE students_address_table DROP FOREIGN key students_address_table_ibfk_1 ĪLTER TABLE students_address_table DROP COLUMN student_id Syntax of deleting a foreign key constraint is similar to deleting a column. Therefore the solution is to delete the foreign key constraint first. Cannot drop column ‘student_id’: needed in a foreign key constraint ‘students_address_table_ibfk_1’ 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. 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
0 Comments
Read More
Leave a Reply. |