Re: Add foreign key

2007-01-09 Thread Mungbeans
And here are the matching drop and create statements: ALTER TABLE `mytable` DROP FOREIGN KEY `fk_mytable_id`; ALTER TABLE `mytable` ADD CONSTRAINT `fk_mytable_id` FOREIGN KEY ( `id` ) REFERENCES `anothertable` ( `id` ) ON UPDATE CASCADE ON DELETE RESTRICT; I don't know what I was doing wro

Re: Add foreign key

2007-01-09 Thread Mungbeans
Just found this added the name: ALTER TABLE `mytable` ADD FOREIGN KEY `fk_mytable_id` ( `id` ) REFERENCES `othertable` ( `id` ); I thought I had tried that - obviously not. -- View this message in context: http://www.nabble.com/Add-foreign-key-tf2950373.html#a8251427 Sent from the MySQL - Ge

Add foreign key

2007-01-09 Thread Mungbeans
Still on the top of foreign keys :) I have this statement: ALTER TABLE `mytable` ADD FOREIGN KEY ( `id` ) REFERENCES `othertable` ( `id` ); Is there a way I can give this key a specific name (eg 'FK_mytable_id') and specific the type of reference (eg 'ON UPDATE CASCADE')? -- View this mess

Re: Syntax error

2007-01-08 Thread Mungbeans
Ah! ORDER BY after GROUP by - now it works: SELECT o.orderid, u.username, o.date, sum( p.price ) FROM order o, users u, order_item oi, product p WHERE o.userid = u.id AND o.orderid = oi.orderid AND oi.productid = p.productid AND o.status = 'new' GROUP BY o.orderid ORDER BY o.date DESC , o.statu

Syntax error

2007-01-08 Thread Mungbeans
Hello again. I am rather (actually very) rusty when it comes to composing SQL these days. Can anyone spot the error here? SELECT o.orderid, u.username, o.date, sum( p.price ) FROM order o, users u, order_item oi, product p WHERE o.userid = u.id AND o.orderid = oi.orderid AND oi.productid = p.

Re: Deleting Foreign Key

2007-01-04 Thread Mungbeans
Chris White-4 wrote: > > Moving along... what I do first is SHOW > CREATE TABLE `table_name`: > ...snipped... > So, first you remove the key: > ALTER TABLE table_name DROP KEY `key_column`; > then the foreign key: > ALTER TABLE table_name DROP FOREIGN KEY `table_name_ibfk_1`; > ...snipped...

Deleting Foreign Key

2007-01-01 Thread Mungbeans
I have a foreign key in a table which I need to drop. I have successfully dropped other foreign keys from this table using phpMyAdmin. However when I use these commands I get similar error messages: ALTER TABLE `mytable` DROP FOREIGN KEY `keyname` #1025 - Error on rename of '.\database\mytab