If you have a One to Many relationship and for the sake of this qustion it is as below,
Where NameId is the PrimaryKey in the NameTable and BookId is the PrimaryKey in the BookTable.
As a stored procedure I can insert data as follows
PROCEDURE [dbo].[spInsertBooks]
@FirstName varchar(150), @LastName varchar(150), @BookTile varchar(500), @YearPublished varchar(4)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @NameId int
INSERT INTO NameTable (FirstName,LastName) VALUES (@FirstName, @LastName)
SELECT @NameId = Scope_Identity();
INSERT INTO BookTable (NameId, BookTitle, YearPublished) VALUES (@NameId, @BookTile, @YearPublished)
END
However this could result in duplicates in the NameTable.
How would I ensure no duplicates in the Name table but the Book Data is still added along with the appropriate NameId.
Thank you for your assistance