Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Index Physical Stats

Posted on 2013-05-11
3
Medium Priority
?
344 Views
Last Modified: 2013-05-13
Hi Experts!

I would like to ask, what could be wrong with this procedure:

USE iass_ent3
GO
SELECT object_id, index_id, avg_fragmentation_in_percent, page_count
FROM sys.dm_db_index_physical_stats(DB_ID('iass_ent3'),
OBJECT_ID('dbo.ad_master'), NULL, NULL, NULL);

Open in new window


it returns:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.

In my other database server, I just changed the database name and table name, the procedure is working fine.

Thank you.
0
Comment
Question by:MediaBanc
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 39158419
please make sure the current compatibility of iass_ent3 is at least 90.
0
 
LVL 23

Accepted Solution

by:
Racim BOUDJAKDJI earned 2000 total points
ID: 39158426
or you can do the following with older compatibility...

declare @db_id smallint, @table_id int
set @db_id=db_id('iass_ent3')
set @tab_id=object_id( 'dbo.ad_master')
select object_id, index_id, avg_fragmentation_in_percent, page_count
from sys.dm_db_index_physical_stats(@db_id,@table_id, NULL, NULL , NULL)
go

Open in new window


hope this helps...
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39159771
As Racimo has pointed out the function dm_db_index_physical_stats() was not available prior to SQL Server 2005.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question