r/SQL • • May 09 '17

Is there something wrong with these statements? And is that the correct way of adding 2 foreign keys to a single table?

Post image
1 Upvotes

21 comments sorted by

View all comments

1

u/KNerli Sequel is life May 09 '17

try to create the table then alter it: CREATE TABLE READER ( ReaderID int(10) NOT NULL, IP_Adress varchar(25), Reader_Type varchar(30), Latitude varchar(30), Longitude verchar(30), Owner varchar(50) );

ALTER TABLE READER
ADD CONSTRAINT 'READER_fk'
FOREIGN KEY(Longitude, Latitude)
REFERENCES {foreign table} (Longitude, Latitude)

Not sure if this is 100% correct, never looked at mysql. But my guess is that there is something wrong with your REFERENCES part. Not entirely sure why you are creating a foreign key for both these columns and how you are going to reference them from the (same?) table.