I am developing a MVC project with sql server. in which each user will be given a username after registration. Registration is done using various data like address and email number and phone number. I am using a table to store address and its id is stored in users table. Now as people can have change address so I'm not able to understand it how to manage it. I want to keep the old address as well as new for new users. Can anybody help?
相关问题
- sql execution latency when assign to a variable
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
相关文章
- Entity Framework 4.3.1 failing to create (/open) a
- Why do I need a ToList() to avoid disposed context
- Code for inserting data into SQL Server database u
- Delete Every Alternate Row in SQL
- Cannot implicitly convert Web.Http.Results.JsonRes
- Linux based PHP install connecting to MsSQL Server
- SQL Azure Reset autoincrement
- How do we alias a Sql Server instance name used in
You have some options:
In address table, add userid column. In user table, add addressid column.
User table will tell you the current address user has indicated.
Address table will tell you ALL the addresses user has used.
The advantage is that user table points you to the recent address table. When user adds new address, address table gets an insert and user table is updated. The disadvantage is repetition of userid in address table - if parents and children have the same address (assuming each individual is a user), you'd be adding the same address multiple times for each user. To get current address, you will have to ask both user and address tables.
In address table, add userid column and isPrimary bit column. In user table do NOT add addressid column
User table will not tell you anything about address, but address table will tell you all the addresses the user has used and which one is their primary.
You can get current address for a given user directly from address table.
Address table, just like in the previous example, will tell you ALL the addresses user has used.
The advantage is just that address table is responsible for telling you who that address belongs to and whether it is primary.
Store user in user table, address in address table. Create junction table to bring address and users together
UserAddress table can be created that has userid, addressid, isPrimary columns. User table will only contain user information. Address table will have addresses and to know which address belongs to which user, you'd ask UserAddress table.
The advantage of this is associate an address with multiple people. Parents and 2 children residing in the same household can be associated with the same address. If household moves to another location, you have one additional record in address table and 4 records in junction table. The disadvantage is an extra join.
Choose the use case you feel appropriate for your situation.