SQL Tips by Namwar Rizvi

April 5, 2010

Online Content Vacuum Technology in SQL Server 2008

Filed under: Information,SQL Server 2008 — namwar @ 9:06 PM
Tags: ,

As per SSWUG.org reports in their newsletter, Microsoft has announced an excellent and cool feature for Data Mining lovers. It is Online Content Vacuum Technology. Following is the announcement from Microsoft:


SEATTLE, WA – Microsoft today announced that the next release of SQL Server would include a new data scraping and categorizing utility, code-named “Vacuum” in the next CTP release of SQL Server.  The functionality allows SQL Server to apply its world-class search technologies to content found on the web, and allows companies to “bring the cloud” down to their local networks for searching.

“This technology will be key to using many of the vast resources that are simply too tough to navigate, too tough to find what you need in today’s world,” says Steve Ballmer, Microsoft CEO.  “The Internet and social networks, blogs and other resource represent the biggest form of business intelligence resources available, but incorporating them into your work is difficult.  By using Vacuum, you simply identify the root sources of information you trust and let SQL Server pull in and categorize information for you automatically.  From there, use the new features of SQL Server 2008 R4.1 to query, report on and learn from all of those sources.  It’s what business intelligence needs to be to really enhance your ROI.”

By using Vacuum, users will be able to provide instant backup to the data represented in their systems.  At the same time, by pulling data from the cloud and bringing it onto the local network databases, companies can better control information presented, can update their databases and can avoid the abstract nature of working on the Internet.

“We’re excited to bring this announcement to the IT Professional community.  It’s clear that we can provide real value by automatically tying online resources to reports and other local resources for reporting.  We’ve been working very hard on the fact-recognition logic in SQL Server 2008 R4.1 so that it can relate information on your systems with information online, bringing the two together automatically,” said Donald Farmer of Microsoft.  “We spent a lot of time building out the great functionality in the PowerPivot toolset.  By adding this Vacuum tool to the mix, we’ll be able to back up any fact you may be looking to share, all automatically.  It’s simply incredible.”

The release of the Vacuum tools should be ready in the next CTP of SQL Server 2008 R4.1.

Advertisements

August 30, 2009

How to Query Active Directory (AD) from SQL Server

There can be a scenario where you will want to query Active Directory, directly from your stored procedure. This can be achieved by creating a linked server to your target Active Directory and then querying it through OPENQUERY functionality. Following is an example to achieve this:

Step 1: Add Linked Server for Active Directory

sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'

Step 2: Query the Active Directory

SELECT * FROM OpenQuery
(
ADSI,   --Name of the linked server for Active directory, created in step 1
'SELECT title, displayName, sAMAccountName, givenName, telephoneNumber, facsimileTelephoneNumber, sn   --Fields you want to retreive
FROM ''LDAP://DC=TestDomain''    --Name of your Active Directory Domain
where objectClass = ''User'''         --Type of objects you want to query e.g. User, Person etc...
)

NOTE: The order in which columns will return will be exactly reversed of what you mentioned in your query. For example, in above query we have mentioned 
title, displayName…….,facsimileTelephoneNumber, sn but the resultset will return as
sn,facsimileTelephoneNumber……,displayName,title.
There is no reason of this behaviour and it is just how Active Directory OLEDB Provider works.

January 20, 2009

TSQL Function to encode HTML Text

Filed under: Uncategorized — namwar @ 9:36 PM
Tags: , , , ,

While browsing through the Sharepoint content database, I found a very useful TSQL utility function which can be used in any application. This function encodes the given html so that it can be safely used in XML tags and other html rendering requirements.

Please note,  this function is originally provided in Sharepoint content database and I have just copied it because of its usefulness. PLEASE DO NOT CALL it directly from Sharepoint database as it is not recommended and supported by Microsoft. Just create this function in your own database and modify it as per your requirement.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
 go

CREATE FUNCTION [dbo].[fn_HtmlEncode](
     @Value nvarchar(1023),
     @PreserveNewLine bit)
 RETURNS nvarchar(4000)
AS
BEGIN
     DECLARE @Result nvarchar(4000)
     SELECT @Result = @Value
     IF @Result IS NOT NULL AND LEN(@Result) > 0
     BEGIN
         SELECT @Result = REPLACE(@ResultN'&'N'&')
         SELECT @Result = REPLACE(@ResultN'<'N'&lt;')
         SELECT @Result = REPLACE(@ResultN'>'N'&gt;')
         SELECT @Result = REPLACE(@ResultN''''N''')
         SELECT @Result = REPLACE(@ResultN'"'N'&quot;')
         IF @PreserveNewLine = 1
             SELECT @Result = REPLACE(@ResultCHAR(10), CHAR(10) + N'<br>')
     END
     RETURN @Result
END

January 15, 2009

How to use more than 4GB RAM on SQL Server?

SQL Server is an highly optimized and well tuned piece of code. It try to utilise Operating System resources as optimum as possible. Due to this, most DBA think that if they will increase RAM on the server then SQL Server will automatically start using it, right? Wrong, SQL Server can only use RAM more than 4GB if and only if,

  • You are running Enterprise Editions of Windows 2003 Servers orAdvanced/Datacenter version of Windows 2000
  • You have enabled Operating System to use the extra RAM you have installed. Please check here for the details and how to do it.
  • You are not running Express or Workgroup version of SQL Server. Please check here for further details about limitations in different versions of SQL Server
  • you have enabled awe enabled option and set max server memory to the maximum memory you can allocate to SQL Server. This is applicatiable for 32 but versions of OS and not required in 64 bit version of Windows servers. Please check here for further details and how to configure the memoryfor SQL Server

January 3, 2009

How to find relationship between tables

As a DBA or even as a SQL Server Programmer, you may need a quick script to find relationship between tables. I found a useful script to do that in a SQL Server newsgroup. With some minor update, here is the script which lists the name of the parent table, child table, Referred table, foreing key table and name of the foreign key constraint. I hope you will find it useful. All credit goes to original author.

Select

object_name(rkeyid) Parent_Table,

object_name(fkeyid) Child_Table,

object_name(constid) FKey_Name,

c1.name FKey_Col,

c2.name Ref_KeyCol

From

sys.sysforeignkeys s

Inner join sys.syscolumns c1

on ( s.fkeyid = c1.id And s.fkey = c1.colid )

Inner join syscolumns c2

on ( s.rkeyid = c2.id And s.rkey = c2.colid )

Order by Parent_Table,Child_Table

January 2, 2009

Two quickest ways to find file information of a given database

If you want to check the name of the files and their respective sizes for the given database then following are two quick tsql scripts:

1. Use sp_helpfile

This stored procedure returns the file information for the selected database e.g.

USE AdventureWorks;

GO

EXEC sp_helpfile;

GO

It will return the resultset similar to following

sp_helpfile

By default, this view returns a column called size but this is actually the size in 8KB pages therefore, to get the exact size in KB, as returned by sp_helpfile, multiply it by 8 as mentioned in above query.

August 28, 2008

Resource Governor in SQL Server 2008 – Beware of catches

Resource governor is one of the best additions in SQL Server 2008. It gives you a real control on your environment as a DBA and can be very useful for better utilization of your database server resources. So far so good, but don’t just start using it without knowing how it actually restricts resource utilization.  Following are some points to remember for better utilization of this feature:

  1. Normally, most of us assume that if we restricts a memory usage for a user A upto 10% only then he will never be able to utilize more than 10% of server in any case. Right? Wrong. Actually, Resource governer only restricts user to utilize not more than 10% if it feels that remaining memory is not available but if memory is available and there are no pending workload then it will allow the user to use more than its allowed quota of 10%. This is there to optimize the utilization of memory and avoids wastage of resources. But it can have worse effects also because if User A fires it query before other users then server will start utilizing all the available memory and all other users which came afterwards will suffer the consequences.
  2. Please note that Resource Governor is for database engine not for other services in SQL Server 2008. It means you can not control usage of Reporting Services, Analysis Services or Integration Services.
  3. If you have multiple instances running on same machine then you can not use Resource Governor to manage load between these instances.

Keeping these points in your mind will help you to better understand how to use resource governor and what to expect. It is one of the best tools to manage your load and highly recommended but make sure you know the pros and cons of it.

August 7, 2008

Welcome to SQL Server 2008

Filed under: Information,SQL Server 2008 — namwar @ 10:20 PM
Tags: ,

Finally, wait is over and just one day before start of 2008 Olympic, Microsoft has released SQL Server 2008. It is a big day as many of us were waiting for the final release to start taking architectural decision based on new technologies offered by SQL Server 2008. The 180 day trial version is available here
To start with, I will recommend to watch following videos covering disfferent aspect of technologies used in SQL Server 2008
SQL Server 2008 Demos and Videos
You can also check these Web Casts

In my next articles, I will try to cover some fundamental technological advancements in this version of SQL Server 2008.

Blog at WordPress.com.