Search code examples
sqlsql-server-2008aspnetdb

Associate users and roles added to ASPNET SQL Database tables with existing user information


I have added a series of ASPNET database tables for roles, user and membership management to my existing SQL database using aspnet_regsql.exe.

There is already a user table in the existing database which contains information (ID, Name, Address, Postcode, etc) for a number of users. What I want to achieve to associate the new aspnet_Users table with the existing user table.

Is there any option or options for recommendation please? Thanks

Cheers, Alex


Solution

  • The UserKey, called UserId in the ASPnet membership tables, is the GUID which identifies a user. You can add a UserKey column to your Users table and then start doing dangerous things like:

    select *
      from Users as U inner join
        aspnet_Users as aU on aU.UserId = U.UserKey inner join
        aspnet_Membership as aM on aM.UserId = aU.UserId
      where U.UserId = @UserId
    

    No warranty, expressed or implied, is provided by Microsoft (or me) if you want to fiddle about directly in their tables.