Am trying to insert data into a column but the 2 methods I've tried haven't worked. Here
Question:
Am trying to insert data into a column but the 2 methods I've tried haven't worked.
Here are the tables:
Create Table Customer ( Customer_id int NOT NULL AUTO_INCREMENT, FirstName VARCHAR(50), LastName VARCHAR(50), MailingAddress Varchar(50), ShippingAddress VARCHAR(50), PhoneNumber Varchar (50), CreditCardLimit VARCHAR(50), DiscountPossible boolean, DiscountAmount int, CONSTRAINT Customer_id_PK PRIMARY KEY (Customer_id) );
Create Table Invoice ( Invoice_id int NOT NULL, Price VARCHAR(50), Customer_id int NOT NULL, CONSTRAINT Invoice_id_PK PRIMARY KEY (Invoice_id), CONSTRAINT Customer_id_FK FOREIGN KEY (Customer_id) REFERENCES Customer(Customer_id) );
Using this command I create new Customer entities and give them basic attributes:
INSERT INTO Customer (FirstName, LastName) VALUES ('John','Smith'); INSERT INTO Customer (FirstName, LastName) VALUES ('Jane','Doe');
Am trying to attach a customer_id and Price to an invoice id entity.
The first method i tried gave both my customer entities Invoice_id 1 and 2 (image one and two). Here's how i wrote the query:
INSERT INTO Invoice (Customer_id, Price, Invoice_id) Values (1, 190, 1); INSERT INTO Invoice (Customer_id, Price, Invoice_id) Values (2, 80, 2);
Data Modeling and Database Design
ISBN: 978-1285085258
2nd edition
Authors: Narayan S. Umanath, Richard W. Scammel