r p

r p

  • NA
  • 343
  • 0

Primary Key created by createuserwizard to use in other tables

Nov 21 2008 4:11 AM
I am developing an e-Commerce site.
I am using username as the foreign key in all my tables.
If I want retrieve all the products entered by a user, then I will
use a query like - "select * from products_table where products_table.username="@current_username"
Now, I noticed a problem - suppose the user wants to CHANGE HIS USERNAME in the future
that will cause a big problem, because my selection from the tables is based on the username.
I use the following code to retrieve the current user name-

      protected static string CurrentUserName
            string userName = "";
            if (HttpContext.Current.User.Identity.IsAuthenticated)
               userName = HttpContext.Current.User.Identity.Name;
            return userName;

Once I get the user name I call - "select * from products_table where products_table.username="@current_username"
So, what should I use as my FOREIGN KEY  in the tables to retrive the productdetails, even if the user wants to
change his user name in the future? Can anyone help me? What is the BEST WAY of doing the table design when I

Answers (2)