Re: SQL Subquery on Max(date)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Sun, 22 Apr 2007 16:00:08 +0200, Bob Hairgrove <invalid@xxxxxxxxxxx> wrote:

CREATE TABLE oncd_activity_company (
company_id LONG NOT NULL,
activity_id LONG NOT NULL,
due_date DATETIME NOT NULL,
CONSTRAINT pk_oncd_activity_company
PRIMARY KEY (company_id, activity_id),
CONSTRAINT fk_company
FOREIGN KEY (company_id)
REFERENCES oncd_company (company_id),
CONSTRAINT fk_activity
FOREIGN KEY (activity_id)
REFERENCES oncd_activity (activity_id)
);

Actually, all three columns should go into the composite primary key here:
...
CONSTRAINT pk_oncd_activity_company
PRIMARY KEY (company_id, activity_id, due_date),
...
etc. Otherwise, it doesn't make sense to do the GROUP BY on company_id and
activity_id.

--
Bob Hairgrove
NoSpamPlease@xxxxxxxx
.



Relevant Pages

  • Re: Foreign key problem
    ... primary key of the parent table columninfo. ... denormalisation, because the table_name is not redundant: ... One can therefore forget that a foreign key is nothing more than a ... In TTM's Algebra I imagine the constraint might be something like: ...
    (comp.databases.theory)
  • RE: Search results
    ... procedure and receive the error message about the update statement ... Due to the FK constraint, each row of Sample has to link to the Parent ... Although the main purpose of a FOREIGN KEY constraint is to control the ... to data in the primary key table. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Updating from PointBase to Derby
    ... CONSTRAINT pk_location PRIMARY KEY, description varchar)"); ... varchar, skill varchar, CONSTRAINT fk_applicant FOREIGN KEY ... REFERENCES Applicant, CONSTRAINT fk_skill FOREIGN ...
    (comp.lang.java.help)
  • Re: Create Table Issues
    ... unique index on BookID. ... > CONSTRAINT PubPK PRIMARY KEY ... > CONSTRAINT PubFK FOREIGN KEY REFERENCES Publisher ...
    (microsoft.public.access.gettingstarted)
  • Re: unknown symbol in ER diagram
    ... main_ID INTEGER NOT NULL PRIMARY KEY ... CONSTRAINT fk__sub1 FOREIGN KEY ... REFERENCES Main ... ALTER TABLE Sub1 ADD CONSTRAINT ch__sub1 ...
    (microsoft.public.access.tablesdbdesign)