Given the following table:
鉴于下表:
CREATE TABLE IF NOT EXISTS devices_used_by_resource (
id INT NOT NULL,
sourcesId INT NOT NULL,
name VARCHAR(45) NOT NULL,
PRIMARY KEY (id, sourcesId),
INDEX sourcesIdInx (sourcesId ASC),
UNIQUE INDEX nameSourceUniqueInx (name ASC, sourcesId ASC),
CONSTRAINT existingSourcesId
FOREIGN KEY (sourcesId)
REFERENCES sources (id)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TAB