I want to make a small ticket-system for a project server which has several projects. So far the TicketID will be counted globally, i.e. there is a project A and a ticket with TicketID 1 and another project B and the ticket for this project will get TicketID 2 - like this:
(TicketID, ProjectID)
(1, 1)
(2, 1)
(3, 1)
(4, 2)
(5, 2)
(6, 3)
But I think it would be better to count the TicketID depending on the ProjectID such as:
(TicketID, ProjectID)
(1, 1)
(2, 1)
(3, 1)
(1, 2)
(2, 2)
(1, 3)
Here the table:
CREATE TABLE IF NOT EXISTS tickets (
TicketID INT UNSIGNED NOT NULL AUTO_INCREMENT,
ProjectID INT UNSIGNED NOT NULL,
...
PRIMARY KEY (TicketID, ProjectID) ,
FOREIGN KEY (ProjectID) REFERENCES projects (ProjectId),
...
);
Is it possible to make the TicketID with auto_increment depending on the ProjectID with SQL? Or is there no way with SQL and I have to set the IDs with my PHP-code manually?