.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

script to check fragmentation

Posted By:      Posted Date: October 23, 2010    Points: 0   Category :Sql Server

Dear all,

Can anyone provide me the complete script to check the average fragmentation for each table (with table name) in a DB?

I have tried this but seem only retrive data for one of the table. I would like to show ALL tables.

SELECT a.index_id, name, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(N'xxxx.master'),
  JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id;








View Complete Post

More Related Resource Links

how to check one time java script file download not every session

how to check one time java script file download not every session

Check Index Fragmentation query

Hi, I have ran the following query to view the fragmentation on my large table with 1000+ pages. Now the results I got are moslty at index level 0 and 1 and most objects are fragmented 90+%. My question to the experts is that the query is displaying fragmentation mostly at Index level 0 and 1. Do I need to look or just Level = 0 is fine? The query is SELECT DB_NAME(SDDIPS.[database_id]) AS [database_name], OBJECT_NAME(SDDIPS.[object_id], DB_ID()) AS [object_name], sddips.[object_id] as [Object_ID] ,SSI.[name] AS [index_name], SDDIPS.partition_number, SDDIPS.index_level ,SDDIPS.index_type_desc, SDDIPS.alloc_unit_type_desc, SDDIPS.avg_fragmentation_in_percent], SDDIPS.[page_count] FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'detailed') SDDIPS INNER JOIN sys.sysindexes SSI ON SDDIPS.OBJECT_ID = SSI.id AND SDDIPS.index_id = SSI.indid WHERE SDDIPS.page_count > 1000 AND avg_fragmentation_in_percent > 15 AND index_type_desc <> 'HEAP' ORDER BY OBJECT_NAME(SDDIPS.[object_id], DB_ID()), index_id

Index fragmentation script runs but yet fragmentation remains high


I have an index maintenance job that runs frequently, what I find is that despite the fact that the script runs, fragmentation is still quite high on the tables. I am using the standard approach of having  a rebuild if fragmentation is over 20 and if its between 5 and 20 then it reorganises the page.

Is this usual for such a behavior ?

script to check the database size



I work with Microsoft SQL Server Workgroup Edition 2008 and I would like to know if there is a script to check the database size.

I need something like ‘give databasename’ and return the database size.
Can I do this via a vbscript?

Background info:
Different departments one SQL Server.
Every department has one or more databases on the SQL Server.
Department managers are billed per GB in use.
Department managers require a script to check the database size without using Microsoft SQL Server Management Studio or any other console. Just a shortcut on their desktop.

Let me know if you need more information.
Thank you,

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Check All with JQuery and a Asp.Net GridView

Display a Grid on the screen with a checkbox in each row. At the bottom of the page have "Check All" button.

Typically if I need to do anything interesting I use a template column. So my GridView will look like the one below (most other columns removed for readability). The only interesting point to note is the CssClass="ApprovalCheckBox" in the CheckBox ItemTemplate.

Rendering ASP.NET Script References into the Html Header

One thing that I've come to appreciate in control development in ASP.NET that use JavaScript is the ability to have more control over script and script include placement than ASP.NET provides natively. Specifically in ASP.NET you can use either the ClientScriptManager or ScriptManager to embed scripts and script references into pages via code.

check box control


Hi ,

I have a three check box in my web form ,i need to choose only one check box, if i choose one check box

another 2 check box automatically unchecked

can i use jquery for check box

I thought this would be simple... Trying to create a login does an ajax check before submit


I have the standard .net login control that is working.  (Still learning .net after 15yrs of classic)

What I want to do is OnButtonClick run a javascript function (to do an ajax call to the db to check if login is valid or not) and if it returns true, then submit the form normally, else don't submit. The piece that I can't figure out, is how to correctly override the default click even to hit my JS routine and then submit the form properly afterwards.

Thanks ahead of time

*.axd script references not being rendered to browser


I'm running VS2010 with .net 4.0, and am running into issues with the .net ajax script tags mysteriously not being rendered to the browser.

So far I've reduced it to a scenario where I set the DataSourceID property of a databound control.  More specifically, I've only tested it on a Gridview and a DropDownList.

This can be reproduced fairly easily on my machine by following these steps:

1. Create a new empty Web Application Project

2. Create a new Web Form

3. Add a ScriptManager inside the form

4. Add a DropDownList and a DataSource (I used an ObjectDataSource)

5. Set the DataSourceID property of the DropDownList to the ID of the DataSource.  This can be done either declaratively on the .aspx page, or in the code behind in the aspx.cs page, and both produce the same results.

6. Open the page in a browser and watch as you get a javascript error stating "Sys is not defined" and notice that the page source contains no script tags referencing *.axd scripts.

Here's my source code showing my set up:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ScriptResourceFAIL.Default" %>


how to check a textbox value in jquery?



I want to perform some action when an asp.net textbox value length is greater than 1 character. And for this I wanted to know how to write this check in jquery?

I have created a check like below-

if ($('[id=txtUserInput]').val().length > 2)
{ do some work...} 

But its giving me the following error

$("[id=txtUserInput]").val() is undefined

Can anybody let me know the right way of doing this?



Client script not running


Dear all,

in my MVC 2 application, and in the shared Master Page I wrote this little script for menu handling :

<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript"> $(document).ready(function () {   
     $('#nav li').hover(  
         function () {  
             //show its submenu  
             $('ul', this).slideDown(100);  
        function () {  
           //hide its submenu  
            $('ul', this).slideUp(100);           

The script, that shows menu items when the

Potentially dangerous script....blah blah


explain this one - -   (please)

2 projects - same code - one, using 2008, one using 2010 - a textbox a button and a label, using html code in the textbox

In the Page Directive:
EnableEventValidation="false" ValidateRequest="false&q

How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

Automatically redirect to HTTPS and check if SSL is active



I've set in the web.config:

    <!-- User Authentication -->
    <authentication mode="Forms">
      <forms loginUrl="~/Page/View/Content/Login.aspx" timeout="2880" requireSSL="true" />

This works fine. If there is no ssl connection, the login form doesn't continue. But I would like to check if ssl is active (in codebehind) and, if it's possible, to automatically the user to the https page if he's currently on http. (I could do this job by manually redirect with page.response("https://url.../login.aspx"); but this is not really generic. For example if the webapp is moved to another domain it doesn't work anymore... I'm looking for something like: FormsAuthentication.RedirectWithSSL(); or so... :D)


how to check which pages of my site that my visitor visiting at the moment


 Hi all, and thanks a lot for the replies since now. I have a new question :

I prepared a simple instant messaging system for my web site and i would like to learn which visitor (registered member) is at which page of my site. 

For example : 

Uid:10000, Username:donald, NameSurname:Donald DUCK is a registered and signed in visitor.

I need the code which tells me that visitor is at which page (ie. images.aspx?imageid=143223)

Sorry for my poor english, and let me know if i should explain more clearly :)

Have a good evening...

Tools for memory error check in VS2005


Dear all,

I am going to write vs2005 program with ASP.NET and C++.

As you know that C++ will involve a lot of memory error handling.

Do you know is there any tools for checking memory error in Code Behind C++??

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend