Skip to main content
krishnav9816
July 15, 2022
Solved

how to set Foreign Key in database?

  • July 15, 2022
  • 22 replies
  • 0 views

how to set Foreign Key in database? mariadb

    Best answer by harshitb6843



    22 replies

    harshitb6843
    July 15, 2022
    krishnav9816
    July 16, 2022

     table1 

     table 2

    based on the above two tables tabel1 & table 2 ,I want claim id is foreign key in the table 2 ? what is the syntax ?

    harshitb6843
    July 17, 2022

    Did you check the link I provided in the above comment?

    July 17, 2022

    ALTER TABLE table2
    ADD FOREIGN KEY (Claim ID) REFERENCES table1(id);

    krishnav9816
    July 18, 2022

    Error

    SQL query: Copy

    ALTER TABLE LMS_Aprrovals
    ADD FOREIGN KEY (Claim ID) REFERENCES lmscustomerdetails(id);
    

    MySQL said: 

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ID) REFERENCES lmscustomerdetails(id)' at line 2

    July 18, 2022

    Try removing the space between Claim and ID in your column name by renaming the column name of 2nd table and try again with same syntax to add foreign key.