1

I'm building a simple database in MySQLWorkbench with two tables: Study (1) and Series (2). In the future, we will import data from a CSV file into these tables.

Study should generate a new UUID as PRIMARY KEY (PK) named ID for every new row. Subsequently, Series should generate a new UUID as PK named ID for every new row.

Lastly, Series should generate a Foreign Key (FK) StudyID, with the same UUID's as the Study table column ID, so that these two tables can be joined on UUID for the ascending rows.

I found topics on stack with a somewhat similar question, but this didn't solve my problem: How to insert the same UUID in two rows of two different tables

Best practices on primary key, auto-increment, and UUID in RDBMs and SQL databases

Could anyone give me a push in the right direction?

My code:

CREATE SCHEMA IF NOT EXISTS `analog_db` DEFAULT CHARACTER SET utf8 ;
USE `analog_db` ;

 
CREATE TABLE Study (`ID` VARCHAR(36) DEFAULT (UUID()),
                    `Number` VARCHAR(36) NOT NULL,
                    PRIMARY KEY (`ID`) );


CREATE TABLE Series (`ID` VARCHAR(36) DEFAULT (UUID()),
                     `Number` VARCHAR(36) NOT NULL, 
                     `StudyID` VARCHAR(36) DEFAULT (UUID()), 
                     PRIMARY KEY (`ID`),
                     KEY `FK_StudyID` (`StudyID`),  
                     CONSTRAINT `FK_StudyID` FOREIGN KEY (`StudyID`) REFERENCES `Study` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION );


             
                 
Jeromekem
  • 85
  • 9

0 Answers0