Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using SQL Server to manager my database and I have several tables which have large number of columns about 40 to 50 columns each.
Now I want to get an specific record from the table using ASP.Net. I am using ADO.Net to get data from SQL Server and I know how can I fetch data but I am looking for some optimized approach to fetch data with large number of columns.
Posted
Comments
PIEBALDconsult 1-Aug-15 11:08am    
For 40 or more columns, you could try spraying the pipes with WD40. :D
But seriously, are you having performance issues? Or are you simply being paranoid that you might? Until you actually have isues, there's no reason to seek a solution. Just try it and see how it goes. And follow the advice in the two solutions given so far.

Not sure what problems would you foresee in having 40-50 columns. Depending on the application a table can have hundreds of columns and perform very well.

However as a rule of thumb few things you need to remember:

  • Never fetch all columns using *, name the columns you want to fetch.
  • Fetch only the columns you need.
  • Never do formatting on the database side, let the client application handle that.
  • Whenever possible fetch based on the key.
  • Remember to uniquely index the key, preferably using primary key and unique constraints when needed.
  • Never fetch more rows than needed.
  • If several rows are fetched, consider paging.
 
Share this answer
 
v2
If you are only using a limited number of the columns, then only retrieve the ones you want: i.e. don't use
SQL
SELECT * FROM MyTable WHERE ...
List only the columns you are interested in:
SQL
SELECT Column12, Column35 FROM MyTable WHERE ...

Other than that, tuning your WHERE clause to only return the rows you want is pretty much your only other optimisation!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900