Hello. Been trying to insert into FK field with no luck.
I created two tables with a script and loaded them:
Code:
use database;
CREATE TABLE coca_cola_customers (
customer_id INT unsigned NOT NULL AUTO_INCREMENT,
customer_name char(30) NOT NULL,
contact_name char(30) NOT NULL,
PRIMARY KEY (customer_id)
) ENGINE = INNODB;
CREATE TABLE coca_cola_orders (
order_id INT unsigned NOT NULL AUTO_INCREMENT,
order_date char(10) NOT NULL,
customer_id INT unsigned NOT NULL,
PRIMARY KEY (order_id),
INDEX (customer_id),
FOREIGN KEY (customer_id) REFERENCES coca_cola_customers (customer_id) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE = INNODB;
I then inserted some random info in my coca_cola_customers table
Here is exactly what I inserted:
Code:
INSERT INTO coca_cola_customers VALUES (NULL,'McDonalds','Ray Fisher','(555)123-4567');
INSERT INTO coca_cola_customers VALUES (NULL,"Domino's Pizza",'Jason Smith','(555)987-4567');
INSERT INTO coca_cola_customers VALUES (NULL,"Mountain Fitness",'Steve Kemp','(555)984-1234')
And that worked nicely for the coca_cola_customers table
Now I want to add information to the coca_cola_orders table
When I try to run a simple INSERT INTO command:
INSERT INTO coca_cola_orders VALUES (NULL,'06/11/2012','
I GET STUCK RIGHT HERE);
Its probably a lot more complicated than I expect but thats ok. I just want to understand what I need to do in order to get my customer_id from coca_cola_customers to join in customer_id to coca_cola_orders.
I know about joining and have outer joins as well and have created tables and experimented with them successfully but this looks like something different.
I am using mysql straight from the command line for all this
Would appreciate any help.
Thanks,
Shawn