Monday, March 26, 2012

Relational databases

I have a membership database and a profile database with a userid column in both. The foreign key is in the profile database where i want a persons profile details to go like location,occupation and what not. How do I make it so when a new user registers a userId is created in the profile database that matched the userid in the membership database so i can query out profile details based on a registered members userid?

There's a couple of ways -

- Add a separate column for the membership id to the profile.

- Make the UserID in the Profile non-auto generated and set it when you create the record as under

INSERT INTO MembershipTable .....DECLARE @.UserID INTSET @.UserID = SCOPE_IDENTITY() -- gets the identity of the lastnew record-- create the profile recordINSERT INTO ProfileTable (UserId, .... VALUES(@.UserID, ....

No comments:

Post a Comment