Archive for September, 2008

SQL 2008: Trace process in activity monitor

September 30, 2008

In SQL Server 2008 when we open activity monitor we can see SPID and information related for that SPID . But what if we want to get detail information for that SPID.

In SQL Server 2008 MS has provided a easy way for this , when we right click on this process , menu has one more option available “Trace Process in SQL Server Profiler”.
So it will directly open profiler ,filter it for that SPID and start to trace this SPID. This can be handy many times for trouble shooting or monitoring activity for selected SPID

Cheers

Alter table rebuild option for data_compression

September 9, 2008

For table which one is stored as a heap we can now reclaim free space from this tables using alter table rebuild option.
lets see

use test

CREATE TABLE tbl
    (
         id   INT IDENTITY (1, 1),
         data VARCHAR(100)
    )
DECLARE @i INT
SET @i = 1
WHILE @i <= 10000
    BEGIN
        –delete top (1) from test
        INSERT INTO tbl
        VALUES     (‘a’)
        SET @i = @i + 1
    END
DBCCupdateusage (‘test’, ‘tbl’)
EXEC Sp_spaceused tbl

name rows reserved data index_size unusedtbl 10000 136 KB 120 KB 8 KB 8 KB

Now delete 5000 rows from this table.

set @i = 1
while @i <= 5000
begin
delete top (1) from tbl
set @i = @i + 1
end

dbcc updateusage (‘test’,’tbl’)
exec sp_spaceused tbl

name rows reserved data index_size unused
tbl 5000 136 KB 120 KB 8 KB 8 KB

We can see the space is not free after delete operation completed

Now we will compress the table.

ALTER TABLE tbl
REBUILD WITH (DATA_COMPRESSION = page);

exec sp_spaceused tbl

name rows reserved data index_size unused
tbl 5000 80 KB 64 KB 8 KB 8 KB

Now we can see the space is now return to the database.

* Similarly if the table has clustered index it will rebuild the clustered index during alter table rebuild operation

* While creating a table we can also specify data_compression option on the table.

create table tbl
(id int identity (1,1),
data varchar(100))
with (data_compression = row)

but on heap data compression will only work on
alter table rebuild , bulk_insert on insert into …. with (tablock) option

*If we have clustered index then we can also specify data_compression on index

create clustered index idx_clst on tbl(data) with (data_compression = row)

*data_compression has some limitation like size of row should not be more then 8060 bytes and some others but overall its a cool feature

Trigger on system tables

September 9, 2008

Lets say for example
If someone disable a job and forgot to inform other team members


If someone modify a package and save it in sql server but forgot to inform others
If someone add new job or modify schedule but forgot to inform other team members.
there are number of such scenarios….
In all this case if we can put a DML trigger on system tables like sysjobs,sysdtspackages which will fire a mail to other team members on data changes in this tables then I think we can better monitor our servers.

We can put triggers on this tables , but not sure in future hot packs or service packs this tables will be modified or not. so we are avoiding to put triggers on this tables.

If microsoft is supporting triggers on system tables then it will be definitely a great help for all of us and also can convince our clients also for this.

Whats new SQL Server Express 2008

September 1, 2008

We all know SQL Server Express 2008 is coming with many new features.
we can get some cool information for this from here

http://blogs.msdn.com/sqlexpress/archive/2008/06/10/sql-server-2008-express-rc0.aspx

Cheers


Design a site like this with WordPress.com
Get started