Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Primary key and foreign key relationship.

$
0
0
I have TABLES products1 and products2CREATE TABLE products1( product_id INT PRIMARY KEY, product_name VARCHAR(50) NOT NULL, category VARCHAR(25));CREATE TABLE products2( product_id INT , product_name VARCHAR(50) NOT NULL, category VARCHAR(25) PRIMARY KEY);ALTER TABLE products1ADD CONSTRAINT fk_nameFOREIGN KEY(category)REFERENCES products2(category) ALTER TABLE products2ADD CONSTRAINT fk_name_2FOREIGN KEY(product_id)REFERENCES products1(product_id) Then i tried to insert a record into table product1, i got the foreign key conflict error which was expected.INSERT INTO products1 VALUES(1,'SSS','FMCG') The Problem here is parent table is also acting like a child table. is there anyway to insert a record , for this kind of scenario ?

Viewing all articles
Browse latest Browse all 3145

Trending Articles