I ran into some syntax over the weekend, that I am trying to make sense
of. Here is the create table statements.
Drop table if exists events
Drop table if exists locations
Create table events (
uid BIGINT NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
start_date DATE,
duration INTEGER,
location_id BIGINT,
primary key (uid)
);
Create table locations (
uid BIGINT NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
address VARCHAR(255),
primary key (uid)
)
Alter table events add index (location_id), add
Constraint FKB307E11920EBB9E5 foreign key (location_id) references
locations(uid)
// Here is my conclusion, and I was hoping someone may back this up.
Events has a primary key of UID that is auto_incremeneted.
Locations has a primary key of UID that is also incremented.
The constraint and index are where I have questions. What is the index
and constraint doing? I can't seem to get my mind around what that alter
statement is trying to accomplish.
Thanks,