![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have found a problem that I can't seem to solve in what I consider a nice way. Basicly I have a table called Jobs. Each Job has some details in its table, it also has a type. These are A, B, C, D, E and F. If it is of type A then it needs an additional 10 columns, B 13, C 30 and so on. These additional piecies of information are totally unrelated to those in a different letter. How do I represent this? My first thought was to have a Jobs table which has a foreign key pointing to a Type table, which lists the types, and then a column which has a foreign key to either Table A, Table B, Table C etc. This would them mean that there was a foreign key that pointed to different tables depending on what another column's data said. Is that even slightly valid relational database thinking? If not what is a better solution? All I could really think of was having an A_key column, a B_key column etc, but then there would be loads of null data. Cheers, Chris |
#3
| |||
| |||
|
|
Hi, I have found a problem that I can't seem to solve in what I consider a nice way. Basicly I have a table called Jobs. Each Job has some details in its table, it also has a type. These are A, B, C, D, E and F. If it is of type A then it needs an additional 10 columns, B 13, C 30 and so on. These additional piecies of information are totally unrelated to those in a different letter. How do I represent this? My first thought was to have a Jobs table which has a foreign key pointing to a Type table, which lists the types, and then a column which has a foreign key to either Table A, Table B, Table C etc. This would them mean that there was a foreign key that pointed to different tables depending on what another column's data said. |
|
Is that even slightly valid relational database thinking? If not what is a better solution? All I could really think of was having an A_key column, a B_key column etc, but then there would be loads of null data. |
#4
| |||
| |||
|
|
Basicly I have a table called Jobs. Each Job has some details in its table, it also has a type. These are A, B, C, D, E and F. If it is of type A then it needs an additional 10 columns, B 13, C 30 and so on. These additional piecies of information are totally unrelated to those in a different letter. How do I represent this? My first thought was to have a Jobs table which has a foreign key pointing to a Type table, which lists the types, and then a column which has a foreign key to either Table A, Table B, Table C etc. This would them mean that there was a foreign key that pointed to different tables depending on what another column's data said. |
#5
| |||
| |||
|
|
Chris <chris (AT) cjetech (DOT) co.uk> writes Basicly I have a table called Jobs. Each Job has some details in its table, it also has a type. These are A, B, C, D, E and F. If it is of type A then it needs an additional 10 columns, B 13, C 30 and so on. These additional piecies of information are totally unrelated to those in a different letter. How do I represent this? |
#6
| |||
| |||
|
|
Each Job has some details in its table, it also has a type. These |
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
|
Yep, we need a priamry key in each of the job tables to prevent duplicates. CREATE TABLE A_jobs (job_ticket INTEGER NOT NULL PRIMARY KEY REFERENCES Tickets(job_ticket), job_type CHAR(1) DEFAULT 'A' NOT NULL CHECK(job_type = 'A'), FOREIGN KEY(job_ticket, job_type) REFERENCES Tickets (job_ticket, job_type) ON DELETE CASCADE ON UPDATE CASCADE, ...); But I do need the FOREIGN KEY (job_ticket, job_type) to make that the job_ticket bellongs to one and only one job_type. |
![]() |
| Thread Tools | |
| Display Modes | |
| |