I want to improve the performance of my SQL select query. I am using SQL Server 2008 R2.
I have a table Orders which has around 1.5 lacs of rows.
I have written a simple
select * from Orders
query which is taking around 8 seconds. Due to this the UI component is getting displayed in around 10-11 seconds.
Can anybody tell what could be issue? Is it due to no index is created on the table? If yes how we can improve the performance?
after edit---
I have posted query the above..which is a simple "select * from Orders".Orders is the table name.in which orderId is the primary key.i guess the DB will create a index for the primary key.I have also mentioned that there are not indexes created on any column in the table.the table as total 0.15 million records.i am running the query in the sql server management studio.even to my surprise the query is taking 8 seconds to show the results.
Thanks,
Hanmayya
I am not familiar with what unit "lacs" is, but you could look at the following to try to improve performance.
Try selecting only the fields that you need.
Remove any kind of formatting from the control. A friend of mine was encountering some issue with a Telerik grid when he was trying some non-standard configuration.
See if there is a problem with the server (is cpu/ram maxing out?)
Is there a problem with the network?
Do other servers have the same issue? You could compare configurations to see what the difference is.
Is the table fragmented? Not sure how much this would affect select performance though.
If you are not using any joins I do not think that putting an index would improve anything.
Just to update on the answer, I have implemented row index to fetch the data based on no of records to be displayed on page and the start index.
Related
In my SQL Server 2008r2 database I have a Table with over 25000 records in it. when I search for the record i need to edit, it returned 6 possible, but it wont let me edit. I can just open the table and go through all 25000 records, which is painful. I would like to be able to search for the right records, then be able to edit those records.
The best option is to write an UPDATE. I could give you an example on how to do it, but since you didn't post any code, I can only give you the examples on the documentation.
Review the documentation on UPDATE.
If you're using SSMS, this may be helpful: How to quickly edit values in table in SQL Server Management Studio?
If you aren't using SSMS, knowing what UI you're using would be helpful.
I want to use merge statement in SSIS. I have one source (Oracle) and one destination (SQL Server). Both the tables and structure are same.
I need to insert, update and delete the data based on some date criteria. My question is should I use Merge Join or Lookup Table as I have more than 40 million records in Oracle.
If need more clarification let me know. I will provide you with more info. I am not good in posting though so forgive me.
Personally i would transfer the oracle table to SQL Server and perform any operations locally. I use this approach almost always (nothing quite to the size of your data) but its also useful when dealing with cloud based databases (latency, etc). Its worth noting that if you don't have a datetime column in your source you can use the ORA_ROWSCN pseudo column which gives you a crude change set to load locally.
I have read lots of tales about Merge join not performing accurate joins - i would expect with data of your size it could be an issue.
Lookup could be an issue also due to the size as it has to cache everything (this would attempt to load all oracle records into SSIS anyway so better to transfer it locally).
Hope this helps :)
I am having some troubles with intellisense in SQL Server 2008 R2.
Intellisense for all tables works fine, but the column intellisense only seems to work for some tables.
For example, this query pulls up a list of all the functions and navigates to the items starting with "sta":
select *
from tbl_cash_stats
where sta
This query doesn't pull up anything after the where clause regardless of if I type any characters or not
select *
from tbl_assignment
where
Furthermore, if I join a table that is working properly with one that is not, no column-level intellisense works:
select *
from tbl_cash_stats
join tbl_assignment
on
I have refreshed local cache several times with no success. There appears to be no specific reason why certain tables work perfectly and others do not, and only about 15% of the tables are affected.
Does anyone have an idea of how to fix this? It has become extremely annoying because it is affecting some of the tables I use most often.
EDIT: After looking into the tables that were affected more closely, it appears that it is only tables with an identity column that do not work with intellisense, but I still cannot figure out why.
Out of sheer luck I stumbled on the answer to this question.
On Friday, I installed Visual Studio 2010 SP1. After the install, I noticed that intellisense for SQL server stopped working completely. Apparently, this is a known issue and can be fixed by installing Cumulative Update 9
Much to my suprise, this update also resolved the issue of intellisense not working on tables that had identity columns.
I hope this saves others from having to deal with this rather obscure issue in the future.
One thing I want to do is build a personal database for myself at home to use a financial database (transaction log, checking/savings account tables, etc), and I want to do this mainly to learn more about developing databases. I am pretty familiar with MS Access, though not put to use in this context, but what I am really trying to learn is SQL Server.
SO, that being said, the first question that popped into my mind is that if I have a transactions table that I would want to use as a ledger, then is there some method to have the table automatically perform a calculation for one field (balance) based on another field(s) (expense, revenue fields)? Similar to what someone may do with Excel......
Or is this something I would have to do with an unbound form, and an UPDATE statement kinda of approach? If a table constraint exists for this type of idea, I would like to learn it....
I mentioned MS Access in the title, but a SQL Server is also most appreciated. Thanks for the help!
Derived data should not be stored except if it needs to be indexed -- you calculate the values in your SQL statements, or in the presentation layer.
In addition to computed columns in SQL Server tables, you can have them in VIEWS and you can index them. The term is "indexed view" and when you do that, the data is persisted in a hidden temp table and updated on the fly when the data the VIEW is derived from is changed. You can read about it under the TYPES OF VIEWS topic in the same link cited in #Roland Bouman's answer.
Last of all, it's not clear to me why you mention Access at all if you're using SQL Server as your back end. Are you developing your front end in Access?
In MS SQL server, you can use computed columns for this: http://msdn.microsoft.com/en-us/library/ms191250.aspx
Does anyone have experience of when SQL Server 2008 R2 is able to automatically match indexed view (also known as materialized views) that contain joins to a query?
For example the view
select dbo.Orders.Date, dbo.OrderDetails.ProductID
from dbo.OrderDetails
join dbo.Orders on dbo.OrderDetails.OrderID = dbo.Orders.ID
Cannot automatically be matched to the same exact query. When I select directly from this view with (noexpand) I actually get a much faster query plan that does a scan on the clustered index of the indexed view. Can I get SQL Server to do this matching automatically? I have quite a few queries and views and I do not want to reference the indexed view manually each time because I am using an OR mapper.
I am on enterprise edition of SQL Server 2008 R2.
Edit: I found the solution. SQL Server 2008 R2 does not match indexed views with more than 2 joins automatically. Probably it would slow down the optimization process too much.
Edit 2: Reviewing this 2 years after the question was created by me, I don't think my conclusion was correct. Materialized view matching is a very fragile process with no clear rules that I could find over the years.
Certainly, the following play a role:
Number of joins
Presence of a predicate
Join order, both in the view and in the query
I'm a little fuzzy on exactly what your question is; but I think this will give you what you want:
http://msdn.microsoft.com/en-us/library/ms181151.aspx
There are a lot of strange, arbitrary-seeming conditions that limit when SQL Server will use a view index in a query. This page documents them for SQL Server 2008.