| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |
|

11-05-08, 15:21
|
|
Registered User
|
|
Join Date: Oct 2008
Posts: 23
|
|
|
Does this violate anything?
|
|
junction table
------------
car.....color
1........1
1........2
1........3
2........1
3........2
3........1
if one car can be as much as 3 colors does the above junction/composite table violate anything is it the right way to approach it?
|
Last edited by Datanalysis; 11-05-08 at 15:24.
|

11-05-08, 16:17
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
|
|
All kosher, but if you are LIMITING cars to a maximum of three colors, you will need additional constraints.
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|

11-05-08, 16:50
|
|
Registered User
|
|
Join Date: Oct 2008
Posts: 23
|
|
|
|
alrighty thanks, I might need to research these constraints up.
|
|

11-05-08, 23:33
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
create table junction
( car integer
, colour integer
, seq tinyint
, check ( seq in (1,2,3) )
);
not sure what the PK would be, though... blindman?
|
|

11-06-08, 02:06
|
|
Registered User
|
|
Join Date: Dec 2007
Location: London, UK
Posts: 732
|
|
Quote:
|
Originally Posted by r937
create table junction
( car integer
, colour integer
, seq tinyint
, check ( seq in (1,2,3) )
);
|
Why make every column nullable?
At least you'll need a uniqueness constraint on (car,seq) otherwise it would still be possible to have more than three colours per car. It also seems sensible not to allow the same colour to appear twice per car. I'd expect referential constraints too:
CREATE TABLE CarColours
( car INTEGER NOT NULL REFERENCES Cars (car)
, colour INTEGER NOT NULL REFERENCES Colours (colour)
, seq TINYINT NOT NULL
, CHECK ( seq IN (1,2,3) )
, UNIQUE (car, seq)
, PRIMARY KEY (car, colour)
);
I'm not a fan of primary keys and I'm not stating an opinion about which key is the "primary" one or even whether it matters at all. Not to be too controversial though, I've included a PRIMARY KEY constraint anyway.
|
|

11-06-08, 03:34
|
|
www.gvee.co.uk
|
|
Join Date: Jan 2007
Location: UK
Posts: 10,156
|
|
You're not a fan of primary keys?
I think you should go stand in the corner and think about what you just said for a moment.
|
|

11-06-08, 04:07
|
|
King of Understatement
|
|
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
|
|
Lol! I think dportas might actually have some interesting points to make on this. I suspect his thinking is with regard to relational purity and (IIRC) Codd shoe horning PKs in as a late revision. There are a few that don't like the concept of PKs, saying they are just a hang over from, and concession to, technical standards that predate Codd's work.
I very much doubt he is bemoaning constraints enforcing uniqueness.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
|
|
|

11-06-08, 06:20
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
Seems a very small number of colour options for a car or has the US gone back to Henry Ford's original colour schemes for the model T? I know my old VW beetle comes in 17 colours for 1972 alone - my one is currently blue.
Quote:
, seq tinyint
, check ( seq in (1,2,3) )
|
Comment removed due to my misunderstanding.
|
Last edited by mike_bike_kite; 11-06-08 at 06:53.
|

11-06-08, 06:36
|
|
King of Understatement
|
|
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
|
|
Mike - the requirement is 3 colour combinations per car.
EDIT - more accurately, a combination of three colours per car....
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
|
|
Last edited by pootle flump; 11-06-08 at 06:43.
|

11-06-08, 06:45
|
|
www.gvee.co.uk
|
|
Join Date: Jan 2007
Location: UK
Posts: 10,156
|
|
To clarify; 3 colours per car, not per model... right?
|
|

11-06-08, 06:50
|
|
King of Understatement
|
|
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
|
|
Further clarification as I understand it:
Each physical instance of a car (i.e. a tangible object that can be used to transport people and other matter from one place on earth to another, and not a theoretical construct such as a "model") can be coloured by up to three colours from a domain of available colours. I imagine each car must have at minimum one colour, otherwise it would be a magic car, but this has not been stipulated as part of the requirement.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
|
|
|

11-06-08, 06:56
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
Quote:
|
Originally Posted by pootle flump
I imagine each car must have at minimum one colour, otherwise it would be a magic car
|
The DeLorean didn't have colours - it was just sheet steel - or does that count as a colour.
|
|

11-06-08, 07:01
|
|
www.gvee.co.uk
|
|
Join Date: Jan 2007
Location: UK
Posts: 10,156
|
|
Magic?
Or transparent!
So we're talking about: car registration "UB3R FLMP" comes in yellow, red and blue. Yellow body, red dash and blue upholstery.
In which case, is the colour not an attribute of the car part rather than the car itself?
|
|

11-06-08, 07:36
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
|
Originally Posted by dportas
Why make every column nullable?
|
wanted to illustrate only the CHECK constraint in the seq column
to include the FKs, and do a thorough job of it, would require that i ensure that the columns that the FKs reference also existed properly, which would mean i'd have to give the DDL for the cars and colours tables, too, and i couldn't be ***ed this time

|
|

11-06-08, 09:52
|
|
World Class Flame Warrior
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
|
|
I wouldn't enforce this using a Sequence column.
I'd enforce it using an indexed view, though that is an MSSQL specific solution.
__________________
If it's not practically useful, then it's practically useless.
blindman
www.chess.com: "sqlblindman"
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|