Woland
Woland

Reputation: 1070

SQL Server dilemma, performance

I am creating app where user can save options

witch one is better?

  1. to save into user table varchar feeld smthing like ('1,23,4354,34,3') query for this is select * from data where CHARINDEX ( 'L', Providers , 0 ) > 0

  2. create other table where user options are and just add rows select * from data where Providers in (select Providers from userdata where userid=100)

thanks for help

Upvotes: 0

Views: 69

Answers (1)

marc_s
marc_s

Reputation: 754258

If ever possible, try to avoid putting stuff into comma-delimited strings and then force SQL Server to have to parse all those entries again.

So in your case, I'd definitely go with option two - use a separate table, and let your user's options be persisted into that table as individual rows. That's the much cleaner and much more SQL Server-like solution, and if you handle it properly, it will also perform much better (since retrieving data from tables it SQL Server's core job and competency - parsing strings is not).

Upvotes: 2

Related Questions