how to set Foreign Key in database? mariadb
Discussion posts and replies are publicly visible
ALTER TABLE table2ADD FOREIGN KEY (Claim ID) REFERENCES table1(id);
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
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.
Refer this link for better understanding..
https://www.sqlshack.com/how-to-write-sql-queries-with-spaces-in-column-names/
ok bro i will do
yea i got it bro thanks....
that's ok bro I got it & one more thing how to delete a unnecessary or useless table (entire table)in mariaDB
any table in this mariaDB
Drop Table Table_Name;
ALTER TABLE `Travel_HR_Approval` ADD FOREIGN KEY (`claimid`) REFERENCES `Travel _Employee _Details`(`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT;
#1452 - Cannot add or update a child row: a foreign key constraint fails (`Appian`.`#sql-alter-200e-2a050`, CONSTRAINT `#sql-alter-200e-2a050_ibfk_1` FOREIGN KEY (`claimid`) REFERENCES `Travel _Employee _Details` (`ID`))
Drop Table CMS_Personal _Details;
#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 '_Details' at line 1
DROP TABLE CMS_Personal _Details;
DROP TABLE CMS_Personal_Details;Use the above code snippet as you are adding an extra space before _Details.
DROP TABLE CMS_Personal_Details;
#1051 - Unknown table 'Appian.CMS_Personal_Details'