![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
CREATE TABLE IF NOT EXISTS `test`.`orders` ( `Order_ID` INT NOT NULL , `Customer_ID` INT NULL , `Order_Date` DATE NULL , `Amount` DOUBLE NULL , PRIMARY KEY (`Order_ID`) , INDEX `ID` () , |
|
CONSTRAINT `ID` FOREIGN KEY () |
|
REFERENCES `test`.`customer` () ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; |
#3
| |||
| |||
|
|
This is my example scenario. I want to insert into this database. My record comes across having both the customer info and the order info, one record at a time. My question is: Given that: There is are 0 to n orders for a customer. A customer record can not be deleted until all their orders are deleted. Do I insert the customer data into the customer table first... I assume it is alright for that to fail as the customer is unique and might be being added for the second time. I assume the primary key be created for me by the auto increment |
|
Have I got the Foreign Key setup properly? It should point to customer.ID What does the insert statement look like for this record? |
|
ENGINE=InnoDB; I guess this is what MySQL prefers. I don't know if I've handled Index files correctly... I hope this question is phrased better this time... Here is the table creation sql... .... |
#4
| ||||||||
| ||||||||
|
|
This is my example scenario. I want to insert into this database. My record comes across having both the customer info and the order info, one record at a time. My question is: Given that: There is are 0 to n orders for a customer. A customer record can not be deleted until all their orders are deleted. |
|
Do I insert the customer data into the customer table first... I assume it is alright for that to fail as the customer is unique and might be being added for the second time. |
|
I assume the primary key be created for me by the auto increment |
|
Have I got the Foreign Key setup properly? It should point to customer.ID |
|
What does the insert statement look like for this record? |
|
ENGINE=InnoDB; I guess this is what MySQL prefers. I don't know if I've handled Index files correctly... |
|
I hope this question is phrased better this time... Here is the table creation sql... CREATE SCHEMA MyTest; USE MyTest; CREATE TABLE IF NOT EXISTS `test`.`customer` ( `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT , `Cust_Name` VARCHAR(32) NOT NULL , PRIMARY KEY (`ID`) , UNIQUE INDEX `cust_id_UNIQUE` (`ID` ASC) ) ENGINE = InnoDB; |
|
-- ----------------------------------------------------- -- Table `test`.`orders` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `test`.`orders` ( `Order_ID` INT NOT NULL , `Customer_ID` INT NULL , `Order_Date` DATE NULL , `Amount` DOUBLE NULL , PRIMARY KEY (`Order_ID`) , INDEX `ID` () , CONSTRAINT `ID` FOREIGN KEY () REFERENCES `test`.`customer` () ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Most excellent post Jerry... Thank you very much.. You too luuk... I was curious about the insert statement and it's syntax... is there a notion of an insert crossing tables? or must each insert be restricted to one table? |
#7
| |||
| |||
|
|
Most excellent post Jerry... Thank you very much.. You too luuk... I was curious about the insert statement and it's syntax... is there a notion of an insert crossing tables? or must each insert be restricted to one table? |
#8
| |||
| |||
|
|
On 1/27/2011 3:01 PM, SpreadTooThin wrote: is there a notion of an insert crossing tables? or must each insert be restricted to one table? You will have two INSERT statements - one for the customer and one for the order. |
#9
| |||
| |||
|
|
I was curious about the insert statement and it's syntax... |
|
is there a notion of an insert crossing tables? or must each insert be restricted to one table? |
![]() |
| Thread Tools | |
| Display Modes | |
| |