I'm very green in the area of SQL, so I don't know what the idea or type is really called but I will call em "Transfer tables" and I will try to explain what I mean and my problem. Please correct me!
Description
3 tables.
Contacts: ID(primary key), Firstname, Lastname, SSN etc
Address: ID(primary key), City, Street etc
ContactsTransferAddress (short: CTA): ID(primary key), ContactID(foreign key), AddressID(foreign key)
The problem
Now this is just an exercise... For now I've made a stored procedure that:
ALTER PROCEDURE [dbo].[AddAddress]
@Street varchar(MAX),
@City varchar(MAX),
@CID int, --ContactID
@AID int OUTPUT --AddressID
AS
BEGIN
INSERT INTO Addressess(Street,City) VALUES (@Street, @City)
SET @AID = SCOPE_IDENTITY()
INSERT INTO CTA(CID,AID) VALUES (@CID, @AID)
END
Is there a way to make 2 people share the same AddressID(AID) when putting the connection data in the CTA? Right now, I get that my SP above will give different IDs for each address. But I don't know how to have unique addresses.
Thanks!