[rt-devel] primary keys on table

Jesse Vincent jesse at bestpractical.com
Fri Oct 18 15:08:07 EDT 2002



On Fri, Oct 18, 2002 at 03:00:30PM -0400, Vivek Khera wrote:
> I was just looking into why some queries were really slow on my RT,
> and I find that the current schema.Pg lists primary keys for nearly
> every table, but my database (updated from earlier versions) has not
> these primary keys!

I seem to recall that these got added somewhere in the 2.0.x series

> it seems that the insertdata script doesn't add them, either (should
> it?)

I'd be curious to know if this is still the case.
> 
> Then, we can add some referential constraints so that we can trivially
> delete dead tickets with one blow:
> 
> begin;
> delete from Tickets where Status='dead';
> commit;
> 
> and the DB takes care of the rest.
> 
> ALTER TABLE Transactions ADD CONSTRAINT transfk1 FOREIGN KEY (Ticket) REFERENCES Tickets(id) MATCH FULL ON DELETE CASCADE;
> ALTER TABLE Attachments ADD CONSTRAINT attachfk1 FOREIGN KEY (TransactionID) REFERENCES Transactions(id) MATCH FULL ON DELETE CASCADE;
> ALTER TABLE Watchers ADD CONSTRAINT watchfk1 FOREIGN KEY (Value) REFERENCES Tickets(id) MATCH FULL ON DELETE CASCADE;
> ALTER TABLE ObjectKeywords ADD CONSTRAINT objectfk1 FOREIGN KEY (ObjectId) REFERENCES Tickets(id) MATCH FULL ON DELETE CASCADE;

Slick. I can't wait until mysql actually supports this ;)

-- 
»|« http://www.bestpractical.com/rt  -- Trouble Ticketing. Free.



More information about the Rt-devel mailing list