Friday, February 29, 2008

At a Glance ASP.Net 2.0

Visual Studio 2008 will be launched this year. It supports completely to .Net 3.5. Although it's time to move further with .Net 3.5, I'm not writing about this newest version of .Net framework. I'm writing about .Net 2.0, specifically on its web technology, ASP.Net 2.0. This version has been used since several years ago and still in use today. Let us start from the beginning, comparing ASP.Net 2.0 with the previous version.

There are several goals reached by using ASP.Net 2.0 rather than ASP.Net 1.0. We will start with two of them.

1. Increasing Developer Productivity
The 2.0 version make common ASP.Net task easier. It decrease much of tedious coding in application. For example, compare using ASP.Net 1.0's DataGrid and ASP.Net 2.0's GridView with SqlDataSource. The code used with GridView are much more simple. GridView and SqlDataSource are new in .Net 2.0. There are other thousand of possible example showing ASP.Net 2.0 productivity. You can imagine how quick you will create your application.

2. Administration and Management of ASP.Net Application Become Easier
ASP.Net 2.0 have a Microsoft Management Console to administer web application, edit configuration setting easily. You can edit the content of machine.config and web.config from dialog instead of editing xml files. There is also a web based way to administer web application using Web Site Administration Tool. Beside managing application configuration, with the tool you can manage user membership and role. This membership and role can be used for user validation in application.

Those are for now. It's just the beginning. 

Tuesday, February 26, 2008

How to shrink your transaction log periodically on SQL Server

The most important thing in maintaining your SQL Server database is shrinking log. You should shrink your LOG data file periodically or your database will pops -i've ever experienced in that case on, hehehe-. Anyway i have a script to maintain your log daily. it would be better if you sign a job to run these queries -cause i use that - using SQL Server Agent.

DECLARE @size INT,
@name VARCHAR(200),
@logSize INT,
@database VARCHAR(200)


SELECT @logSize = 1000, -- specify your log size
@database = 'DATABASE' -- specify your sql server database name

Declare c_cursor CURSOR FAST_FORWARD FOR
    SELECT
        name,
        size
    FROM sys.master_files
    WHERE database_id = (select database_id
    FROM sys.databases where name = @database)
        AND type_desc = 'LOG'

OPEN c_cursor

FETCH NEXT FROM c_cursor INTO @name,@size

WHILE @@FETCH_STATUS = 0
BEGIN
    IF (@size >= @logSize)
    BEGIN dbcc shrinkfile(@name,2)
END

FETCH NEXT FROM c_cursor INTO @name,@size
END

CLOSE c_cursor
DEALLOCATE c_cursor


@logSize means how huge your transaction log to be shrink. if you set 0, it means you've job to shrink transaction log daily in case your transaction log in minimum size. Anyway, that is your choice to decide whatever you want. cause there is no side effect for your database.

I suggest you to run these queries at SQL Server is idle. because you don't want to distrub your database transaction, don't you. Maybe you can put your SQL Server Agent Job at Midnight -I did that in here-.Any suggestion ?

Note : @logSize = 1000 means 10MB

Monday, February 25, 2008

How to find unused index on SQL Server 2005

When i had a problem a couple days ago about indexing, i've got this query to find
unused index in your database. If you are running this query, it might help you to
maintain your index easily. If you want to be sure your index is used, you can use this
query to showing the unused index.


Here it is:

declare @DBID int

set @DBID = db_id()

SELECT
C.name TableName,
B.name IndexName,
(isnull(A.user_seeks, 0) + isnull(A.user_scans, 0) + isnull(A.user_lookups, 0) +
isnull(A.system_seeks, 0) + isnull(A.system_scans, 0) + isnull(A.system_lookups, 0))
total_used,
A.user_seeks,
A.user_scans,
A.user_lookups,
A.user_updates,
A.system_seeks,
A.system_scans,
A.system_lookups,
A.system_updates,
A.last_user_seek,
A.last_user_scan,
A.last_user_lookup,
A.last_user_update,
A.last_system_seek,
A.last_system_scan,
A.last_system_lookup,
A.last_system_update,
B.type_desc,
B.is_unique,
D.name DataSpaceName,
D.type DataSpaceType,
D.is_default DataSpaceIsDefault,
B.ignore_dup_key,
B.is_primary_key,
B.is_unique_constraint,
B.fill_factor,
B.is_padded,
B.is_disabled,
B.is_hypothetical,
B.allow_row_locks,
B.allow_page_locks
FROM sys.indexes B
LEFT JOIN sys.dm_db_index_usage_stats A
ON A.index_id = B.index_id and A.object_id = B.object_id
AND A.database_id = @DBID
INNER JOIN sys.tables C
ON B.object_id = C.object_id
INNER JOIN sys.data_spaces D
ON B.data_space_id = D.data_space_id
--WHERE C.name = 'SUBSIDY_REFUND_AMORTIZED' -- specify your table here
ORDER BY (A.user_seeks + A.user_scans + A.user_lookups + A.system_seeks + A.system_scans + A.system_lookups) desc

You can see the result, if total_used field is 0 this mean that index is unused. so you
better drop the index, to make your application better (impact to your insert and
update transaction). Another thing is your database size is getting smaller, because
the index has been dropped.

Different Types Of Crashes in IIS

There several type of crashes in IIS :

1. Access Violation
2. Unhandled Exception
3. Stack Overflows
4. Stack Corruption

1. Access Violation

Caused when code tries to access region of memory or object that are either not there (not allocated) or has protection set on it. Example :
_________
object 1
_________
null ---> you try to get this object in index-2
_________
object 1
_________

if you want to access some object in ArrayList, while the object already unallocated. It will make your application crash.

2. Unhandle Exception

when you are not handling some exception and the exception not throwed by application.

3. Stack Overflow

when you have a recursive function, if some data not complete or this recursive function not well designed, it would make looping forever, it will make stack overflow and you will get (in .net 1.1) System.OutOfMemoryException. Bottleneck also can raise stack Overflow

4. Stack Corruption

When code writes beyond a buffer on the stack and overwrites other value on the stack

This is some trouble that i found in project. I hope we more carefull to wrote code so this problem would not rise in production anymore. Hope so.

Saturday, February 23, 2008

SQL Server Tips - How to improve your tempdb performance

Tempdb is used for sorted data, temporary object (such as tables, stored procedures or cursors), indexes if the option of SORT_IN_TEMPDB is specified and transaction isolation level snapsnot. tempdb is re-created every time SQL Server is started so that the system always starts with a clean copy of the database. Temporary tables and stored procedures are dropped automatically on disconnect, and no connections are active when the system is shut down. Therefore, there is never anything in tempdb to be saved from one session of SQL Server to another. You can improve it by using these methods :

  • Tempdb has to reside in separate disk with primary files, data files and log files. put them to a fast I/O to guarantee good performance. You can use this code to move tempdb data files to other location.

    USE master;
    GO
    ALTER DATABASE tempdb
    MODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf');
    GO
    ALTER DATABASE tempdb
    MODIFY FILE (NAME = templog, FILENAME = 'E:\SQLData\templog.ldf');
    GO

    verify the changes using this query :
    SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('tempdb');
    GO
  • Increase the number of data files in tempdb to maximum disk bandwith and reduce contention in allocation structures.- Set the file growth increment percentage to a reasonable size to avoid the tempdb growing by small value.
  • Implement trace flag -T1118. Under this trace flag, SQL Server allocates full extents to each database object, thereby eliminating the contention on SGAM pages.
  • Examine the query plans of the queries associated with the user session. If the amount of tempdb space used by a query is higher than expected, try to modify the query to minimize tempdb usage. For example, an index may be missing, or the query may use a cursor and could be rewritten to use a set-based statement instead.

Introducing Deterministic and Nondeterministic Functions on SQL Server

SQL Server marks a function as deterministic when it returns the same result any time it is called with a spesific set of input values. it also marks a function nondeterministic when it returns different results each time it is called with a specific set of input values. You can create an index on a computed column if a function is deterministic. This means whenever the row is updated, the index will be updated as well, and you could gain a lot of query performance when using the function in a query expression.

SQL Server user-defined functions are deterministic when they're the following:- Schema bound- Defined with only deterministic user-defined or built-in functions. The following are the example of deterministic functions :

  • DATEDIFF
  • ABS
  • CEILING
  • DATALENGTH
  • ISNUMERIC
  • ROUND
  • ISNULL
  • NULLIF
  • FLOOR

The following are the example of nondeterministic functions :

  • GETDATE
  • NEWID
  • RAND
  • @@CONNECTIONS
  • @@TOTAL_WRITE
  • @@TOTAL_READ
  • @DBTS
  • @@IDLE

Calling Extended Stored Procedures from functions

Functions calling extended stored procedures on SQL Server are nondeterministic, because the extended stored procedures can cause side effects on the database. Side effects are changes to a global state of the database, such as an update to a table, or to an external resource, such as a file or the network. For example, modifying a file or sending an e-mail message. You should not rely on returning a consistent result set when executing an extended stored procedure from a user-defined function. User-defined functions that create side effects on the database are not recommended.

SQL Server Best Practice - Database Option

AUTO_SHRINK

Frequently shrinking and expanding a database can lead to physical fragmentation. We recommend you to set the AUTO_SHRINK database option to OFF. If you know that the space that you are reclaiming will not be needed in the future, you can reclaim the space by manually shrinking the database.

AUTO_CLOSE

The AUTO_CLOSE database setting can cause performance degradation. This is caused by the increased overhead of opening and closing the database after each connection. AUTO_CLOSE also flushes the procedure cache after each connection. We recommend you to set the AUTO_CLOSE option to OFF for the database if a database accessed frequently.

PAGE_VERIFY

When CHECKSUM is enabled for the PAGE_VERIFY database option, the SQL Server Database Engine calculates a checksum over the contents of the whole page, and stores the value in the page header when a page is written to disk. When the page is read from disk, the checksum is recomputed and compared to the checksum value that is stored in the page header. This helps provide a high level of data-file integrity. Wer recommend you to set the PAGE_VERIFY database option to CHECKSUM.

Max Degree of Parallelism

This rule determines whether the max degree of parallelism (MAXDOP) option for a value greater than 8. Setting this option to a larger value often results in unwanted resource consumption and performance degradation. We recommend you to Set the max degree of parallelism option to 8 or less by using sp_configure. Here it is:

sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
sp_configure 'max degree of parallelism', 8;
GORECONFIGURE WITH OVERRIDE;GO

Auto Update Statistic

SQL Server uses the statistic to optimize the query, which is the statistic is up-to-date. Thereby it can make the smart query optimization decisions to generate query. Using the Auto Update Statistic ON can make your statistic always up-to-date, so SQL Server can uses the statistic for optimize the query. And also Turn Auto Update Statistic ON has a drawback, where it is running when your server has a heavy load data. Thus, your server performance will fall-down. Sometimes you should turn OFF the option to better performance. We recommend you to investigate first before decide the options. But as a rule of tumb, if your server is not maxed out, then leaving this option ON is probably the best decision.

Default Trace Log Files

This rule checks the value of the sp_configure option, default trace enabled, to determine whether default trace is turned ON (1) or OFF (0). When enabled, default tracing provides information about configuration and DDL changes to the Database Engine. Use the sp_configure stored procedure to enable tracing by setting the value of default trace enabled to 1. Here it is:

sp_configure 'default trace enabled', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO

AWE Properties

When you are running SQL Server under stress conditions, an instance of SQL Server might exhibit unpredictable behavior. This problem occurs when you use the Intel Physical Addressing Extensions (PAE) specification. The PAE specification is a 36-bit physical addressing mode. This problem occurs even if you do not turn on the Address Windowing Extension (AWE) option to address large memory. Enabling AWE properties will helps SQL Server to allocate memory themself. We recommend you to set memory 4 GB (6 GB for total) at minimum server memory and maximum server memory.

Present Continous, Present Simple, Future Continous and Future Perfect

Today i write english grammar about present continous, present simple, future continous and future perfect. basically, these grammar is used very often. Now i am improving english grammar about these topic. So, if i have a mistake, please fill the comment.

Present Continous (I am doing)

We use present continous when we talk about something which is happening at the time of speaking.

  • Please don’t make so much noise. I’m studying.
  • Are you enjoying the party?

We use present continous when we talk about somethin which is happening arround the time of speaking.

  • I’m reading an interesting book at the moment. I’ll lend it to you when I’ve finished it.(= he is not reading at the time of speaking. He means that he has begun the book and hasn’t finished it yet).

We often use present continous when we talk about a perod around the present (today, this season, etc).

  • Tom isn’t playing football this season. He want to concentrate on his studies.
  • You’re working hard today.

We use the present continous when we talk about changig situations.

  • You’re English is getting better.

Present simple (I do)

We use the present simple to talk about things in general, something happens all the time or repeatedly, or something is true in general. It is not important wheter the action is happening at the time of speaking.

  • The earth goes round the sunI work in a bank.
  • Barry works in a shop.

We use do/does to make questions and negative sentences.

  • Do you speak English?
  • Rice doesn’t grow in Britain.

Future continous (will be doing) and future perfect (will have done)

Situations: There is a footbal match on televiion this evening. The match begins at 07.30 and ends at 9.15

We use will be doing to say that we will be in the middle of doing something at a certain time in the future.

  • Is it all right if I come at about 8.30? No. don’t come the. I’ll be watching the footbal match on television.

We use will be doing when we talk about things which are already planned or decided.

  • I’ll be going to the city center (=similar with I am going to the city center).
  • Will you be using your bicylce this evening?

We use will have done to say that something will already have happened before a certain time in the future.

  • Oh, Well. What about 9.30?Yes, that’ll be fine. The match will have finished by then.
  • Next year is Ted and Amy’s 25th wedding nniversary. They will have been married for 25 years. (= now they have been marreid for 24 years).

The Modal Verb - Must

Must is a modal verb of obligation and necessity. We can also use have to for obligation and necessity.For example :- You must study hard if you want to do well. (Personal obligation)- You have to wear uniform at many schools in England. (Exteranal obligation, a rule or a law)
In the negative, however, the meanings are completely different.

For example :

  • You mustn't smoke here (Mustn't means that it is forbidden. it isn't allowed).
  • You don't have to come if you don't want to. (Don't have to means that it is not neccesary).

If we want to talk about obligation and necessity in the past or the future, we have to use a suitable form of have to:

For example :

  • We have to cancel tommorow's meeting (Future)- We had to cancel yesterday's meeting (Past).
  • We have had to cancel all meetings this week (Present Perfect).


Question And Answer

1. In Britain you have to/mustn't wear a seatbelt when you're in a car.

2. You don't have to/mustn't park hear. It is not allowed.

3. You really must/have to talk to Jim. He's so upset.

4. Yester day I've had to/had to wait almast an hour for my bus. I was furius.

5. If you want to catch the early train tomorow morning, you'll have to/musn't get up at 6 am.

Thursday, February 21, 2008

PostNuke Installation

Several months ago I heard that a friend of mine use a Content Management Support (CMS) to build website. I felt curious but it was only in my mind because I didn't have much time to explore.

3 days ago i installed what is so called PostNuke. It is a CMS based on Php. I have WampServer in my computer. WampServer consist of Apache, Php and MySQL. They are required to use PostNuke.

1. The first thing to do is downloading Postnuke from Download Page of PostNuke Website. I choose Latest Stable Release and I download PostNuke-0.764.tar.gz. You can also download PostNuke-0.764.zip. The link is http://noc.postnuke.com/frs/?group_id=5&release_id=700

2. Extract PostNuke tar.gz or zip file to document root of Apache. I used WinRAR.

3. Install PostNuke by accessing install.php in PostNuke directory.In installation process there will be setting to access MySQL database, its host (usually localhost), username, password and
database name. If you have other web server such as IIS, oftenly you change port setting of Apache. For example if you set to 8080, your host is localhost:8080. Follow all instruction given. After it finish, PostNuke will be ready to use. In my computer PostNuke is accessed through
http://localhost:8080/postnuke/index.php

There are many system modules inside, consist of Administration module, Admin Messages, Groups, Mailer etc. There are also Content modules to add comments, downloadable files, Polls, News etc. Now it's time to explore!

Windows XP stuck on Mup.sys

It has been a month since my friend's daughter asked me to repair her computer. At the time she said that first of all her computer was attacked by virus. Her friend divided the hard drive storage into two partition to save the data and made new installation of Windows. When Windows installation was loading, it stuck and the system hang. They don't know how it happen then they brought the computer to me.

My first try was switching the hard drive to my computer and reinstall Windows. It worked. But putting back the hard drive to her own computer result in the stuck problem when loading Windows. So I used safe mode. When it called for drivers, it stucked again on Mup.sys. I switched again the hard drive, placing my hard drive on her computer but it was still in problem. I suppose there was a driver which could not be loaded after Mup.sys. Then I checked any
cards and cables, making sure that everything fit well in their place. The result was the same.

My first try was failed. The next day I searched on internet about the problem. I found that many people has the same problem. Most of them agree that the problem is related with hardware. There are many suggestion given, i.e

- replacing power supply due to failed voltage supplying
- resetting BIOS
- removing USB device, etc

The links are
http://www.aitechsolutions.net/mupdotsysXPhang.html
http://www.computing.net/windowsxp/wwwboard/forum/97354.html
http://www.cyberiapc.com/forums/index.php?showtopic=5288

I tried any advice given one by one. Now it has been a month and I still could not fix the computer. Ugh, I will search again on internet but I would be glad if you guys have any suggestions to do.

Maintaining Index on SQL SERVER 2005 - Part 2

If your database has a lot of transaction, the index is fragmented obviosly. And then your database performance is going to slow. So, to overcome the problem, you must maintain your index periodically. Rebuild and Re-organize index might help you to goback to top performance of your database. I have tried and experienced for altering index. That was amazing, cause it helped to boost my database performance.

Rebuild vs Re-organize

What's the difference of these two methods? they are look like the same things but they don't. We use Rebuild Index when the index has more than 30% data is fragmented, and we use Re-organize index when the index has less than 30% data is fragmented. You can see the fragmented index at DBCC SHOWCONTIG (@TABLENAME) or SELECT *FROM sys.dm_db_index_physical_stats(db_id(),Object_ID(N'contracts'),NULL, NULL, 'limited')
For example :

-- Rebuild Index
ALTER INDEX IX_ACCRUED_INCOMES_3 ON
ACCRUED_INCOMES
REBUILD WITH (FILLFACTOR = 80, SORT_IN_TEMPDB = OFF, STATISTICS_NORECOMPUTE = ON)

-- Reorganize Index
ALTER INDEX IX_ACCRUED_INCOMES_3 ON ACCRUED_INCOMES REORGANIZE

Now, I have scheduled the index maintenance daily (i created a job that run at night -SQL Server Idle-), but if you wanna run (index maintenance) the job at the busy time , i suggest you to add options ONLINE = ON. therefore your table can be accessed although the table is locking by maintenance index performance.

RAID Strategy on SQL Server

Using RAID (Redundant Array of Inexpensive Disks) can be ensure the reliability and consistency of your database. Each of this RAID has a feature and drawback. Thus, we must analyze first before we decide to use RAID. As per usual, one of database has many filegroup (Best Practice is split up Primary Filegroup, Data filegroup, Index filegroup and log filegroup) and we can put it into RAID that can give you the best performance.

RAID 0

RAID-0 uses disk striping; that is, it writes data across multiple hard disk partitions in what is called a stripe set. This can greatly improve speed because multiple hard disks are working at the same time. You can implement RAID-0 through the use of Windows Server software or third-party hardware. Although RAID-0 gives you the best speed, it does not provide any fault-tolerance. If one of the hard disks in the stripe set is damaged, you lose all of your data. Because of the lack of faulttolerance, Microsoft doesn’t recommend storing any of your SQL Server data on RAID-0 volumes.

RAID 1

RAID-1 uses disk mirroring. Disk mirroring actually writes your information to disk twice— once to the primary file and once to the mirror. This gives you excellent fault-tolerance, but it is fairly slow, because you must write to disk twice. Windows Server allows you to implement RAID-1 with a single controller, or you can use a controller for each drive in the mirror, commonly referred to as disk duplexing. This is the recommended place for storing your transaction logs because RAID-1 gives fast sequential write speed (writing data in sequence on the disk rather than jumping from one empty spot to the next), a requirement for transaction logs.

RAID 5

RAID-5—striping with parity—writes data to the hard disk in stripe sets. Parity checksums will be written across all disks in the stripe set. This gives you excellent fault-tolerance as well as excellent speed with a reasonable amount of overhead. You can use the parity checksums to re-create information lost if a single disk in the stripe set fails. If more than one disk in the stripe set fails, however, you will lose all your data. Although Windows Server supports RAID-5 in a software implementation, a hardware implementation is faster and more reliable, and we suggest you use it if you can afford it. Microsoft recommends storing your data files on this type of RAID because data files require fast read speed as opposed to transaction logs, which need fast write speed.


RAID 1+0

You should use RAID-1+0 (sometimes referred to as RAID 0+1) in mission-critical systems that require 24/7 uptime and the fastest possible access. RAID-10 implements striping with parity as in RAID-5 and then mirrors the stripe sets. So, you get the incredible speed and faulttolerance, but RAID-10 has a drawback. With this type of RAID you get the added expense of using more than twice the disk space of RAID-1. Then again, we are talking about a situation that can afford no SQL Server downtime.


I have tried to use RAID 1+0 (4 Disk) in my server, (before i implement this RAID, i was using RAID 5). After Raid 1+0 was implemented, my server can boost performance. That was amazing. you should try for RAID 1+0, if you can't afford that, use RAID 5 and RAID 1 combination.

Wednesday, February 20, 2008

Maintaining Index on SQL SERVER 2005 - Part 1

Indexing can perform your database faster, but sometimes it's make your database slower. It is caused using index make your database faster within searching data and slower within insert or update data. So you need to be analyze the index if you want to implement or not. if you've had index that reasonable so you have to maintain it whether it is uses or not.

Use this query to find your useless or uses index :

Declare @tablename varchar(200)
    ,@indexName varchar(500)
    ,@indexColumn Varchar(500)

CREATE TABLE #INDEX_TEMP_STATISTICS
(
    alldensity numeric(29,10),
    averagelength numeric(29,6),
    columns varchar(500)
)

CREATE TABLE #INDEX_STATISTICS
(
    tablename varchar(200),
    indexname varchar(500),
    alldensity numeric(29,10),
    averagelength numeric(29,6)
)

SET NOCOUNT ON
SET ANSI_WARNINGS OFF

DECLARE C_CURSOR CURSOR FAST_FORWARD FOR
    SELECT
        o.name,
        i.name,
        RTRIM(LTRIM(ISNULL(MIN (CASE ik.keyno WHEN 1 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 2         THEN c.name END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 2 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 3 THEN c.name         END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 3 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 4 THEN c.name         END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 4 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 5 THEN c.name         END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 5 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 6 THEN c.name         END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 6 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 7 THEN c.name         END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 7 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 8 THEN c.name         END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 8 THEN c.name END),'') + (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 9 THEN c.name         END),'T') = 'T' THEN '' ELSE ',' END) +
        ISNULL(MIN (CASE ik.keyno WHEN 9 THEN c.name END),'') +
        ISNULL(MIN (CASE ik.keyno WHEN 10 THEN c.name END),'')))
FROM sysobjects o
    JOIN sysindexes i ON i.id = o.id
    JOIN sysindexkeys ik ON ik.id = i.id
        AND ik.indid = i.indid
    JOIN syscolumns c ON c.id = ik.id
        AND c.colid = ik.colid
    JOIN INFORMATION_SCHEMA.TABLES IFT ON IFT.table_name = o.name
        AND IFT.table_type = 'BASE TABLE'
WHERE i.indid BETWEEN 1 AND 254
    AND indexproperty(o.id, i.name, 'IsStatistics') = 0
    AND indexproperty(o.id, i.name, 'IsHypothetical') = 0
--And o.name = 'Addresses'
GROUP BY o.name, i.name
ORDER BY o.name, i.name

OPEN C_CURSOR

FETCH NEXT FROM C_CURSOR INTO @tablename,@indexName,@indexColumn

WHILE @@FETCH_STATUS = 0
BEGIN
    INSERT INTO #INDEX_TEMP_STATISTICS
    EXEC ('DBCC SHOW_STATISTICS (''' + @tablename + ''',' +     @indexName + ') WITH density_vector,NO_INFOMSGS')

    INSERT INTO #INDEX_STATISTICS
    SELECT @TABLENAME,@INDEXNAME,
        ALLDENSITY * 100,
        averagelength
    FROM #INDEX_TEMP_STATISTICS
    WHERE [columns] = @indexColumn

    print @indexColumn

    DELETE FROM #INDEX_TEMP_STATISTICS

    FETCH NEXT FROM C_CURSOR INTO     @tablename,@indexName,@indexColumn
END

CLOSE C_CURSOR
DEALLOCATE C_CURSOR

SELECT * FROM #INDEX_STATISTICS
Order by tablename

DROP TABLE #INDEX_STATISTICS
DROP TABLE #INDEX_TEMP_STATISTICS

See the result ...

If the alldensity field > 10, i suggest that index must be dropped. I think it is useless, Cause Sql Server has a logic if the density of index higher than 10%, it uses table scans (I have read other references that density index higher than 15%). So the index is never uses. If you keep this index, it doesn't make your database performance better instead it getting worse and worse, like i said at the beginning, your INSERT or UPDATE performance will fall.

How to get indexes at Sql Server 2005 using query

I have query that make you easier to find index. here it is. I hope i would be able to help you to make easier.

SELECT
    o.name,
    i.name,
    RTRIM(LTRIM(ISNULL(MIN (CASE ik.keyno WHEN 1 THEN c.name     END),'') +
    (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 2 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 2 THEN c.name END),'') +     (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 3 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 3 THEN c.name END),'') +     (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 4 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 4 THEN c.name END),'') +     (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 5 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 5 THEN c.name END),'') +     (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 6 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 6 THEN c.name END),'') +     (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 7 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 7 THEN c.name END),'') +     (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 8 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 8 THEN c.name END),'') +     (CASE WHEN ISNULL(MIN (CASE ik.keyno WHEN 9 THEN c.name     END),'T') = 'T' THEN '' ELSE ',' END) +
    ISNULL(MIN (CASE ik.keyno WHEN 9 THEN c.name END),'') +
    ISNULL(MIN (CASE ik.keyno WHEN 10 THEN c.name END),'')))
FROM sysobjects o
    JOIN sysindexes i ON i.id = o.id
    JOIN sysindexkeys ik ON ik.id = i.id
        AND ik.indid = i.indid
    JOIN syscolumns c ON c.id = ik.id
        AND c.colid = ik.colid
    JOIN INFORMATION_SCHEMA.TABLES IFT ON IFT.table_name = o.name
        AND IFT.table_type = 'BASE TABLE'
WHERE i.indid BETWEEN 1 AND 254
    AND indexproperty(o.id, i.name, 'IsStatistics') = 0
    AND indexproperty(o.id, i.name, 'IsHypothetical') = 0

--And o.name = 'Addresses' -- specify your table
GROUP BY o.name, i.name
ORDER BY o.name, i.name

Wednesday, February 13, 2008

Modal verbs (Can,Could and May) - English Learning Lesson

The lesson today is about Modal verbs -Can, Could and May-. These sentences uses if you're asking someone to help you. Yup ... there it is ... I hope i wouldn't make mistakes. hehehe ...

Modal verbs -Can, Could and May- has the sama meaning if you ask somebody to help you. But the level is May (More Polite than two others), Could and Can.
For an example :
May
- May i smoke here ? (At the restourant) - you don't know who they are
- May i borrow your dictionary ? (At the library) - yup, same like at the restourant

Could and Can
- Could you help me ? - you're asking your friend to help you - your friend
- Can you give me some water, please ? - your friend too

May uses for stranger people, you want to be polite, don't you? so use May if you want to be polite for asking someone help. But use can if they are your friend.

Sometimes i am confused about Could and Can, but today i don't want to figure out more further. Next time maybe i could give an example.

What About + Verb + ing - English Learning Lesson

Ok, these day we learn english about "What about ... " sentences. Yesterday i have already attend the encounter class at wallstreet and the exams was about "What about" sentences. I will try to explain that thing. You could see this lesson at Wallstreet Insituate Unit 17 - Waystage Level.

When we use sentences "What about ... ", use verb + ing after sentences "what about ...".
For an example :
- What about GOING to shop ? - Not this time, i don't have money right now.
- What about PLAYING the video games ? - That's a good idea.
- What about WATCHING movie ? - That's Great. Which movie are we going to watch ?

Yup.. that's from me, i could have learned about this lesson yesterday before the encounter class began but i didn't. So i learned it one more time.

My first Encounter Class at Wallstreet Institute

Yesterday was my first encounter class. i was so excited but i am a little nervous. The Class had three students -One student didn't show up- and one native teacher. The native teacher name is Kristy, she comes from canada -wow, far away from here-. At the encounter class we was talking about the story of unit and grammar. The grammar focuses on "What About ...", Modal verbs (Can, Could and May) and also present tense using yet and already.

She said i was exellent at grammar and vocabulary -wow, that's surprising, because i fell i haven't been excellent for grammar and vocab- and i want to learn more english very often right after this. I hope to the next encounter class i could be talking with native teacher fluently.

I have already booked for the next encounter class, it will be Feb, 29. But i want to reschedule that because i have thought that i can't attend for the encounter class that day. i must go to outside jakarta - my wife will be engender -. And also i have already booked for the complementary class. it will be Feb, 23. Actually, i haven't joined the complementary class. that is my first time to join it.

Supernatural Season 2 - In my time of Dying

At the end of Seasion 1, John, Dean and Sam has been able to escape from demon's
attack. but they have an accident, The truck driver has been possesed by the demon.
and crash to Dean's mobile. John and dean is unconscious and they've got to the
hospital.


Meanwhile, Dean has been awake from his unconscious. he walks through the hospital
and feels like nobody else can't see him - he thinks he was able to escape from the
demon and the accident. Apparently, he don't know about his condition. He is dying,
and bed-rest in the room. John winchester has had a plan to Dean and Sam, so he
summons the Demon to make a Deal - His life and colt for Dean's Dying.


Right after that, John is dead in his room at the hospital. Time of Death 10.14 PM

Tuesday, February 12, 2008

Supernatural Season 1 - Finish

Sam and Dean meet John Winchester and he said that there is a colt which could kill anything, and also the Demon. So they are searching for the Colt - Made by Samuel Colt -. After they have it by fighting with vampire, Sam - who have the ability to figure out what will be going on - have a nightmare about the Demon will come tonight.

They have been waiting for a couple hours and then the sign is coming. They run to hunting that things but, they can't kill it. The next day they have known his father - John Winchester - has kidnapped by the Demon. and he wants exhange with the colt.
After Sam and Dean searching his father, Dean has already known is possesed by the Demon and wants to take the colt. And the fighting begin but the demon is able to escape.

Supernatural Session 1

Have you seen Supernatural TV Series ? that's fascinating. There's a lot of Demon or Ghost around the movie. The movie is started when Winchester kids, Sam was infant and Dean was a 4-year-boy. They mother was killed by demon, but they and their father - John Winchester -was able to escape. That day urge their father to "Hunting things", and Sam and Dean is equiped to hunting demon too. They want to revenge about mary's death.

But, in sam is age 22, sam want to "Normal Life", having a girlfriend, Getting school until their father is missing and Dean come to sam estrangement. he wants sam come to search their father, But Sammy only want onces cause he has had an interview next week on oxford University, And Dean agree with that. Right after that - After this two-brothers hunting the Demon, Sam's girlfriend was found dead at his room. Sammy was angry and he is coming with Dean to hunting these Demon.