How To Gather SELECT Statistics?

May 17, 2004

Hi folks

I wonder if anyone has any pointers on how to gather statistics for SELECT queries? For instance, say 10 rows are returned by a query, is it possible to log which rows where returned?

TIA

Jarud

View 3 Replies


ADVERTISEMENT

Performing Statistics In SELECT Statement

May 30, 2008

I have listed below a sql statement generated by a MS Access query. The Access is the frontend, using a SQL Server 2005 View as the backend. I have already corrected the obvious differences between Access and SQL Server syntax, such as replacing UCase$ with UPPER,
replacing '_' with '.' between the db owner and view name, replacing IIF with IF, and replacing "D" with 'D' and "E" with 'E', but it still generates syntax errors (of course, with no explanation). As you can see, it is SUMing a field based on whether the value is 'D' or 'E', then using those calculated values to calculate a percentage. Can anyone out there let me know what I'm doing wrong?

SELECT dbo_vwDisplayUserList.DEPT_DESC, Sum(IIf(UCase$([Essential_Code])="D",1,0)) AS Department_Essential, Sum(IIf(UCase$([Essential_Code])="E",1,0)) AS EOC_Essential, Count(dbo_vwDisplayUserList.UserID) AS Total_Employees, Int([Department_Essential]/[Total_Employees]*100) AS [%Department_Essential], 100-Int([Department_Essential]/[Total_Employees]*100) AS [%EOC_Essential]
FROM dbo_vwDisplayUserList
GROUP BY dbo_vwDisplayUserList.DEPT_DESC
ORDER BY dbo_vwDisplayUserList.DEPT_DESC

View 1 Replies View Related

Wht Statistics Are Updated After SELECT Query?

Jul 31, 2006

Hi

My understanding is that whenever any INSERT, DELETE, or UPDATE statements execute that impacts significant amount of rows in a table, its statistics must be automatically updated by SQL Server. But it was surprise to see in the profiler that after INSERT no update statistics event happen. But the moment a SELECT is executed on the table the event 'Auto Stats' is shown up. What is the reason behind this? Why the Auto Stats not happening immediately after the INSERT statement?

Following code can be used to illustrate this (in the profiler select the Auto Stats event under Performance):

IF(SELECT OBJECT_ID('t1')) IS NOT NULL
DROP TABLE t1
GO
CREATE TABLE t1(c1 INT, c2 INT IDENTITY)
INSERT INTO t1 (c1) VALUES(1)
INSERT INTO t1 (c1) VALUES(2)
INSERT INTO t1 (c1) VALUES(3)
CREATE NONCLUSTERED INDEX i1 ON t1(c1)

GO

--Now add 10,000 rows to update so that statistics are updated. Look into the profiler:

SET NOCOUNT ON
GO

DECLARE @n INT
SET @n = 1
WHILE @n <= 10000
BEGIN
INSERT INTO t1 (c1) VALUES(2)
SET @n = @n + 1
END

SET NOCOUNT OFF
GO


--Next runt he following statement. The profiler will now show 'Auto Stats' event

SELECT * FROM t1 WHERE c1 = 2



Regards

Sanjay Singh

View 3 Replies View Related

Auto Created Statistics And Missing Statistics

Jul 20, 2005

Hello group.I have an issue, which has bothered me for a while now:I'm wondering why the column statistics, which SQL Server wants me tocreate, if I turn off auto-created statistics, are so important to theoptimizer?Example: from Northwind (with auto create stats off), I do the following:SELECT * FROM Customers WHERE Country = 'Sweden'My query plan show a clustered index scan, which is expected - no indexexists for Country. BUT, the query plan also shows, that the optimizer ismissing a statistic on Country, which tells me, that the optimizer wouldbenefit from knowing this.I cannot see why? (and I've been trying for a while now).If I create the missing statistics, nothing happens in the query plan (andwhy should it?). I could understand it, if the optimizer suggested an indexon Country - this would make sense, but if creating the missing index, queryanalyzer creates the statistics with an empty index, which seems to me to beless than usable.I've been thinking long and hard about this, but haven't been able to reacha conclusion :) It has some relevance to my work, because allowing theoptimizer to create missing statistics limits my options for designingindexes (e.g. covering) for some rather wide tables, so I'm thinking why notturn it off altogether. But I would like to know the consequences - hopesomebody has already delved into this, and knows a good explanation.RgdsJesper

View 5 Replies View Related

Unit Of Time-statistics In Client Statistics

Aug 1, 2006

What is the unit of the numbers you get in the Time Statistics-part when running a query in Microsoft SQL Server Management Studio with Client Statistics turned on?

Currently I get mostly 0īs, but if I try and *** up a query on purpose I can get
it up to around 30... Is it milliseconds or som made up number based on clockcycles or... ?

I would also like to know if itīs possible to change the precision.


- Nikolaj

View 3 Replies View Related

Gather Meta Data

Jul 23, 2005

Hi,I would like to prepare a data dictionary for my database (northwind).I have framed the below SQLSELECT'NAME ' = a.name,'DESCRIPTION' = b.value,'Type ' = type_name(a.xusertype),' ' AS 'Values','NULL ' = case when a.isnullable = 0 then ' ' else 'X' end,' ' AS 'PK',' ' AS 'FK'FROMsyscolumns a,sysproperties bWHEREa.id = 2073058421 AND --- Customers Tablea.number = 0 ANDb.id = a.id ANDb.smallid = a.colidORDER BY a.colidand the output would be:NAME DESCRIPTION Type Values NULL PK FK-------------- --------------- ---------- ------ ----- ---- ----CustomerID Customer ID ncharCompanyName Company Name nvarcharContactName Contact Name nvarchar XContactTitle Contact Title nvarchar XAddress Address nvarchar XCity City nvarchar XRegion Region nvarchar XPostalCode Postal Code nvarchar XCountry Country nvarchar XPhone Phone # nvarchar XFax Fax # nvarchar XPK and FK is where I need to print whether the column is Primary Key orForeign Key.If CustomerId is defined as Primary Key then PK should have X printed.Thats the objective.How will I accomplish this ?Thanks in advance,Anu

View 3 Replies View Related

Automate Process To Gather Server Name

Jun 20, 2001

Can anyone direct me to either some code or reading, that talk about gather all my server information. What I want to do is gather all the server Used and Free space size. I'm know a little sql-dmo, and I think I can do it that way, but not sure.

View 1 Replies View Related

Best Way To Gather Large Quantities Of Data

Mar 30, 2008

Hi all,

I have a table which basically stores multiple users' responses to a questionnaire. I want to calculate certain statistics on this data (for example: how many users selected a specific answer to a question). If there are many questions and possible answers, then this can get really inefficient. I was wondering what would be the best way to go about doing this.

Currently, I was thinking of using what I believe are called crosstabs:


Code:

SELECT (SELECT COUNT(*) FROM tableName WHERE Q1answer='value1'), (SELECT COUNT(*) FROM tableName WHERE Q1answer='value2'), (SELECT COUNT(*) FROM tableName WHERE Q2answer='value1'), etc...



Is this the best way to go about this or is this really inefficient?

View 2 Replies View Related

Gather Format And Store - Right Or Wrong

May 4, 2006

The IT group that I work with has the habit of gathering data,formatting (i.e. in reports) and then storing the same formated data inthe same database.I think the practice is wrong. I think the activity is fundamentallywrong because we are storing the exact same data in a database in twodifferent locations. Somehow I have the impression that database designis about "oneness".I believe that collecting the data and then storing summerized data forreporting into a data warehouse would be the right solution.I am getting flack for my viewpoint.Am I all washed up?

View 1 Replies View Related

Gather Aggregate Data From Two Tables

Jun 13, 2006

I have three tables:

1) Contract - columns ContractNo and ContractName

2) SalesTransactions - multiple rows for each contract - relevant columns: ContractNo, InvoiceDate, Value

3) CostOfSaleTransactions - multiple rows for each contract - relevant columns: ContractNo, TransactionDate, Cost



How do I write a SELECT statement to produce rows containing:

ContractNo
ContractName
Sum of Value for ContractNo between @FromDate and @ToDate
Sum of Cost for ContractNo between @FromDate and @ToDate

Not all Contracts have either Sales or CostOfSales Transactions in the relevant date range and so one or both totals can be zero.

I've written something like:

SELECT CT.ContractNo, CT.ContractName, sum(CT.Value) as TotalValue, Sum(CS.Cost) as TotalCost

FROM Contract CT

INNER JOIN SalesTransactions ST ON CT.ContractNo=ST.ContractNo

INNER JOIN CostOfSaleTransactions CS ON CT.ContractNo=CS.ContractNo

WHERE (ST.InvoiceDate BETWEEN @FromDate AND @ToDate) AND (CS.TransactionDate BETWEEN @FromDate AND @ToDate)

GROUP BY CT.ContractNo, CT.ContractName

The TotalValue and TotalCost figures I get are much higher than expected. I presume this is something to do with the JOINs or WHERE clause. Please can you advise how I get the correct values?

View 1 Replies View Related

SQL 2012 :: Configure Replication Which Will Gather Logs From Publication Once In A Day?

Jan 21, 2015

I wanted to schedule the transaction replication. How do I do it? Currently I have set up a transaction replication which runs continuously and synchronizes the changes with immediate effect.

I need to configure a replication which will gather logs from the publication once in a day.

Is there any possibility?

View 1 Replies View Related

Statistics

Jul 31, 2000

I need a script to drop all statistics in a database at once.
HELP!

View 5 Replies View Related

Statistics

Jun 14, 2001

I want to be able to generate a script that gives me all statistics that are in my database currently.

Does anyone know how to do this? Is the following correct:


select --a.id as SysIndex_id,
'create statistics ' + a.name + ' on ' + b.name + ' (' + SUBSTRING(A.NAME, 9, LEN(A.NAME)-17) + ')'

as SysIndex_name

--b.name
from
sysindexes A left join sysobjects B
on A.id = B.id
where a.name like '%wa%'
order by b.name

View 1 Replies View Related

Where, Oh Where, Have My Little Statistics Gone?

Aug 3, 2007

Hi all,

As part of my automagical nightly index maintenance application, I am seeing a fairly regular (3-4 failures out of 5 attempts per week) failure on one particular table in my database. The particular line which seems to be failing is this one:

DBCC SHOWCONTIG (WON_Staging_EPSEst) WITH FAST, TABLERESULTS, ALL_INDEXES

The log reports the following transgression(s):Msg 2767, Sev 16: Could not locate statistics 'WON_Staging_EpsEst' in the system catalogs. [SQLSTATE 42000]
Msg 0, Sev 16: [SQLSTATE 01000]
Msg 0, Sev 16: -------------------- Simple ReIndex for [WON_Staging_EpsEst].[IX_WON_Staging_EpsEst] [SQLSTATE 01000]
Msg 2528, Sev 16: DBCC execution completed. If DBCC printed error messages, contact your system administrator. [SQLSTATE 01000]
Msg 0, Sev 16: [SQLSTATE 01000]
Msg 0, Sev 16: -------------------- Post-Maintenance Statistics Report for WON_Staging_EpsEst [SQLSTATE 01000]
Msg 0, Sev 16: Statistics for WON_Staging_EpsEst, WON_Staging_EpsEst [SQLSTATE 01000]
Msg 2528, Sev 16: DBCC execution completed. If DBCC printed error messages, contact your system administrator. [SQLSTATE 01000]
Msg 0, Sev 16: Statistics for WON_Staging_EpsEst, IX_WON_Staging_EpsEst [SQLSTATE 01000]
Msg 2768, Sev 16: Statistics for INDEX 'IX_WON_Staging_EpsEst'. [SQLSTATE 01000]
Updated Rows Rows Sampled Steps Density Average key length
-------------------- -------------------- -------------------- ------ ------------------------ ------------------------
Aug 3 2007 3:22AM 674609 674609 196 2.0958368E-4 8.0

(1 rows(s) affected)

This table is dropped and recreated each day during a data import job. After the table is recreated and repopulated with data (using a bulk import from a flat file), the index is also recreated using the following code:CREATE INDEX [IX_WON_Staging_EpsEst]
ON [dbo].[WON_Staging_EpsEst](OSID, [Year], Period)
ON [PRIMARY]Yet more often than not, that evening, when the index maintenance job runs, it fails with the aforepasted messages complaining of being unable to find table/index statistics.

Worth noting, perhaps, is that this same process is used on roughly 10 data staging tables in this database each day, and none of the other tables fail during the index maintenance job.

Also worth noting, perhaps, is that this IDENTICAL table/code is processed in exactly the same way on TWO other servers, and the failure has not occured in any of the jobs on those other two servers (these other two servers are identical mirrors of the one failing, and contain all the same data, indicies, and everything else.

Any thoughts, suggestions for where to look, or unrestrained abusive comments regarding my ancestry?

Thanks!

View 14 Replies View Related

Statistics

Jun 13, 2008

I have a small doubt.
If we apply a statistics command on a particular table what will it update.
Normally statistics are created automatically by the server or we have to create it.

View 1 Replies View Related

SQL Use Statistics

Jul 20, 2005

Anybody know how many companies worldwide use SQL server and how manyindividual servers this amounts to? Also, at what rate is SQL usegrowing? Can someone at least point me to a source where I could findclose to exact numbers?

View 2 Replies View Related

A Statistics Question

Jun 20, 2001

Here my data sample on which I need to perform some stats
Time(Sec) Result
1 2
2 8
3 6
4 2
5 2
6 4
7 2
8 7
9 8

What I need from this is a result set that looks as follows
GroupNo Value
1 5.33
2 2.67
3 5.67

This is a grouping of the result data in 3's by time. Value is the average of the Group.
In need to write a select statement to do this.
Note the Group could be done from 1 to 10

The end result of this is to display a Range Chart which shows Results grouped according to requirements.
Any Help would nice.
Pargat

View 6 Replies View Related

Statistics On Tables

Oct 10, 2001

Hello List,

I would like to know, How can I drop Statistics from tables. My user tables has two indexes and and some statistics created onto them. I would like to drop the statistics indexes and apprecaite, If someone please advice.

The statistics indexes looks something like this:

"_WA_Sys_status_01EAB64E"

Any help would be apprecaited.

Thanks,

View 4 Replies View Related

Index Statistics

Jun 6, 2000

What are some ways to analyze index coverage and usage? I have a 18 GB database, half is data, other half is indexes and I want to cut down that number as much as I can without affecting performance. Thanks

Peter Karhatsu

View 2 Replies View Related

Dropping The Statistics

Nov 17, 2000

Does anyone have any generic scripts that Drop all the statistics that SQL auto generates?? I have hundreds of '_WA_....'
indicies that are auto created by SS7 and I just want to get rid of ALL of them. Thanks!

View 3 Replies View Related

Index Statistics

Feb 14, 2001

I have been monitoring some indexes on a table with a lot of inserts, no updates and no deletes. I was wanting to determine when to update the statistics on the index. Does anyone know what would be a good target range for the density when you run the dbcc show_statistics?

View 1 Replies View Related

Create Statistics

Jun 14, 2000

When the "create statistics" command is run, what table entries are made into system tables?

I want to check for the existence of statistics on certain columns and if they are not there, create them. What is a good way to see if they are already created?

View 1 Replies View Related

Update Statistics

Feb 6, 2001

I am using SQL 6.5. We have tables of upto 2.5GB in size. Running update statistics againts these tables takes too long, and locks out users.

Anyone know how I can make this quicker?

Davy

View 4 Replies View Related

Index Statistics

Jun 9, 2000

I was wondering how often you should reindex. By looking at dbcc showcontig and statistics I see that I am heavily fragmented and scan density is between 10-30% on my important indexes. I'm thinking of scheduling this to be done nightly. nay help is much appreciated.

Pete Karhatsu

View 4 Replies View Related

Update Statistics

Dec 9, 2004

Hi,

I am contemplating creating a job to execute every 5 mins which will update index statisics if they are more than say 8% out. I would like to know what thoughts people have on this? i.e. pros and cons.

I like forward to what you have to say.

I have auto stats on. Our stats are often more than 10% out. At what level do you reckon the query plan might be effected by out of data stats?

Thanks
Jamie.

View 5 Replies View Related

Update Statistics

Dec 7, 2005

Is the Update Statistics found in a Maintenance Plan performed online or offline? Will it kick users out when this is run on SQL Server 2000?

Thanks

View 1 Replies View Related

Statistics - How To Update

Sep 6, 2006

Hi,

It seems to me there are many ways to update statistics for a table. i.e. "sp_updatestats", "sp_recompile", "dbcc updateusage"

Can somebody tell me the difference between those commands and what's the best way for updating your statistics? Does reindexing update the statistics?

thx,
Wilfred van Dijk

View 3 Replies View Related

Statistics In SQL Server

Feb 12, 2002

Can I copy statistics in SQL Server from one environment to another without copying the actual data. For example from production to development. It is possible to copy statistics in other databases, like DB2/UDB, Oracle. Reason is to execute some poor performing SQLs and analyze their execution plan.

Did not find anything on this subject in BOL. Since statistics is stored in the statblob column of sysindexes, I tried updating statblob column of the index and rowcnt columns of table & index to mimic the copy. After my updates to 'TO' table

dbcc show_statistics ( stat_test2, stat_test2_idx)

showed the results that is identical to the statistics of my FROM table.

But when I execute a small SELECT on (FROM) table(which contains the original, required stats) and the (TO) table (where the statistics is now copied), I get 2 different execution plans. This means I am not successful in my attempt to cheat the optimizer.

Is there any more columns to be updated?

Is there another direct way to do this?

Thanks in advance.
Gana.

View 1 Replies View Related

How Can I Get User Statistics?

Nov 5, 1999

I am supporting a SQL Server 6.5 databases that users query using
pre-configured reports. The reports use views, stored procedures,
and triggers set up by the programmers and accessed thru a client
on the workstation.

I need to be able to count which users log in (SQL Server security),
how often, and either which reports they use or what tables they
select.

I do not have access to the WindowsNT server, so the solution
has to work with SQL Server SA rights.

Thanks for any suggestions.

Joan

View 1 Replies View Related

Statistics Degrade

Aug 6, 2004

Hi,

another daily problem ...

I've a table with half million records that my application uses continious with several UPDATE e SELECT statement (about 5 requests/sec).
After several (4-5) hours I've a degrade of performance, but if I update the statistics (of thi table) all return ok.

Now the situation is I create a job to maintenance this table updating statististic two times a day ....

Is it normal? SQL should update statistics by itself?
I choose the wrong way or ... what can i do?

Thx

View 1 Replies View Related

Updating Statistics

Jan 17, 2007

Hi All,

I have few quries

1) Do we need downtime or to make database offline while updating statistics for table? Or this can be done online?

2) If this can be done online, will it consume CPU or memory?

3) Will the log file will grow during statistics updation?

Thanks in Advance

Regards
SS

Don't sit back because of failure. It will come back to check if you still available. -- Binu

View 2 Replies View Related

IISLog Statistics For SQL

Mar 29, 2007

I am looking for a product similar to:

Sawmill Enterprise (www.sawmill.net) that has IISLog support direct from an SQL server. There are other products out there as well like AWStats (http://www.sawmill.net/) and WebLog Expert that does it, but they use the actual log files.

Does anyone have suggestions on where I can look? Thank you.

View 1 Replies View Related

UPDATE STATISTICS

Dec 14, 2007

HI,

To update statistics for entire DB i have taken the script from under given link.But need to know the
1 : what is sample percent on update statistics
2 : will it be applicable for 2005 ?

script taken from :
http://weblogs.sqlteam.com/tarad/archive/2006/08/14/11194.aspx

kindly reply soon.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved