Tuesday, February 14, 2012

Sql Server Shrink Log file

 

For a business Intelligence application, we used a sql server 2008 database for consolidating data from different sources, since data was imported, we didn’t need backup facility, so the database was kept in Simple Logged Mode.

In this blog we will see how to shrink the log files for a simple logged database.

IMPORTANT : Use this only for Simple Logged Databases

Use [DatabaseToShrink]-- Replace this with your simple logged database

Declare @FileId Int
select @FileId = FILE_ID from sys.database_files Where type_desc = 'LOG'

DBCC ShrinkFile(@FileId, 1)

select * from sys.database_files

Monday, February 6, 2012

Html content in RDLC Microsoft Reporting

 

We have been using microsoft reporting for generating itineraries, hotel vouchers etc in TourMast, the tour operator software. In this post i will explain how we display html content in some places:

Step 1:

Select the placeholder,

image
Right click and then select PlaceHolder Properties, you will get the following screen where you must select “HTML-Intepret HTML Tags as styles” in the Markup Type section

image
Reference:

http://stackoverflow.com/questions/3786884/visual-studio-2010-rdlc-support-for-html

Friday, January 27, 2012

Prevent duplicate rows using unique index

create table test(id int identity(1,1), name varchar(10))create
insert
unique index ix_test on test(name) with IGNORE_DUP_KEY into test(name)values('ppv')select * from test

Friday, January 6, 2012

Reenable sql server index

SELECT
'ALTER INDEX ' + I.name + ' ON ' + T.name + ' REBUILD ' FROM SYS.indexes I INNER JOIN SYS.tables T ON I.object_id = T.object_idWHERE I.name LIKE 'IX%'

Wednesday, January 4, 2012

Disable all indexes in sql server

For a data marting application being done @ SyneITY, we needed to disable all indexes in our Sql Server 2008 database. We used the following query to get this done

SELECT 'ALTER INDEX ' + I.name + ' ON ' + T.name + ' DISABLE ' FROM SYS.indexes I INNER JOIN SYS.tables T ON I.object_id = T.object_id


WHERE I.name LIKE 'IX%'

Saturday, December 24, 2011

Use unpivot to convert columns into rows


blog
In a previous blog we converted rows into columns using pivot, now this time i needed to convert columns into rows. This was simply achieved using the unpivot functionality in sql server.

declare @tbl table(name varchar(50), amt1 numeric(12,2), 
    amt2 numeric(12,2))
    
insert into @tbl(name, amt1, amt2)values('ppv', 1, 3)
insert into @tbl(name, amt1, amt2)values('ppvs', 41, 43)

select * from @tbl 

select * from @tbl unpivot
 ([Amt] for Types in (amt1, amt2)) as unpv
 
 
Credits:
Thanks to Sachin for this!!