Storing Multi Choice Field into in SQL Server 2008
-
22-09-2019 - |
Question
I'm writing an app in .NET, and using a dropdown checkbox.
I'm not sure what the best practice is for storing this info in the db.
Currently I'm writing back a comma delimited string to an SP in SQL Server 2008 ie "apple, banana, pear", storing this in a nvarchar(MAX) and then splitting this in the SP into another table holding the ID and the Type ie
ID Type
17 apple
17 banana
17 pear
Is this overkill, or the correct approach?
Solution
The important thing is to keep the database normalized. You're doing exactly that, so I'd say your approach is fine.
Passing a comma-separated string to a stored procedure is okay too. You could refine it with tables parameters or multiple procedure calls, but those have a significant overhead in development time and performance.