The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 305 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I keep getting this ERROR:
Â
The INSERT statement conflicted with the FOREIGN KEY constraint "fk_Customer_Rentals_Customers". The conflict occurred in database, table " Customers", column 'customer_id'.
Â
 What can I do to fix this?
Â
Background Info:
Â
/* Customer_Rentals */
CREATEÂ TABLEÂ Customer_Rentals(
item_rental_id INT IDENTITY(1,1) NOT NULL,
customer_id INT NOT NULL,
movie_id INT NOT NULL,
rental_status_code INT NOT NULL,
rental_date_out DATE NULL,
rental_date_returned DATE NULL,
rental_amount_due MONEY NULL,
other_rental_details varchar(250) NULL);
Â
/* Insert data for table Customer_Rentals*/
INSERT INTO Customer_Rentals VALUES (1, 2, 1, '2012/07/02', NULL, $2.50,'This movie is out');
INSERT INTO Customer_Rentals VALUES (2, 1, 2, NULL, NULL, NULL, 'This movie has been reserved');
Â
Â
/* Customers */
CREATEÂ TABLEÂ Customers(
customer_id INT IDENTITY(1,1) NOT NULL,
member_yn CHAR(3) NOT NULL,
membership_number CHAR(5) NOT NULL,
date_became_member DATE NOT NULL,
customer_first_name VARCHAR(32) NOT NULL,
customer_last_name VARCHAR(32) NOT NULL,
customer_address VARCHAR(128) NOT NULL,
customer_city VARCHAR(32) NOT NULL,
customer_state VARCHAR(2) NOT NULL,
customer_zip VARCHAR(12) NOT NULL,
customer_phone VARCHAR(13) NOT NULL,
customer_email VARCHAR (128) NOT NULL,
customer_dob DATE NOT NULL);
Â
Â
Â
/* Insert data for table Customers */
INSERT INTO Customers VALUES ('100', 'M1001', '2010/01/05', 'John', 'Smith', '1235 Main St.', 'Dunmore', 'PA', '18512','752-242-6548', , '1955/02/01');
INSERT INTO Customers VALUES ('100', 'M1002', '2010/05/05', 'Mary', 'Jones', '235 Ardmore Blvd.', 'Pittsburgh', 'PA','15221', '412-535-8974', , '1955/02/02');
Â
/* create primary keys with ALTER TABLE statement */
ALTER TABLE Customer_Rentals ADD CONSTRAINT pk_Customer_Rentals PRIMARY KEY (item_rental_id);
ALTER TABLE Customers ADD CONSTRAINT pk_Customers PRIMARY KEY (customer_id);
/*Â end of primary key creation */
Â
/* create foreign keys */
ALTER TABLE Customer_Rentals ADD CONSTRAINT fk_Customer_Rentals_Customers FOREIGN KEY(customer_id)
REFERENCES Customers (customer_id);
/* END OF SCRIPT */
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly