关于MySQL:ERROR 1022 (23000): Can't write; duplicate key in table 'test4'


ERROR 1022 (23000): Can't write; duplicate key in table 'test4':在为"test4"表设置外键时.外键名与已有的外键名重复;代码如下,注意加粗部分

 

错误代码:

mysql> create table test4(

    -> id int,

    -> cp_name varchar(32),

    -> constraint test_fk foreign key(cp_name) references student(name)

    -> );

ERROR 1022 (23000): Can't write; duplicate key in table 'test4'

 

正确代码:

mysql> create table test4(

    -> id int,

    -> cp_name varchar(32),

    -> constraint test1_fk foreign key(cp_name) references student(name)

    -> );

Query OK, 0 rows affected (0.54 sec)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM