views:

38

answers:

1

I have a simple table with autoincrementing ID's and one text column. id(int), value(nvarchar)

In another User table I have this ID as a foreign key. When i retrieve datat using Linq to Sql, I get the text value of the associated ID in one simple call.

What about when I need to save into the User table when i only have the text and not the id? only the id is stored in the usertable.

am i desinging this incorrectly?

+1  A: 

You might need to explain your schema a little better. From what you have so far, it sounds like you have two tables, a Values table and a User table.

Values table
  id (int)
  value (varchar)

User table
  id (int)
  value_id (int)
  ...

It sounds like you're then getting some information you want to update in the User table for the record or records matching some value from the Values table. If that's correct, you'll want something like:

UPDATE User u
JOIN Values v ON v.id = u.value_id
SET <update field>=<update value>
WHERE v.value = <matching value>
Randy
i ended up doing something like this, but is it good practice to create another table to assign values for 3 text categories?
zsharp
Generally, if you want to be able to represent a one-to-many relationship (e.g., if one user could be associated with 0-3 values), it's better to do that with this two table design than to do something like putting three interchangeable fields value_1, value_2, and value_3 into a table.
Randy