Trong bài đăng này, tôi đang chia sẻ các tập lệnh khác nhau để tìm sự phụ thuộc của bảng cho Khoá ngoại
Ràng buộc, Xem và Thủ tục Lưu trữ của MySQL.
Kiến trúc cơ sở dữ liệu hoặc Nhà phát triển cơ sở dữ liệu phải tìm sự phụ thuộc của bảng trước khi có bất kỳ thay đổi DDL nào trên các Bảng.
Dưới đây là ba tập lệnh khác nhau:
1 2 3 4 5 6 7 8 9 10 | /*Find Table Dependency in Foreign Key Constraint.*/ SELECT Constraint_Type ,Constraint_Name ,Table_Schema ,Table_Name FROM information_schema.table_constraints WHERE Constraint_Type = 'FOREIGN KEY' AND Table_Name = 'Any_Table' AND Table_Schema ='db_Name'; |
1 2 3 4 5 | /*Find Table Dependency in Views.*/ SELECT * FROM information_schema.views WHERE Table_Schema='db_name' AND Table_Name = 'table_name' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /*Find Table Dependency in Stored Procedure.*/ SELECT Table_Schema ,Table_Name ,Table_Type ,Engine ,Routine_Name ,Routine_Schema ,Routine_Type FROM information_schema.tables INNER JOIN information_schema.routines ON routines.routine_definition LIKE Concat('%', tables.table_name, '%') WHERE Table_Schema ='db_name' |