Showing posts with label run. Show all posts
Showing posts with label run. Show all posts

Thursday, March 29, 2012

Can I have replication between two completely different schemas?

Hi SQL guys,

I have 2 different databases and an import tool that reads from one and fills the other one and then whenever we run it, it should synch the two databases and its kind of a heavy task. I was wondering if i can replace it with replication between these databases. I defined publisher and subscriber, but i cannot find anywhere that i can say which field in source maps to which field in destination.

Is it possible at all to have a replication between 2 databases with totally different schemas? If so, please let me know how.

Thanks,

Sina

No, the schemas should match. Aleast they should be compatible.|||

yes, you can, but only if the subscriber is not updating the data.

if you are only importing data from the publisher, then you can , what you need is create a transformable subscription, you use dts in that subscription to make all matching or convertions you need between source and destination.

Thank you

Armando Marrero

|||

hi Armando...

can you please brief the steps of making the matches between source and destination for transformable subscription.

Thanks in advance

Can I have replication between two completely different schemas?

Hi SQL guys,

I have 2 different databases and an import tool that reads from one and fills the other one and then whenever we run it, it should synch the two databases and its kind of a heavy task. I was wondering if i can replace it with replication between these databases. I defined publisher and subscriber, but i cannot find anywhere that i can say which field in source maps to which field in destination.

Is it possible at all to have a replication between 2 databases with totally different schemas? If so, please let me know how.

Thanks,

Sina

No, the schemas should match. Aleast they should be compatible.|||

yes, you can, but only if the subscriber is not updating the data.

if you are only importing data from the publisher, then you can , what you need is create a transformable subscription, you use dts in that subscription to make all matching or convertions you need between source and destination.

Thank you

Armando Marrero

|||

hi Armando...

can you please brief the steps of making the matches between source and destination for transformable subscription.

Thanks in advance

Can I have replication between two completely different schemas?

Hi SQL guys,

I have 2 different databases and an import tool that reads from one and fills the other one and then whenever we run it, it should synch the two databases and its kind of a heavy task. I was wondering if i can replace it with replication between these databases. I defined publisher and subscriber, but i cannot find anywhere that i can say which field in source maps to which field in destination.

Is it possible at all to have a replication between 2 databases with totally different schemas? If so, please let me know how.

Thanks,

Sina

No, the schemas should match. Aleast they should be compatible.|||

yes, you can, but only if the subscriber is not updating the data.

if you are only importing data from the publisher, then you can , what you need is create a transformable subscription, you use dts in that subscription to make all matching or convertions you need between source and destination.

Thank you

Armando Marrero

|||

hi Armando...

can you please brief the steps of making the matches between source and destination for transformable subscription.

Thanks in advance

sql

Tuesday, March 27, 2012

Can I GROUP BY aggregate Function (Like SUM)

Hello,
I column that calculated at run time in insert , can i gruop by this column,the new one that not exist yetyes, with a derived table, but why would you want to?

please show an example, using sample data to illustrate|||this is my case:

i have a table with a column datetime (I use to record time of calls) , i want to create table that hold data for each hour, so i round the column and want to group by this column in the same time|||you can round a datetime? please show your query|||This is the Query of round datetime

DATEADD(Hour, DATEDIFF(Hour, 0, cdrCallDate), 0)

You can change [hour] to day , minutes , second , etc...|||yes, you can GROUP BY that expression :)

and you cannot use second, it causes an overflow

:)|||thanks man for this information

Can I get a link to step-by-step MSDE install instrustions on WIN2

Hi All,
I new when it comes to MSDE but all I need to do is install it and setup an
ODBC data source for an application I run. It's on Windows 2003 Server and no
matter what I do I can't setup an ODBC connection using SQL authentication
because I get error 18456 all the time. I've granted my windows account login
access, the install is NOT set for windows authentication only, and TCP/IP is
enabled. I can login as sa from the command line but not through the ODBC
manager. I'm on about my 5th reinstall and have become very frustrated here.
Can some one point me in the right direction please?
Thanks
That error is a login failure, it surely doesn't help reinstalling. You need
permission to log into your SQL Server.
If you are member of the local administrators group, you shouldn't get this
error.
Other possibilities could be if you have semi-colon in your username (there
is a KB article on this).
Please use your full name when posting to these newsgroups.
Jon Jahren
"ComfortablySAD" <ComfortablySAD@.discussions.microsoft.com> wrote in message
news:D5C5E09E-BEE4-4BC9-A2E4-4E1BAEFB67BB@.microsoft.com...
> Hi All,
> I new when it comes to MSDE but all I need to do is install it and setup
an
> ODBC data source for an application I run. It's on Windows 2003 Server and
no
> matter what I do I can't setup an ODBC connection using SQL authentication
> because I get error 18456 all the time. I've granted my windows account
login
> access, the install is NOT set for windows authentication only, and TCP/IP
is
> enabled. I can login as sa from the command line but not through the ODBC
> manager. I'm on about my 5th reinstall and have become very frustrated
here.
> Can some one point me in the right direction please?
> Thanks

Sunday, March 25, 2012

can I export a database from query analyzer?

Is there a command or script I can run from query analyzer to export a
database?
Its a long story but I can only get to the database through query analyzer
and there is one database I need to pull out to another machine.
Thanks,
You can do a couple of things:
1) Backup the database and then restore it on the other server. Refer to SQL Server Books Online for syntax and examples
2) If you have a copy of the database files (data + logs) then you can use sp_attach_db to attach the database files on another server.
3) If you don't have the database files but can take the database offline for sometime then you can take the database offline (one method will be to use sp_dboption) then
copy the files to the new server. Now you can take db online. connect to the new server using QA and use sp_attach_db
HTH,
Best Regards,
Uttam Parui
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
Microsoft highly recommends that users with Internet access update their Microsoft software to better protect against viruses and security vulnerabilities. The easiest way
to do this is to visit the following websites: http://www.microsoft.com/protect
http://www.microsoft.com/security/guidance/default.mspx
|||Great I do have the database files and log. I will just attach those in
another instance.
Thanks for your help.
"Uttam Parui[MS]" wrote:

> You can do a couple of things:
> 1) Backup the database and then restore it on the other server. Refer to SQL Server Books Online for syntax and examples
> 2) If you have a copy of the database files (data + logs) then you can use sp_attach_db to attach the database files on another server.
> 3) If you don't have the database files but can take the database offline for sometime then you can take the database offline (one method will be to use sp_dboption) then
> copy the files to the new server. Now you can take db online. connect to the new server using QA and use sp_attach_db
> HTH,
> Best Regards,
> Uttam Parui
> Microsoft Corporation
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Are you secure? For information about the Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.com/security.
> Microsoft highly recommends that users with Internet access update their Microsoft software to better protect against viruses and security vulnerabilities. The easiest way
> to do this is to visit the following websites: http://www.microsoft.com/protect
> http://www.microsoft.com/security/guidance/default.mspx
>
>
sql

Can I dynamically change the width of objects?

I have a problem using the table object. I have columns that I sometimes want to show, and I want the page to run off the edge and be two pages. However, usually I'm hiding many of the columns and the table "shrinks" enough to fit on one page. When this happens, the table looks right on the first page, but I get blank pages after it, because the report itself will not shrink.
Is there a way to dynamically change the size of the table and report so that it doesn't print blank pages if it doesn't need to?
Thanks,
John
Unfortunately, there is no way to shrink the body size of the report. This is under consideration for a future release.|||

We had same situation where user would select few columns out of some possible 50 data columns.

We ended with doing some logic programmatically.

1) GetReportDefinition() of report containing 50 columns

2) As rdl from #1 is XML, we manipluate the xml by deleting the unselected columns and reordering them as per selected display order

3) publish the new report with unique name to a temp folder in reporing server

4) Now generate the report

5) then delete the report from temp folder

|||

We have the same issue with a client where a dense grid in 12.5 in body with borders it is 13in. The client uses IE6.

I read that IE7 supports Shrink-to-fit. Would that work with SSRS reports pending the Shrink-to-fit functionality printing in SSRS?

Thanks

Can I dynamically change the width of objects?

I have a problem using the table object. I have columns that I sometimes want to show, and I want the page to run off the edge and be two pages. However, usually I'm hiding many of the columns and the table "shrinks" enough to fit on one page. When this happens, the table looks right on the first page, but I get blank pages after it, because the report itself will not shrink.
Is there a way to dynamically change the size of the table and report so that it doesn't print blank pages if it doesn't need to?
Thanks,
John
Unfortunately, there is no way to shrink the body size of the report. This is under consideration for a future release.|||

We had same situation where user would select few columns out of some possible 50 data columns.

We ended with doing some logic programmatically.

1) GetReportDefinition() of report containing 50 columns

2) As rdl from #1 is XML, we manipluate the xml by deleting the unselected columns and reordering them as per selected display order

3) publish the new report with unique name to a temp folder in reporing server

4) Now generate the report

5) then delete the report from temp folder

|||

We have the same issue with a client where a dense grid in 12.5 in body with borders it is 13in. The client uses IE6.

I read that IE7 supports Shrink-to-fit. Would that work with SSRS reports pending the Shrink-to-fit functionality printing in SSRS?

Thanks

Can I dynamically change the width of objects?

I have a problem using the table object. I have columns that I sometimes want to show, and I want the page to run off the edge and be two pages. However, usually I'm hiding many of the columns and the table "shrinks" enough to fit on one page. When this happens, the table looks right on the first page, but I get blank pages after it, because the report itself will not shrink.
Is there a way to dynamically change the size of the table and report so that it doesn't print blank pages if it doesn't need to?
Thanks,
John
Unfortunately, there is no way to shrink the body size of the report. This is under consideration for a future release.|||

We had same situation where user would select few columns out of some possible 50 data columns.

We ended with doing some logic programmatically.

1) GetReportDefinition() of report containing 50 columns

2) As rdl from #1 is XML, we manipluate the xml by deleting the unselected columns and reordering them as per selected display order

3) publish the new report with unique name to a temp folder in reporing server

4) Now generate the report

5) then delete the report from temp folder

|||

We have the same issue with a client where a dense grid in 12.5 in body with borders it is 13in. The client uses IE6.

I read that IE7 supports Shrink-to-fit. Would that work with SSRS reports pending the Shrink-to-fit functionality printing in SSRS?

Thanks

Can I disconnect users on a timed basis?

I know SQL Server is a pretty powerful beast and I can use SQL Server Agent
Jobs to run things on a timed basis, but can anyone answer...
Is it possible to write scripts or stored procedures (or whatever is needed)
to disconnect a user from the database after a period of inactivity?
If so, can someone give me a clue how I would do this or possibly point me
in the right direction.
Thanks!Hi,
Yes it is possible to do, But please check the status of that user before
disconnecting. If it is runnable please wait for some more time and
kill the user once the status become "Sleeping"
declare @.status varchar(30)
declare @.pid int,@.sql nvarchar(100)
select @.status=status from master..sysprocesses where loginame='user_name'
if @.status = 'sleeping'
begin
select @.pid = spid from master..sysprocesses where loginame='user_name'
set @.sql= 'kill '+convert(char,@.pid)
exec sp_executesql @.sql
end
Schedule the script thru SQL Agent jobs. THe above script can take care of 1
user kill . If you have mutiple user, you have to slightly modify the script
Thanks
Hari
MCDBA
"Dave Roys" <daveroys@.xtra.co.nz> wrote in message
news:u4FeDTmAEHA.2600@.TK2MSFTNGP09.phx.gbl...
> I know SQL Server is a pretty powerful beast and I can use SQL Server
Agent
> Jobs to run things on a timed basis, but can anyone answer...
> Is it possible to write scripts or stored procedures (or whatever is
needed)
> to disconnect a user from the database after a period of inactivity?
> If so, can someone give me a clue how I would do this or possibly point me
> in the right direction.
> Thanks!
>

Thursday, March 22, 2012

Can I Created a BPA 'Job'

Can I created a job that I can send to my Service Delivery group to run on the Production servers? I'm a developer and don't WANT access to PROD, but I want BPA run against PROD. I'd like to have them install BPA and them send them a 'package' to run. Is
this available with BPA?
Thanks,
Maybe not exactly what you want, but there's a way you can get close.
Install BPA, which creates the repository. In it, create a best practice
group that scans things the way you want. You should register the servers
from production, or register them as (local).
Have your production team install BPA (they will have to create a repository
but it can be discarded) and then ask them to run bpa (likely the command
line version bpacmd.exe) pointing at your repository database. If they do
that, they'll have to execute the best practice group that you created.
- Christian
"B.W." <bw.lightsey@.tetrapak.com> wrote in message
news:611E0DF9-C69E-4EF6-AA6B-0E390C3430A8@.microsoft.com...
> Can I created a job that I can send to my Service Delivery group to run on
the Production servers? I'm a developer and don't WANT access to PROD, but I
want BPA run against PROD. I'd like to have them install BPA and them send
them a 'package' to run. Is this available with BPA?
> Thanks,
>
sql

Sunday, March 11, 2012

Can drill through reports display parameters

I have a top level report in which I am select a particular run. The id for
that run is passed to a child report which uses the id from that run to
generate a list of possible values to generate the drill through report. My
problem is that I seem to have to set both values from the top level report
and then the second report does not show the parameters. If I browse
directly to the second report then I have the option of entering parameters.
Should I be able to see parameters when drill into a reportI forgot to mention that when I am in the designer the parameters are always
visible, but when I deploy to website and try to browse the report, that is
when they ar not visible.
"slumley" wrote:
> I have a top level report in which I am select a particular run. The id for
> that run is passed to a child report which uses the id from that run to
> generate a list of possible values to generate the drill through report. My
> problem is that I seem to have to set both values from the top level report
> and then the second report does not show the parameters. If I browse
> directly to the second report then I have the option of entering parameters.
> Should I be able to see parameters when drill into a report|||I have the same problem but only with the latest CTP (Sept), it worked fine
in the June version.
"slumley" wrote:
> I forgot to mention that when I am in the designer the parameters are always
> visible, but when I deploy to website and try to browse the report, that is
> when they ar not visible.
> "slumley" wrote:
> > I have a top level report in which I am select a particular run. The id for
> > that run is passed to a child report which uses the id from that run to
> > generate a list of possible values to generate the drill through report. My
> > problem is that I seem to have to set both values from the top level report
> > and then the second report does not show the parameters. If I browse
> > directly to the second report then I have the option of entering parameters.
> >
> > Should I be able to see parameters when drill into a report

Thursday, March 8, 2012

can dbcc indexdefrag reindex the whole database in one time?

Hi,
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
--
Thank you very much!
Best regards,
FlorenceHi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
--
Thanks
Yogish|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>> CREATE PROC ukug2_op_defrag
>> @.is_reindex char(1) = 'Y'
>> AS
>> BEGIN
>> SET NOCOUNT ON
>> -- Basis of script taken from BOL
>> CREATE TABLE #fraglist (
>> ObjectName CHAR (255),
>> ObjectId INT,
>> IndexName CHAR (255),
>> IndexId INT,
>> Lvl INT,
>> CountPages INT,
>> CountRows INT,
>> MinRecSize INT,
>> MaxRecSize INT,
>> AvgRecSize INT,
>> ForRecCount INT,
>> Extents INT,
>> ExtentSwitches INT,
>> AvgFreeBytes INT,
>> AvgPageDensity INT,
>> ScanDensity DECIMAL,
>> BestCount INT,
>> ActualCount INT,
>> LogicalFrag DECIMAL,
>> ExtentFrag DECIMAL)
>> DECLARE tables_cur CURSOR FOR
>> SELECT TABLE_NAME
>> FROM INFORMATION_SCHEMA.TABLES
>> WHERE TABLE_TYPE = 'BASE TABLE'
>> ORDER BY TABLE_NAME
>> OPEN tables_cur
>> DECLARE @.ObjectName sysname
>> FETCH NEXT FROM tables_cur INTO @.ObjectName
>> WHILE @.@.FETCH_STATUS = 0
>> BEGIN
>> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
>> COUNT_ROWS, NO_INFOMSGS' )
>> INSERT #fraglist
>> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
>> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
>> FETCH NEXT FROM tables_cur INTO @.ObjectName
>> END
>> CLOSE tables_cur
>> DEALLOCATE tables_cur
>> SELECT *
>> FROM #fraglist fo
>> WHERE LogicalFrag > 30 -- % fragmentation
>> AND IndexID BETWEEN 1 AND 254
>> AND ( IndexID = 1
>> OR NOT EXISTS (
>> SELECT * -- If clustered index to defrag then don't do
>> anything else (no point).
>> FROM #fraglist fi
>> WHERE fi.ObjectId = fo.ObjectId
>> AND fi.IndexID = 1
>> )
>> )
>> IF @.is_reindex = 'Y'
>> BEGIN
>> DECLARE defrag_cur CURSOR FOR
>> SELECT ObjectName,
>> IndexName
>> FROM #fraglist fo
>> WHERE LogicalFrag > 30 -- % fragmentation
>> AND IndexID BETWEEN 1 AND 254
>> AND ( IndexID = 1
>> OR NOT EXISTS (
>> SELECT * -- If clustered index to defrag then
>> don't do anything else (no point).
>> FROM #fraglist fi
>> WHERE fi.ObjectId = fo.ObjectId
>> AND fi.IndexID = 1
>> )
>> )
>> DECLARE @.IndexName sysname
>> DECLARE @.sql varchar(1000)
>> OPEN defrag_cur
>> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
>> WHILE @.@.FETCH_STATUS = 0
>> BEGIN
>> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
>> indexname=' + @.IndexName
>> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''',
>> ' + @.IndexName + ')'
>> PRINT @.sql
>> EXEC( @.sql )
>> PRINT 'Complete.'
>> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
>> END
>> DEALLOCATE defrag_cur
>> END
>> DROP TABLE #fraglist
>> END
>>
>> --
>> Tony Rogerson
>> SQL Server MVP
>> http://www.sqlserverfaq.com?mbr=21
>> (Create your own groups, Forum, FAQ's and a ton more)
>>
>|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
Regards.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> > This is a very timely thread for me as I'm just getting ready to
implement
> > a SP that is based on the BOL sp.
> >
> > I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> > DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> > from the BOL base is a bit different and I guess I just want to know if
> > the one if BOL is incorrect or just different.
> >
> > It determines the indexes to defrag based on the results of:
> >
> > SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> > FROM #fraglist
> > WHERE LogicalFrag >= @.maxfrag
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> >
> > if you wanted to exclude clustered indexes I suppose you would be able
to
> > modify to:
> >
> > SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> > FROM jdit_fraglist
> > WHERE LogicalFrag >= @.maxfrag
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> > AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> >
> > Thanks
> >
> > Ivan
> >
> > "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> > news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> >> CREATE PROC ukug2_op_defrag
> >> @.is_reindex char(1) = 'Y'
> >> AS
> >> BEGIN
> >> SET NOCOUNT ON
> >>
> >> -- Basis of script taken from BOL
> >>
> >> CREATE TABLE #fraglist (
> >> ObjectName CHAR (255),
> >> ObjectId INT,
> >> IndexName CHAR (255),
> >> IndexId INT,
> >> Lvl INT,
> >> CountPages INT,
> >> CountRows INT,
> >> MinRecSize INT,
> >> MaxRecSize INT,
> >> AvgRecSize INT,
> >> ForRecCount INT,
> >> Extents INT,
> >> ExtentSwitches INT,
> >> AvgFreeBytes INT,
> >> AvgPageDensity INT,
> >> ScanDensity DECIMAL,
> >> BestCount INT,
> >> ActualCount INT,
> >> LogicalFrag DECIMAL,
> >> ExtentFrag DECIMAL)
> >>
> >> DECLARE tables_cur CURSOR FOR
> >> SELECT TABLE_NAME
> >> FROM INFORMATION_SCHEMA.TABLES
> >> WHERE TABLE_TYPE = 'BASE TABLE'
> >> ORDER BY TABLE_NAME
> >>
> >> OPEN tables_cur
> >>
> >> DECLARE @.ObjectName sysname
> >>
> >> FETCH NEXT FROM tables_cur INTO @.ObjectName
> >>
> >> WHILE @.@.FETCH_STATUS = 0
> >> BEGIN
> >> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> >> COUNT_ROWS, NO_INFOMSGS' )
> >>
> >> INSERT #fraglist
> >> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> >> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> >>
> >> FETCH NEXT FROM tables_cur INTO @.ObjectName
> >>
> >> END
> >>
> >> CLOSE tables_cur
> >> DEALLOCATE tables_cur
> >>
> >> SELECT *
> >> FROM #fraglist fo
> >> WHERE LogicalFrag > 30 -- % fragmentation
> >> AND IndexID BETWEEN 1 AND 254
> >> AND ( IndexID = 1
> >> OR NOT EXISTS (
> >> SELECT * -- If clustered index to defrag then don't
do
> >> anything else (no point).
> >> FROM #fraglist fi
> >> WHERE fi.ObjectId = fo.ObjectId
> >> AND fi.IndexID = 1
> >> )
> >> )
> >>
> >> IF @.is_reindex = 'Y'
> >> BEGIN
> >> DECLARE defrag_cur CURSOR FOR
> >> SELECT ObjectName,
> >> IndexName
> >> FROM #fraglist fo
> >> WHERE LogicalFrag > 30 -- % fragmentation
> >> AND IndexID BETWEEN 1 AND 254
> >> AND ( IndexID = 1
> >> OR NOT EXISTS (
> >> SELECT * -- If clustered index to defrag then
> >> don't do anything else (no point).
> >> FROM #fraglist fi
> >> WHERE fi.ObjectId = fo.ObjectId
> >> AND fi.IndexID = 1
> >> )
> >> )
> >>
> >> DECLARE @.IndexName sysname
> >> DECLARE @.sql varchar(1000)
> >>
> >> OPEN defrag_cur
> >>
> >> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> >>
> >> WHILE @.@.FETCH_STATUS = 0
> >> BEGIN
> >> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> >> indexname=' + @.IndexName
> >> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) +
''',
> >> ' + @.IndexName + ')'
> >> PRINT @.sql
> >> EXEC( @.sql )
> >> PRINT 'Complete.'
> >>
> >> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> >>
> >> END
> >> DEALLOCATE defrag_cur
> >> END
> >>
> >> DROP TABLE #fraglist
> >>
> >> END
> >>
> >>
> >> --
> >> Tony Rogerson
> >> SQL Server MVP
> >> http://www.sqlserverfaq.com?mbr=21
> >> (Create your own groups, Forum, FAQ's and a ton more)
> >>
> >>
> >
> >
>

can dbcc indexdefrag reindex the whole database in one time?

Hi,
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
Thank you very much!
Best regards,
Florence
Hi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
Thanks
Yogish
|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)
|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>
|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>
|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...[vbcol=seagreen]
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
implement[vbcol=seagreen]
to[vbcol=seagreen]
do[vbcol=seagreen]
''',
>

can dbcc indexdefrag reindex the whole database in one time?

Hi,
Normally i run the DBCC INDEXDEFRAG one table in one time, can run
all the tables in one time?
--
Thank you very much!
Best regards,
FlorenceHi,
This gives DBCC DBREINDEX. You can use this during off-peak hrs, as this is
not an online re-indexing operation. If you still want to use DBCC
INDEXDEFRAG, look at the usage of the same in BOL, and replace it with DBCC
DBREINDEX in given script.
/* Re-indexes the specified database */
CREATE PROCEDURE scr_defrag_database
@.dbname nvarchar(256)
AS
BEGIN
-- Quote the database name with brackets
DECLARE @.quoteddbname nvarchar(256)
SET @.quoteddbname = quotename( @.dbname )
-- The outer EXEC is so we can do USE, not allowed in stored procs
-- The inner EXEC does the actual reindex on each table in the
-- specified database
EXEC('
USE '+ @.quoteddbname +'
DECLARE @.stablename sysname
DECLARE PKMS_Tables CURSOR LOCAL FOR
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ''BASE TABLE'' ORDER BY 1
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @.stablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.stablename = quotename(@.stablename, ''[]'')
EXEC('' DBCC DBREINDEX ( ''+@.stablename+'') WITH NO_INFOMSGS'')
FETCH NEXT FROM PKMS_Tables INTO @.stablename
END
CLOSE PKMS_Tables')
END
Thanks
Yogish|||CREATE PROC ukug2_op_defrag
@.is_reindex char(1) = 'Y'
AS
BEGIN
SET NOCOUNT ON
-- Basis of script taken from BOL
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
DECLARE tables_cur CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
OPEN tables_cur
DECLARE @.ObjectName sysname
FETCH NEXT FROM tables_cur INTO @.ObjectName
WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH COUNT_ROWS,
NO_INFOMSGS' )
INSERT #fraglist
EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
FETCH NEXT FROM tables_cur INTO @.ObjectName
END
CLOSE tables_cur
DEALLOCATE tables_cur
SELECT *
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then don't do
anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
IF @.is_reindex = 'Y'
BEGIN
DECLARE defrag_cur CURSOR FOR
SELECT ObjectName,
IndexName
FROM #fraglist fo
WHERE LogicalFrag > 30 -- % fragmentation
AND IndexID BETWEEN 1 AND 254
AND ( IndexID = 1
OR NOT EXISTS (
SELECT * -- If clustered index to defrag then
don't do anything else (no point).
FROM #fraglist fi
WHERE fi.ObjectId = fo.ObjectId
AND fi.IndexID = 1
)
)
DECLARE @.IndexName sysname
DECLARE @.sql varchar(1000)
OPEN defrag_cur
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
WHILE @.@.FETCH_STATUS = 0
BEGIN
PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
indexname=' + @.IndexName
SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
+ @.IndexName + ')'
PRINT @.sql
EXEC( @.sql )
PRINT 'Complete.'
FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
END
DEALLOCATE defrag_cur
END
DROP TABLE #fraglist
END
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)|||This is a very timely thread for me as I'm just getting ready to implement a
SP that is based on the BOL sp.
I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created from
the BOL base is a bit different and I guess I just want to know if the one
if BOL is incorrect or just different.
It determines the indexes to defrag based on the results of:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
if you wanted to exclude clustered indexes I suppose you would be able to
modify to:
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM jdit_fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
Thanks
Ivan
"Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
> CREATE PROC ukug2_op_defrag
> @.is_reindex char(1) = 'Y'
> AS
> BEGIN
> SET NOCOUNT ON
> -- Basis of script taken from BOL
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> DECLARE tables_cur CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> ORDER BY TABLE_NAME
> OPEN tables_cur
> DECLARE @.ObjectName sysname
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> EXEC( 'DBCC UPDATEUSAGE( 0, [' + @.ObjectName + '] ) WITH
> COUNT_ROWS, NO_INFOMSGS' )
> INSERT #fraglist
> EXEC ( 'DBCC SHOWCONTIG( [' + @.ObjectName + '] ) WITH
> TABLERESULTS, ALL_INDEXES, NO_INFOMSGS' )
> FETCH NEXT FROM tables_cur INTO @.ObjectName
> END
> CLOSE tables_cur
> DEALLOCATE tables_cur
> SELECT *
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then don't do
> anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> IF @.is_reindex = 'Y'
> BEGIN
> DECLARE defrag_cur CURSOR FOR
> SELECT ObjectName,
> IndexName
> FROM #fraglist fo
> WHERE LogicalFrag > 30 -- % fragmentation
> AND IndexID BETWEEN 1 AND 254
> AND ( IndexID = 1
> OR NOT EXISTS (
> SELECT * -- If clustered index to defrag then
> don't do anything else (no point).
> FROM #fraglist fi
> WHERE fi.ObjectId = fo.ObjectId
> AND fi.IndexID = 1
> )
> )
> DECLARE @.IndexName sysname
> DECLARE @.sql varchar(1000)
> OPEN defrag_cur
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> PRINT 'Processing dbreindex on ' + RTRIM( @.ObjectName ) + ',
> indexname=' + @.IndexName
> SET @.sql = 'DBCC DBREINDEX( ''' + RTRIM( @.ObjectName ) + ''', '
> + @.IndexName + ')'
> PRINT @.sql
> EXEC( @.sql )
> PRINT 'Complete.'
> FETCH NEXT FROM defrag_cur INTO @.ObjectName, @.IndexName
> END
> DEALLOCATE defrag_cur
> END
> DROP TABLE #fraglist
> END
>
> --
> Tony Rogerson
> SQL Server MVP
> http://www.sqlserverfaq.com?mbr=21
> (Create your own groups, Forum, FAQ's and a ton more)
>|||Boy, I wish I could recall messages...I think I answered my own
question--this is for DBREINDEX, not INDEXDEFRAG.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
> This is a very timely thread for me as I'm just getting ready to implement
> a SP that is based on the BOL sp.
> I guess I'm confused by this a bit. From what I read in BOL in SQL 2000
> DBCC INDEXDEFRAG will defragment clustered indexes. The SP you created
> from the BOL base is a bit different and I guess I just want to know if
> the one if BOL is incorrect or just different.
> It determines the indexes to defrag based on the results of:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> if you wanted to exclude clustered indexes I suppose you would be able to
> modify to:
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
> FROM jdit_fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> AND INDEXPROPERTY (ObjectId, IndexName, 'IsClustered') = 0
> Thanks
> Ivan
> "Tony Rogerson" <tonyrogerson@.sqlserver.eu.com> wrote in message
> news:%23xN31fA9EHA.2112@.TK2MSFTNGP14.phx.gbl...
>|||Seems like a bit of confusion here. DBCC INDEXDEFRAG can defragment
clustered and non-clustered indexes. DBCC DBREINDEX can rebuild clustered
and non-clustered indexes. The example scripts in this thread are taken from
Example E in BOL for DBCC SHOWCONTIG - look there for more details.
You should read the whitepaper below on fragmentation and when you actually
need to do anything about it (don't just blindly defrag/rebuild everything
in your database - you're wasting resources).
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
news:O3CQZhB9EHA.1228@.tk2msftngp13.phx.gbl...
> Boy, I wish I could recall messages...I think I answered my own
> question--this is for DBREINDEX, not INDEXDEFRAG.
> "Ivan J. Lee" <ivan.lee@.jdinetsystems.com> wrote in message
> news:uU4xUfB9EHA.2900@.TK2MSFTNGP09.phx.gbl...
implement[vbcol=seagreen]
to[vbcol=seagreen]
do[vbcol=seagreen]
''',[vbcol=seagreen]
>

can database name be assigned as a variable?

I need to have a query like below to run to select all the fields from different databases that each database have a table named 'table1'

select * from test...table1

select * from test1..table1

I have the following code sample:

declare @.dbname varchar(50)
set @.dbname='test'
select @.dbname
select * from @.dbname..table1

However I received the error messge when I ran this code. Can anyone help to resolve this?

Thank you!


Hi

One way of doing this is to build the query dynamically and use the Exec, as shown in the example below:


Declare @.xQuery varchar(1000)
Select @.xQuery = 'Select * from test..table1'
Exec(@.xQuery)

Select @.xQuery = 'Select * from test1..table1'
Exec(@.xQuery)


Best regards
Georg
www.l4ndash.com - Log4Net Dashboard / Log4Net Viewer

can data analysis done using SQL Server 2005 be used in a consumer website?

I just have a simple question that can hopefully answer whether I should dive too deeply into Reporting/Analysis Services. I'm looking to run some clustering algorithms on user-inputted keywords on objects within my database (please see http://flickr.com/photos/tags/friends/clusters/ for an example of what I'm talking about). It seems to me that the various reporting methods that SQL Server provides would be an ideal, quick and easy way of providing this for my SQL Server 2005 database.

Can the reporting services provide this type of functionality? And if so, would this be scalable? I would want to be able to access this clustered data in much the same way I do queries across my database and would want them to be done quickly and efficiently.

Thank you for your help.

We hacve done tests executing up to 36 million data mining singleton queries/day on desktop hardware. Up to 240M/day on really nice hardware. This was issuing queried through ASP.NET (I believe, I know it was IIS).

Regarding the scalability of RS, you need to ask on the RS forum

Wednesday, March 7, 2012

Can connect from Query Analyzer but not from Report Services

I can terminal service into the box running Reporting Services. If I try to
run the
report I can't connect, it says login failed. Using the same
username/password which is sa because it's a log shipped server. I can
connect through Query Analizer. The only rememdy is to restart both servers.
Then I can connect. Then it will go hey wire after a day or two and same
situation. What could be causing this?
Please help me,
BryanAlso if I try to do net stop reportserver it says the server is not
responding to the control function. Actually the same thing happens if I try
to shut down the secondary log shipped server that the reports are pointing
at. If I do net stop mssqlserver. It gives me the same error. Something is
going on here between the two and I can't figure out what it is that is going
on?
"bmurtha" wrote:
> I can terminal service into the box running Reporting Services. If I try to
> run the
> report I can't connect, it says login failed. Using the same
> username/password which is sa because it's a log shipped server. I can
> connect through Query Analizer. The only rememdy is to restart both servers.
> Then I can connect. Then it will go hey wire after a day or two and same
> situation. What could be causing this?
> Please help me,
> Bryan

Can AUTO UPDATE STATISTICS hold an X-lock?

We are experiencing a non-deterministic (ND) problem. It is happening
regularly, but not consistently. We run a suite of tests for performance
evaluation. Some of the tests insert data into empty tables, and later these
tables are read. Each time we are able to reproduce the hang, it is because
one of the connections is shown as holding an X lock as described below on
one of the tables. The process holding the lock will always be shown as
sleeping by the SQL Server Activity Monitor. At the point that the hang
occurs, we will only be using a single connection to the database. We use a
connection pool, so there will be some connections shown as coming from the
JDBC driver (us) and sleeping. This is because of our connection pool.
However, there should be no outstanding active work for any of those
connections because we always end the transaction, either by commit or
rollback, before getting a new connection or at the end of an individual test
case.
My guess is that the X lock is being acquired by the autostats feature when
SQL Server is updating the statistics on a table during a SQL statement
because 1 of the thresholds (inserts, updates) has been exceeded and that the
lock is not being released as it should be. I am confident that we are not
explicitly updating the statistics on any table through our application until
well after this X lock becomes visible in the SQL Server Activity Monitor.
We are running of SQL Server 2005 SP1, and we experience the problem with
both the 1.0 and 1.1 CTP versions of the Microsoft JDBC driver. The database
has the default settings of AUTO_UPDATE_STATISTICS ON, and
AUTO_CREATE_STATISTICS ON, but AUTO_UPDATE_STATISTICS_ASYNC OFF.
Blocking process is holding an X lock (Type=Object, Subtype=UPDSTATS, Object
ID = 1157579163 â' cc_typekeydatadist, Description = NULL, Owner Type = TRANSACTION, Object = (internal))
Successfully processed 0 ops in 468.0069999694824 secs (running avg 0
ops/secs; last interval avg 0 ops/secs) Detailed Status:
Number of threads: 1, total number of tables: 634, number of tables
processed: 421, total number of commands: 846, number of commands processed:
492, number of command errors: 0
Index name synch started at: Mon Jul 31 17:00:58 PDT 2006, ended at: Mon Jul
31 17:00:58 PDT 2006, duration: 0 seconds
Thread #0: Active: true, number of tables processed: 421, number of commands
processed: 492, number of command errors: 0,
start time: Mon Jul 31 17:00:58 PDT 2006,
start command time: Mon Jul 31 17:01:09 PDT 2006, current command: UPDATE
STATISTICS cc_typekeydatadist WITH FULLSCAN
Successfully processed 0 ops in 478.021999835968 secs (running avg 0
ops/secs; last interval avg 0 ops/secs) Detailed Status:
Number of threads: 1, total number of tables: 634, number of tables
processed: 421, total number of commands: 846, number of commands processed:
492, number of command errors: 0
Index name synch started at: Mon Jul 31 17:00:58 PDT 2006, ended at: Mon Jul
31 17:00:58 PDT 2006, duration: 0 seconds
Thread #0: Active: true, number of tables processed: 421, number of commands
processed: 492, number of command errors: 0,
start time: Mon Jul 31 17:00:58 PDT 2006,
start command time: Mon Jul 31 17:01:09 PDT 2006, current command: UPDATE
STATISTICS cc_typekeydatadist WITH FULLSCAN
We are going to try running with all auto-stats options off, and with the
aync option on, to see if that works around the problem.
We do not issue a commit after a read-only operation, because we do not
expect to be holding any locks, but that we do return the connection to the
connection pool. Does the UPDATE STATISTICS operation occur in the same
transaction, and thus could be holding a lock unless we are running in
autocommit mode or do an explicit commit? Or does it occur on a separate,
server-initiated thread?
I've posted the same question on the Connect Feedback area."Wes Clark" <WesClark@.discussions.microsoft.com> wrote in message
news:85E8BB89-22E7-427A-B263-4155783F125A@.microsoft.com...
> We are experiencing a non-deterministic (ND) problem. It is happening
> regularly, but not consistently. We run a suite of tests for performance
. . .
> We do not issue a commit after a read-only operation, because we do not
> expect to be holding any locks, but that we do return the connection to
> the
> connection pool. Does the UPDATE STATISTICS operation occur in the same
> transaction, and thus could be holding a lock unless we are running in
> autocommit mode or do an explicit commit? Or does it occur on a separate,
> server-initiated thread?
>
In a simple test I did, I did not see any locks enlisted in a transaction
from automatically created statistics, but I suppose it's possible.
In any case, leaving transactions open when you return connections to the
pool is a dangerous and unusual thing to to. As you have discovered, you
have to be 100% sure you have not created any locks, and if one slips in,
you've got a big problem. Why not just commit? If you haven't written any
log records it doesn't really cost anything.
David|||Your suggestion sounds reasonable, and we shall consider it.
Do you know the answer to my questions: Does the UPDATE STATISTICS
operation occur in the same transaction, and thus could be holding a lock
unless we are running in autocommit mode or do an explicit commit? Or does it
occur on a separate, server-initiated thread?
"David Browne" wrote:
> "Wes Clark" <WesClark@.discussions.microsoft.com> wrote in message
> news:85E8BB89-22E7-427A-B263-4155783F125A@.microsoft.com...
> > We are experiencing a non-deterministic (ND) problem. It is happening
> > regularly, but not consistently. We run a suite of tests for performance
> .. . .
> > We do not issue a commit after a read-only operation, because we do not
> > expect to be holding any locks, but that we do return the connection to
> > the
> > connection pool. Does the UPDATE STATISTICS operation occur in the same
> > transaction, and thus could be holding a lock unless we are running in
> > autocommit mode or do an explicit commit? Or does it occur on a separate,
> > server-initiated thread?
> >
>
> In a simple test I did, I did not see any locks enlisted in a transaction
> from automatically created statistics, but I suppose it's possible.
> In any case, leaving transactions open when you return connections to the
> pool is a dangerous and unusual thing to to. As you have discovered, you
> have to be 100% sure you have not created any locks, and if one slips in,
> you've got a big problem. Why not just commit? If you haven't written any
> log records it doesn't really cost anything.
> David
>
>

Can AUTO UPDATE STATISTICS hold an X-lock?

We are experiencing a non-deterministic (ND) problem. It is happening
regularly, but not consistently. We run a suite of tests for performance
evaluation. Some of the tests insert data into empty tables, and later these
tables are read. Each time we are able to reproduce the hang, it is because
one of the connections is shown as holding an X lock as described below on
one of the tables. The process holding the lock will always be shown as
sleeping by the SQL Server Activity Monitor. At the point that the hang
occurs, we will only be using a single connection to the database. We use a
connection pool, so there will be some connections shown as coming from the
JDBC driver (us) and sleeping. This is because of our connection pool.
However, there should be no outstanding active work for any of those
connections because we always end the transaction, either by commit or
rollback, before getting a new connection or at the end of an individual tes
t
case.
My guess is that the X lock is being acquired by the autostats feature when
SQL Server is updating the statistics on a table during a SQL statement
because 1 of the thresholds (inserts, updates) has been exceeded and that th
e
lock is not being released as it should be. I am confident that we are not
explicitly updating the statistics on any table through our application unti
l
well after this X lock becomes visible in the SQL Server Activity Monitor.
We are running of SQL Server 2005 SP1, and we experience the problem with
both the 1.0 and 1.1 CTP versions of the Microsoft JDBC driver. The database
has the default settings of AUTO_UPDATE_STATISTICS ON, and
AUTO_CREATE_STATISTICS ON, but AUTO_UPDATE_STATISTICS_ASYNC OFF.
Blocking process is holding an X lock (Type=Object, Subtype=UPDSTATS, Object
ID = 1157579163 – cc_typekeydatadist, Description = NULL, Owner Type =
TRANSACTION, Object = (internal))
Successfully processed 0 ops in 468.0069999694824 secs (running avg 0
ops/secs; last interval avg 0 ops/secs) Detailed Status:
Number of threads: 1, total number of tables: 634, number of tables
processed: 421, total number of commands: 846, number of commands processed:
492, number of command errors: 0
Index name synch started at: Mon Jul 31 17:00:58 PDT 2006, ended at: Mon Jul
31 17:00:58 PDT 2006, duration: 0 seconds
Thread #0: Active: true, number of tables processed: 421, number of commands
processed: 492, number of command errors: 0,
start time: Mon Jul 31 17:00:58 PDT 2006,
start command time: Mon Jul 31 17:01:09 PDT 2006, current command: UPDATE
STATISTICS cc_typekeydatadist WITH FULLSCAN
Successfully processed 0 ops in 478.021999835968 secs (running avg 0
ops/secs; last interval avg 0 ops/secs) Detailed Status:
Number of threads: 1, total number of tables: 634, number of tables
processed: 421, total number of commands: 846, number of commands processed:
492, number of command errors: 0
Index name synch started at: Mon Jul 31 17:00:58 PDT 2006, ended at: Mon Jul
31 17:00:58 PDT 2006, duration: 0 seconds
Thread #0: Active: true, number of tables processed: 421, number of commands
processed: 492, number of command errors: 0,
start time: Mon Jul 31 17:00:58 PDT 2006,
start command time: Mon Jul 31 17:01:09 PDT 2006, current command: UPDATE
STATISTICS cc_typekeydatadist WITH FULLSCAN
We are going to try running with all auto-stats options off, and with the
aync option on, to see if that works around the problem.
We do not issue a commit after a read-only operation, because we do not
expect to be holding any locks, but that we do return the connection to the
connection pool. Does the UPDATE STATISTICS operation occur in the same
transaction, and thus could be holding a lock unless we are running in
autocommit mode or do an explicit commit? Or does it occur on a separate,
server-initiated thread?
I've posted the same question on the Connect Feedback area."Wes Clark" <WesClark@.discussions.microsoft.com> wrote in message
news:85E8BB89-22E7-427A-B263-4155783F125A@.microsoft.com...
> We are experiencing a non-deterministic (ND) problem. It is happening
> regularly, but not consistently. We run a suite of tests for performance
. . .
> We do not issue a commit after a read-only operation, because we do not
> expect to be holding any locks, but that we do return the connection to
> the
> connection pool. Does the UPDATE STATISTICS operation occur in the same
> transaction, and thus could be holding a lock unless we are running in
> autocommit mode or do an explicit commit? Or does it occur on a separate,
> server-initiated thread?
>
In a simple test I did, I did not see any locks enlisted in a transaction
from automatically created statistics, but I suppose it's possible.
In any case, leaving transactions open when you return connections to the
pool is a dangerous and unusual thing to to. As you have discovered, you
have to be 100% sure you have not created any locks, and if one slips in,
you've got a big problem. Why not just commit? If you haven't written any
log records it doesn't really cost anything.
David|||Your suggestion sounds reasonable, and we shall consider it.
Do you know the answer to my questions: Does the UPDATE STATISTICS
operation occur in the same transaction, and thus could be holding a lock
unless we are running in autocommit mode or do an explicit commit? Or does i
t
occur on a separate, server-initiated thread?
"David Browne" wrote:

> "Wes Clark" <WesClark@.discussions.microsoft.com> wrote in message
> news:85E8BB89-22E7-427A-B263-4155783F125A@.microsoft.com...
> .. . .
>
> In a simple test I did, I did not see any locks enlisted in a transaction
> from automatically created statistics, but I suppose it's possible.
> In any case, leaving transactions open when you return connections to the
> pool is a dangerous and unusual thing to to. As you have discovered, you
> have to be 100% sure you have not created any locks, and if one slips in,
> you've got a big problem. Why not just commit? If you haven't written an
y
> log records it doesn't really cost anything.
> David
>
>