關於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