Foreign key error

Joined
Nov 8, 2024
Messages
5
Reaction score
0
Hello,

I am a newbie in databases and programming in general...

I build a new database, I have made 5 tables so far and have added foreign keys without problems
I have a table that must have foreign key from the same column of the same table 8 times...
I have changed the foreign key name but I get an error, that is not true....

Type is INT in both columns

Thanks!!!
 

Attachments

  • Screenshot from 2024-12-26 12-57-16.png
    Screenshot from 2024-12-26 12-57-16.png
    17.5 KB · Views: 50
Joined
Jul 4, 2023
Messages
609
Reaction score
81
Type is INT in both columns

1735302533323.png

In SQL, the difference between INT and UNSIGNED INT can lead to issues when joining tables using foreign keys.
  • INT: Can store integer values in the range of -2,147,483,648 to 2,147,483,647.
  • UNSIGNED INT: Stores values in the range of 0 to 4,294,967,295 (positive numbers only).
If you attempt to join an id field of type INT in one table with UNSIGNED INT in another, SQL may raise an error or warning because the ranges of these two data types do not overlap.

SQL:
CREATE TABLE Table1 (
    id UNSIGNED INT PRIMARY KEY
);

CREATE TABLE Table2 (
    id INT PRIMARY KEY
    table1_id UNSIGNED INT,
    FOREIGN KEY (table1_id) REFERENCES Table1(id)
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top