The INSERT statement conflicted with the FOREIGN KEY constraint "fk3".

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Why in sql given me this error, when i try to fill the table 

The INSERT statement conflicted with the FOREIGN KEY constraint "fk3".

This is my code : 

1. CREATE TABLE employees(
id int identity not null primary key,
EmpFirstName nvarchar(30) not null,
EmpLastName nvarchar(30) not null,
);

2. CREATE TABLE products(
id int identity not null primary key,
ProductName nvarchar(50) not null,
ProductPrice float not null,
SupplierID int not null,
);

3. CREATE TABLE orders(
EmployeeId int not null,
ProductId int not null,
OrderDate date not null,
Quantity int not null,
PRIMARY KEY (EmployeeId,ProductId,OrderDate),
FOREIGN KEY (ProductId )REFERENCES products(id)
);
4. CREATE TABLE suppliers(
id int identity not null primary key,
CompanyName nvarchar(60) not null,
CompanyAddress nvarchar(255) not null,
CompanyPhone bigint not null,
);

5.
ALTER TABLE orders
ADD CONSTRAINT fk1
FOREIGN KEY (EmployeeId)
REFERENCES employees(id)

7.
ALTER TABLE products
ADD CONSTRAINT fk3
FOREIGN KEY (SupplierID)
REFERENCES suppliers(id)

ex.2 
1. ALTER TABLE employees ADD EmployeeAddress nvarchar(255)

ex.3
INSERT INTO employees(EmpFirstName,EmpLastName,EmployeeAddress)
VALUES ('Иван','Иванов','Хаджи Димитър 25'),
('Милена','Димитрова','Панайот Хитов 3'),
('Миглена','Панайотова', 'Васил Априлов' ),
('Васил','Трайков','Иван Вазов бл 4'),
('Димитринка', 'Станчева','Стефан Стамболов');

--------------------------------------------------------------------
INSERT INTO orders (EmployeeId,ProductId,OrderDate,Quantity)
VALUES (5353,63533,'09-08-2021',8);
-----------------------------------------------------------------
INSERT INTO products (ProductName,ProductPrice,SupplierID)
VALUES ('apple', 1.50, 7473),
('milk', 1.30, 4252),
('biscuits', 2.20, 5352),
('bread', 1.20, 5425),
('cheese', 2.50, 45728);

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY