mysql - 将外键和名称更新为新的相似表列

标签 mysql

假设我们有四个表

员工、employee_history、employee_details、emp_details_history

employee_history 是员工的重复项 emp_details_history 应该是employee_details 的重复

人们没有引用emp_details_history中的employee_history,而是引用了员工表并创建了列并且也具有值。

现在我想更改employee_details_history的外键列名称以指向employee_history而不是emp_details。

employee_details_history 具有列 pkey 和 employee_id(而不是 pkey 和 employee_history_id)

系统不允许删除历史表中引用的员工记录。历史不同,实际记载应该不同。

现在想要指向正确的列和名称。

您能帮我看看如何更改外键列和名称吗?

提前致谢。

最佳答案

         1. To remove foreign key constraints
            go to phpmyadmin

            select prefered table

            select structure

            click relational view link under the structure

            change the Foreign key constraint of needed columns


         2. to change column names

            go to phpmyadmin

            select prefered table

            select structure
            click change link of preferred column
            change the column name

如果您想作为查询来更改列名称,请尝试此操作 Error renaming a column in MySQL

如果你想删除外键试试这个 MySQL Removing Some Foreign keys

希望这有帮助

关于mysql - 将外键和名称更新为新的相似表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35476292/

相关文章:

sql - Mysql 是否与 mssql 中的 @@ROWCOUNT 等效?

mysql - 非常大的数据库插入失败 - MySQL、JPA 2、WildFly 8

mysql - 在表中有一对 friend ,如何创建一个抽象获取用户 friend 列表的 View ?

mysql - SQL 中点与线的空间交集

mysql - 如何使用没有数据库名称的引擎对象查询数据库

mysql - 将图像转换为 nvarchar(max)

php - 将此文本导入数据库

mysql - 如何读取 innodb 日志文件?

php - 按行显示图像

php - 在MySQL上创建日期类型的表并使用其默认值作为CURRENT_DATE