0
CREATE TABLE CASUAL(
   id int AUTO_INCREMENT NOT NULL,
   session_id int,
   FOREIGN KEY(session_id )  REFERENCES SESSION(id),
   PRIMARY KEY(id,session_id )
    )ENGINE=InnoDB;

I want to have:

  • id = 1 session_id=200
  • id = 2 session_id=200
  • id = 3 session_id=200
  • id = 1 session_id=300

ecc..

Now i have:

  • id = 1 session_id=200
  • id = 2 session_id=200
  • id = 3 session_id=200
  • id = 4 session_id=300
devj
  • 362
  • 3
  • 6
  • 2
    Yes, but in that case it will not be an auto increment. You can do it in query, but not in table. – Alex Apr 10 '20 at 16:38
  • With innodb tables you can use trigger (see duplicate question) or insert ... select ... query. However, you really should not be doing this, you just make your life more difficult. It is easier to store simple auto increment and generate the sequence per group on the fly. – Shadow Apr 10 '20 at 16:42

0 Answers0