Hi akhter,
When inserting the null to foreign key column you need to declar the column as NULL.
Check the below query.
CREATE TABLE Customer
(
CustomerID INT IDENTITY PRIMARY KEY,
CustomerName VARCHAR(100)
)
GO
CREATE TABLE Sale
(
SaleID INT IDENTITY PRIMARY KEY,
CustomerID INT NULL FOREIGN KEY REFERENCES Customer (CustomerID)
)
GO
INSERT INTO Customer VALUES ('John Hammond')
INSERT INTO Customer VALUES ('Mudassar Khan')
INSERT INTO Sale VALUES (1)
INSERT INTO Sale VALUES (NULL)
INSERT INTO Sale VALUES (2)
INSERT INTO Sale VALUES (NULL)
SELECT * FROM Customer
SELECT * FROM Sale
Output