Download SQL Server 2008 Samples

Now we have a new location for SQL Server 2008 Samples. The new location is on the codePlex web site. Please find the below link to download the SQL Server 2008 Samples
http://sqlserversamples.codeplex.com/Wikipage

Quickly :
Download AdventureWorks Family Database:
http://msftdbprodsamples.codeplex.com/releases/view/37109
Download All the samples together without AdventureWorks
http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=SqlServerSamples

Happy Learning !!!

Support for DTS in SQL Server 2008

As we all know that SQL Server 2000 Data Transformation Services is already deprecated but SQL Server 2008 still supports DTS (Limited Functionality). SQL Server 2008 provides optional 32 bit management, run-time, and design-time support for packages that were created by using the DTS tools and object model.

Note:

  1. Please note that not all the functionality of DTS is not supported in SQL Server 2008.
  2. To get the DTS support in SQL Server 2008 you might have to manually install additional, optional components that are not available during setup.

For more information on which are the functionalities of DTS is supported in SQL Server 2008, please visit the below link

http://msdn.microsoft.com/en-us/library/bb500440(v=SQL.105).aspx

Happy Learning !!!

Download BI Architecture and Design Guide – Microsoft Business Intelligence

Today, I came across very useful design guide for Microsoft BI and thought to share with the readers.
This guide is available for download on CodePlex.com. It contains following chapters.

  1. BI Framework
  2. Data Extraction
  3. Data Staging
  4. Data Transformations and Data Quality
  5. Data Loading
  6. Dimensional Modeling
  7. Data Partitions
  8. Online Analytical Processing (OLAP)
  9. Data Mining

Please visit : http://biarchanddesignguide.codeplex.com/ for more information on the design guide and to download the material.

Happy Learning !!!

Get the list of all the constraints in a table in SQL Server

Often we think of How to get a list of all the constraints in a table. The below post answers that question. We can make use of INFORMATION_SCHEMA views to get the details of the meta data in SQL Server.

    • INFORMATION_SCHEMA view is contained in each database.
    • Each INFORMATION_SCHEMA view contains meta data about each object stored in that particular database.
      • information schema views are defined in a special schema named INFORMATION_SCHEMA.

The below query will list all the details about the meta data available in that particular database.

SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS;

For example the above query will give you the below output i.e. List of all the constraints in a particular database. You can even filter data by specific constraint type , schema name, table name etc.

 

image

Example 2: List all the constraint in a table Employee under Schema STTest.
Answer: Following query will result the correct answer

SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS

WHERE TABLE_NAME =‘Employee’ AND TABLE_SCHEMA =‘STTest’;

 

image

Note: Here TABLE_CONSTRAINTS is a view defined in a special schema named INFORMATION_SCHEMA.

Happy Learning !!!

Choose the right SQL Server 2008 Editions

Which edition of SQL Server 2008 is right for me? – The below page answers exactly the same.

http://www.microsoft.com/sqlserver/2008/en/us/editions.aspx

Also visit the below link to understand the components available in the various SQL Server 2008 Editions.

http://msdn.microsoft.com/hi-in/library/ms144275(en-us).aspx

How to Get the Current Database Name, Database ID in SQL Server

The DB_NAME() function returns the current database name. You can use this in the following way.
 

SELECT DB_NAME();

Get Database ID: The DB_ID() function returns the database ID for the given database name. You can use this in the following way.

Syntax : DB_ID([‘database name’]) 

Example:

SELECT DB_ID(DB_NAME());

 

What is Package in SSIS?

Let’s understand the basics of Package in SSIS. This could also be a good interview question for SSIS.

  • A package is a unit of work that is retrieved, executed and saved.image
  • It’s a collection of various objects i.e. Control Flow elements, data flow elements,event handlers, variables, logging which together builds a package.
  • Various functionalities can be added into package using Control Flow elements, Data Flow elements.
  • We can set the security settings on the package.
  • We can also incorporate transactions in packages to better control the package execution.
  • Using connection managers in package helps us to connect with different data sources to extract and load data.
  • Logging in packages allows us to better control the package execution and also enables efficient error handling.
  • Event handlers handles the events raised during the package runtime.

 

Happy Learning !!!

What is LineageID in SSIS?

Let’s understand about LineageID property in SSIS

  1. LineageID is a very important property in SSIS packages.
  2. Every column used in dataflow has atleast one LineageID.
  3. It’s an integer value which identifies the column in the buffer.
  4. A column can have more than one LineageID and this is based on the types of transformation outputs  the column has (or passes through) in the data flow.

Below is the image of column properties in ADO.NET Source – Advanced Editor (right click on the ADO.NET Source in Data  Flow task and select Show Advanced Editor)

Image : 1

image

 

Image 2:  How to open Advanced Editor for ADO.NET Source (in Data Flow Task)

image

 

Happy Learning !!!

Delete duplicate records from a SQL Server table

Today one of my colleague asked me how to delete duplicate records from a SQL Server Table. So to answer his question, let’s check the following example.

Note: The below example works on SQL Server 2005 and later versions.

–Create Table

CREATE TABLE dbo.TestDuplicate (EmpNo INT, EmpName VARCHAR(10));

–Insert Test Data

INSERT INTO dbo.TestDuplicate VALUES (1,‘Emp 1’);

INSERT INTO dbo.TestDuplicate VALUES (1,‘Emp 1’);

INSERT INTO dbo.TestDuplicate VALUES (2,‘Emp 2’);

INSERT INTO dbo.TestDuplicate VALUES (2,‘Emp 2’);

INSERT INTO dbo.TestDuplicate VALUES (3,‘Emp 3’);

–Remove Duplicates

WITH CTE
AS (SELECT ROW_NUMBER () OVER (ORDER BY EmpNo) SrNo , EmpNo FROM dbo.TestDuplicate)
DELETE FROM CTE WHERE SrNo NOT IN (SELECT MAX(SrNo) FROM CTE GROUP BY EmpNo);

–Check the table

SELECT * FROM dbo.TestDuplicate;

— Data before deleting the duplicate records.

image

— Data after deleting the duplicate records.

image

Points to Note:

  1. This was possible because of the ROW_NUMBER() function available in SQL 2005 onwards.
  2. ROW_NUMBER() function Returns the sequential number of a row within a partition of a result set. This means for each row in a result set it will return one unique sequential number for that row.
  3. The OVER clause determines the partitioning and ordering of the row set.
  4. As we have used CTE (Common Table Expression) it allows us to reuse the result set like a temporary table.

Hope this article may help you in deleting the duplicate records.