Wednesday, 8 January 2014

Differences between SSIS 2005 & SSIS 2008 // SSIS 2005 Vs SSIS 2008




Character
SSIS 2008
SSIS 2005
1.       Scripting Engine changes
 SSIS 2008 uses VSTA (Visual Studio 2005 Tools for Applications) for scripting engine.
 SSIS 2005 uses VSA (Visual Studio for Applications) for scripting engine.

So we can write VB & C#  coding also in Scripting of SSIS Packages
2005 only enabled the users to write the scripts in only VB
2.       New Tasks
New Data Profiling Task & Viewer
Not there
3.       Enhancements( Lookup,

Enhanced Performance and Caching for the Lookup Transformation

4.       Enhancements @ Data Flow Task
Enhanced Data Flow Engine Tuned for Parallelism

5.       Excel enhancements
Importing Excel 2007 worksheets is native to SQL 2008
. In SQL 2005, you have to build a new connection based on the office 12.0 OLEDB client.
6.       Cache Enhancements
you can cache lookup data from any type of data source (not only an OLE DB source)(Named Cache)
you can cache lookup data from  only an OLE DB source
7.       Source & Destinations changes
SSIS 2008 now includes the ADO.NET source and destination components
The ADO.NET source replaces the DataReader source in SSIS 2005
8.       Data Type Changes
DT_DBTIMESTAMP2 is one of the new date/time data types supported in SSIS 2008.
These new types let you work with a wider range of date and time values than in SSIS 2005
9.       Look Up
2008 it has an additional feature “No match Out-Put” including Fail Component, Ignore Failure and Re-direct row
In 2005 for Error Output look-ups had only 3 options Fail Component, Ignore Failure and Re-direct row.


Changes in these Areas
·         Introduction
·         SSIS Architecture
o   ADO.NET
·         Data Integration
·         Moving Forward

How to get Non matching records from 2 tables in Sql Server



We are having 2 tables like below

select * from table_2

select * from Table_1


Now write the below queries:

1. (select table_2.id from table_2
except
select Table_1.id from Table_1)
union
(select Table_1.id from Table_1
except
select table_2.id from table_2)

OR

2. (select table_2.id from table_2
left join Table_1
on table_2.ID=Table_1.id)
union
(select Table_1.id from Table_1
left join table_2
on table_2.ID=Table_1.id)
except
(select Table_1.id from Table_1
 join table_2
on table_2.ID=Table_1.id)


Result is:




Sunday, 5 January 2014

Difference between SQL Server 2008 R2 and SQL Server 2012 // SQL Server 2012 Vs 2008 R2



What are the Difference between SQL server 2008 R2 (10.5) and SQL Server 2012 (11)?
(OR)
Difference between SQL Server 2008 R2 and SQL Server 2012

Character
Sql Server 2012
Sql Server 2008 R2
1.       Code Name
SQL Server 2008 R2 is codenamed as Kilimanjaro
SQL Server 2012 is codenamed as Denali
2.       New Functions
CONCAT(), FORMAT() and TRY_CONVERT() ,functions are not available in SQL Server 2012
CONCAT(), FORMAT() and TRY_CONVERT() functions are not available in SQL Server 2008 R2
3.       Concurrent Connection
SQL server 2012 has unlimited concurrent connections.
SQL server 2008 R2 has 32767 concurrent connections.
4.       Working with CONVERT(  )       and
FORMAT(  )  functions
SQL Server 2012 come up with new function FORMAT() same as .format() C# function for change the date/currency format etc.
This example displays the date in Taiwan format. Taiwan uses traditional Chinese characters.
DECLARE @date DATETIME = '12/21/2011';
SELECT FORMAT ( @date, 'MMMM dddd d', 'zh-TW' ) AS FormattedDate;

In US format
DECLARE @date DATETIME = convert(datetime,'2011/01/01 2:00:00');
SELECT FORMAT ( @date, 'yyyy/MM/dd hh:mm ss tt','en-US' ) AS FormattedDate;
Result
FormattedDate
2011/01/01 02:00:00 AM
CONVERT() function for convert date format. for that we need to memorizing cryptic style codes like 101 and 103 for converting datetime values to localized presentation formats.

CONVERT(DATETIME, '7/24/2010 12:00:00 AM', 101)
5.       Currency / Numbers
SQL Server 2012 have the solution for cast a money field, this is done by FORMAT() function
Example
Let's see some of the numeric formats that we can display using the FORMAT() function. Personally, I format numbers for currencies and number of decimal characters or for percentage. Here are some examples.

To display the number with currency using locale, use the following example.
Example 1:

DECLARE @money money = '125000';
SELECT FORMAT ( @money, 'C') AS MyMoney;
Result:
$125,000.00

There is no direct way to cast a money/currency field in SQL Server 2008
6.       Server Down
In SQL Server 2012, server down time is reduced by 50% , hence OS patching is not rebooting n times.
In SQL Server 2008 R2 , rebooting is requisite for OS patching , hence server down time is high.
7.       New  Objects
SQL Server 2012 has “SEQUENCE” as new Object
To create an integer sequence number that increments by 1 from -2,147,483,648 to 2,147,483,647, use the following statement.
SQL Server 2008 R2 has  no “SEQUENCE” Object

8.       IIF( ) Function
SQL Server 2012 has “IIF” as new Function
SQL Server 2008 R2 has no “IIF” Function






To create an integer sequence number that increments by 1 from -2,147,483,648 to 2,147,483,647, use the following statement.

CREATE SEQUENCE Schema.SequenceName
    AS int
    INCREMENT BY 1 ;
To create an integer sequence number similar to an identity column that increments by 1 from 1 to 2,147,483,647, use the following statement.

CREATE SEQUENCE Schema.SequenceName
    AS int
    START WITH 1
    INCREMENT BY 1 ;

Syntax:
CREATE SEQUENCE [schema_name . ] sequence_name
 [ AS [built_in_integer_type | user-defined_integer_type ] ]
 [ START WITH  ]
 [ INCREMENT BY  ]
 [ { MINVALUE [  ] } | { NO MINVALUE } ]
 [ { MAXVALUE [  ] } | { NO MAXVALUE } ]
 [ CYCLE | { NO CYCLE } ]
 [ { CACHE [  ] } | { NO CACHE } ]
 [ ; ]

Where:
Start with:             the initial value to start with sequence.

Increment by:       the step by which the values will get incremented or decremented.
Minvalue:              the minimum value of the sequence.
Maxvalue:             the maximum value of the sequence.
Cycle / No Cycle:  to recycle the sequence once it reaches to the maximum or minimum (if increment by is a negative number).
Cache / No Cache:  to pre-allocate the number of sequences specified by the given value.


Example: 

USE TempDB
GO
-- Create sequence
CREATE SEQUENCE dbo.SequenceID AS BIGINT
START 
WITH 3
INCREMENT 
BY 1
MINVALUE 1
MAXVALUE 5
CYCLE
NO CACHE
;
GO
-- Following will return 3
SELECT next value FOR dbo.SequenceID;
-- Following will return 4
SELECT next value FOR dbo.SequenceID;
-- Following will return 5
SELECT next value FOR dbo.SequenceID;
-- Following will return which number
SELECT next value FOR dbo.SequenceID;
-- Clean up
DROP SEQUENCE dbo.SequenceID;
GO




SQL Server 2008 R2 (SQL Server 10.5) :

1.SQL Server 2008 R2 is codenamed as Kilimanjaro
***2.In SQL Server 2008 R2 , rebooting is requisite for OS patching , hence server down time is high
3.SQL Server 2008 R2 does not have this feature of availability groups, hence fast recovery is not possible.
4.The SQL Server 2012 uses 48 bit precision for spatial calculations
5.CONCAT(), FORMAT() and TRY_CONVERT() functions are not available in SQL Server 2008
6.SQL Server 2008 R2 is slow compared to SQL Server 2012.
7.However buffer rate is less because there is no data redundancy in SQL Server 2008 R2
8.Data visualization is not supported in SQL Server 2008 R2
9.Spatial features are not supported more in SQL Server 2008 R2. Instead a traditional way for geographical elements have been set in SQL Server 2008 R2.
10.The Maximum number concurrent connections to SQL Server 2008 is 32767.
11. SQL Server have old CONVERT() function for convert date format. for that we need to memorizing cryptic style codes like 101 and 103 for converting datetime values to localized presentation formats
CONVERT(DATETIME, '7/24/2010 12:00:00 AM', 101)
12. There is no direct way to cast a money/currency field in SQL Server 2008

SQL Server 2012 (SQL Server 11) :


1.SQL Server 2012 is codenamed as Denali
2.In SQL Server 2012, server down time is reduced by 50% , hence OS patching is not rebooting n times.
3.In SQL Server 2012, high availability and disaster recovery factor has been introduced which duplicates the data and rapidly recovers the loss.
4.The SQL Server 2012 uses 48 bit precision for spatial calculations
5.CONCAT(), FORMAT() and TRY_CONVERT() functions are newly included in SQL Server 2012
6.In SQL Server 2012, the performance is 10 times faster than the predecessor.
7.Buffer rate is high in SQL Server 2012 because of data compression.
8.Data visualization tool is available in SQL Server 2012.This allows snapshots of data.
9.Support for persistent computed columns and extra geographical approach is possible with spatial features in SQL Server 2012.
10.SQL server 2012 has unlimited concurrent connections.

11. SQL Server 2012 come up with new function FORMAT() same as .format() C# function for change the date/currency format etc.
This example displays the date in Taiwan format. Taiwan uses traditional Chinese characters.
DECLARE @date DATETIME = '12/21/2011';
SELECT FORMAT ( @date, 'MMMM dddd d', 'zh-TW' ) AS FormattedDate;

In US format
DECLARE @date DATETIME = convert(datetime,'2011/01/01 2:00:00');
SELECT FORMAT ( @date, 'yyyy/MM/dd hh:mmConfuseds tt','en-US' ) AS FormattedDate;
Result
FormattedDate
2011/01/01 02:00:00 AM

12. SQL Server 2012 have the solution for cast a money field, this is done by FORMAT() function
Example
Let's see some of the numeric formats that we can display using the FORMAT() function. Personally, I format numbers for currencies and number of decimal characters or for percentage. Here are some examples.

To display the number with currency using locale, use the following example.
Example 1:

DECLARE @money money = '125000';
SELECT FORMAT ( @money, 'C') AS MyMoney;
Result:
$125,000.00

Here, I am getting the currency symbol ‘$’ because my current locale language setting is en-us. I could also display the currency ‘$’ explicitly by using the culture parameter as shown below.
DECLARE @money money = '125000';
SELECT FORMAT ( @money, 'C', 'en-US' ) AS MyMoney;
for more example http://www.databasejournal.com/features/...-2012.html

References http://onlydifferencefaqs.blogspot.in/20...8-and.html


Differences between Triggers & SPs / SPs Vs Triggers (not yet written)


Differences between Functions & Stored Procedures / Functions Vs SPs






Character
Stored Procedure
Function
How to call
1  Function is called using select statements.
1  Stored procedure can be called independently using EXEC or EXECUTE keyword
Return Value
2  Function must return a value(scalar, inline table or multi statement table)
2  Stored procedure may or may not return a value. 
Out Put Param
3  Cannot return output parameter
3  Can return output parameter
Table Variable
4  Can return Table variables.
4  Can create table but won’t return Table Variables
Joins
5  You can join UDF 
5  You cannot join SP
Server settings
6  Cannot be used to change server configuration.
6  Can be used to change server configuration
Transactions
7  Cannot have transaction within function
If you can’t modify anything, there’s no point in allowing transactions.
7  Can have transaction within SP
Calling each other
8  Only extended/system stored procedures can be called from a function. 
When you create a function, SQL server will allow you to call a procedure from the Function. However when you execute the function, it will error out with the message “Only functions and extended stored procedures can be executed from within a function”.
8  Stored procedures can call a function or another stored procedure
Working with
DML , SELCT statements
9 Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it.
9 Function allows onlySELECT statement in it.
  Can we use in SELECT Statement
      10 Procedures can not be utilized in a SELECT statement.
       10 Function can be embedded in a SELECT statement.
     Usage in Filter Stmts like WHERE/HAVING/SELECT
       11 Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section .
       11 Functions can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section.
        Exception Handling
      12 Exception can be handled by try-catch block in a Procedure.
    12 try-catch block cannot be used in a Function.
       TableVariables
        & TempTables
      13 We can use only table variables, it will not allow using temporary tables.
   13 Can use both table variables aswell astemporary table in it.
       Execution
 14Stored procedure can run independently. It can be executed using EXECUTE or EXEC command
 14 The function cannot run independently. It has to be the part of the SQL statement
Data types usage
15 Stored procedures can use all the data types available in sql server.
The parameters for the stored procedures can be any data types which are available on the sql server.
15 function cannot use the ntext, image and timestamp data types as return type.
The function won't allow several data types of the sql server as a parameter.

16 Stored procedures can create table variable and cannot return the table variable.
The table variable is one of the performances tuning mechanism. Because it takes minimum resources and it uses the memory location for store the data. (Recommended for minimum rows)
It can be created and do the operations. But it cannot be the return type.
16 function can create, update and delete the table variable. It can return table variable.
It can be created and can do all the DML operations and it can be the return type. That is called the multi valued table function.

17 Stored procedure can have the dynamic sql statement and which can be executed using sp_executesql statement.
The stored procedure can have the dynamic sql statement for the complex decision making operations which generated inside the stored procedures. It can be executed using the sp_executesql statement.
17 function cannot execute the sp_executesql statement.
The function can generate the dynamic sql statement. But it cannot get execute. It will not allow writing the sp_executesql command to execute the dynamically created sql statement.
Usage of GetDate()
18 Stored procedure allows getdate () or other non-deterministic functions can be allowed.

The stored procedure will allow all the sql server built-in functions like getdate(),DB_ID(),
DB_NAME (), etc..,
18 function won't allow the non-deterministic functions.
The function will not allow using non-deterministic functions like GETDATE ()



Diff b\w Stored Procedure and Function:-
1. Procedure can have both input\output parameters
But function can have only input parameter.



2. Inside procedure we can use DML (INSERT/UPDATE/DELETE) statements.
But Inside function we can’t use DML statements.



3. We can’t utilize stored procedure in Select Statement,
But we can use function in Select Statement.


















































4. We ca use Try-Catch Block in Stored Procedure,
But Inside function we can’t use Try-Catch block.




5. Procedure can return 0 or n values (max 1024),
But function can return only 1 value which is mandatory.


6. Procedure can’t be call from function,
But we can call function from Procedure.


7. We can go for 
transaction management in procedure,
But we can't go in function.


8. Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section 
But we can use Function anywhere.


9.We can’t join Stored Procedure,
But We can join functions.



Differences between Stored procedures and User defined functions
 Difference 1:
Stored procedure will be used for perform specific tasks

The stored procedure normally used to perform a speck task. The bulk of sql statement that that will be complied and it uses the cached execution plans. It can be return more than one result set.
Normally functions will be used for computing value
The functions are used to do the calculations instead of doing in the query. It can be used for many places if we want the same operation.     

Difference 2:


Stored procedures may or may not return values
The stored procedure based on query type it will do the operation. If we write any select query then it will return the results. If we do only update, insert or delete then it wont return any results. However if you want to check the confirmation of the transaction then we can return the result. It is not compulsory to return the result set.
But function should return value
The function must return the value. Based on the function type it will return the results.
If we have written scalar function then it returns single value. If we have written table valued function then it returns multiple rows. We cannot write the function without return any value to the calling program.
Difference 3:
Stored procedure cannot be used in the select/where/having clause
The stored procedure cannot be called like the following.

 SELECT * FROM Pr_RetrieveEmployees -- It will throws an error
It will throw an error. Similarly the stored procedure cannot be part the sql query any where.
But function can be called from select/where/having clause

The function can be called using the select query.
It can be called from the select/where/having clause.

For instance SELECT [dbo].fn_EmployeeSalary (5) ÃƒÆ’  it is scalar UDF. It returns single value.
                         SELECT * FROM fn_EmployeeHistory (3) ÃƒÆ’  its will return multi value.
Difference 4:
Stored procedure can run independently. It can be executed using EXECUTE or EXEC command
The stored procedure can run independently. Once the stored procedure is compiled then it can be executed. It can be executed using the sql command statement EXECUTE or EXEC.
EXECUTE proc_RetrieveEmployeeDetails EXEC proc_RetrieveEmployeeDetails proc_RetrieveEmployeeDetails
But function cannot run independently
The function cannot run independently. It has to be the part of the SQL statement.
Difference 5:
Temporary table (derived) cannot be created on function.

The temporary table cannot be created in the function. As you know if you create a temp table then it will be stored on the tempdb database. But the temp table won't allow us to create with inside the function

There are two ways to create the temp table.
       1. Create temp table
       2. Derived table

SELECT * INTO #tmpEmployee FROM Employees

The above statement is derived table. It cannot create on function.
But it can be created in stored procedures

The stored procedure allows us to create the temp tables in the stored procedure.
Difference 6:
From sql server 2005 onwards, TRY CATCH statements can be used in the stored procedures.
The TRY CATCH is one of the new features in the SQL server 2005 edition. It can be used with inside the stored procedure. As you know it handles the error in the catch block, whatever the statements written in the try block.
But it cannot be used in the function. But we can use raise error function.
The TRY CATCH block cannot be used with inside the functions. But we can use the raiserror function to throw the exception.
Difference 7:
Stored procedure can call the user defined functions
The function can be called from the stored procedure.
 
CREATE PROC Pr_RetirveCustomers AS BEGIN SET NOCOUNT ON SET XACT_ABORT ON SELECT * FROM Customers SELECT *
FROM [dbo].fn_GetOrderedCustomers (5) END
But the function cannot call the stored procedures.
The function cannot call the stored procedures like procedures. There are many types of stored procedures in sql server.
  • System Stored procedure
  • User defined Stored procedure
  • NET CLR stored procedure
  • Extended stored procedure
Except extended stored procedures no one can call the user defined functions.
Difference 8:
Stored procedures can have input and output parameters.
As you know, the input and output are the parameters which can return the results through that variable. The output parameter can be only used to return the results through the output variable. But the input parameter can be do the both input and output operations.
But the function can have only input parameters.

This won't allow us to use the output parameters. But we can use input parameter.
Difference 9:
Stored procedures can have select and all DML operations.
The stored procedures can do all the DML operations like insert the new record, update the records and delete the existing records.
But the function can do only select operation.
 The function won't allow us to do the DML operations in the database tables like in the stored procedure. It allows us to do only the select operation.
It will not allow to do the DML on existing tables. But still we can do the DML operation only on the table variable inside the user defined functions.
Difference 10:
Function cannot have the transaction statements.
The transaction statement cannot be used in the function. Normally we won't do any DML operations in the function.
Stored procedure can use transaction statements.
The transaction statement can be used inside the stored procedures.
Difference 11:
Stored procedures can use all the data types available in sql server.
The parameters for the stored procedures can be any data types which are available on the sql server.
But the function cannot use the ntext, image and timestamp data types as return type.
The function won't allow several data types of the sql server as a parameter.
Difference 12:
Stored procedures can create table variable and cannot return the table variable.
The table variable is one of the performances tuning mechanism. Because it takes minimum resources and it uses the memory location for store the data. (Recommended for minimum rows)
It can be created and do the operations. But it cannot be the return type.
But the function can create, update and delete the table variable. It can return table variable.
It can be created and can do all the DML operations and it can be the return type. That is called the multi valued table function.
Difference 13:
Stored procedure can have the dynamic sql statement and which can be executed using sp_executesql statement.
The stored procedure can have the dynamic sql statement for the complex decision making operations which generated inside the stored procedures. It can be executed using the sp_executesql statement.
But the function cannot execute the sp_executesql statement.
The function can generate the dynamic sql statement. But it cannot get execute. It will not allow writing the sp_executesql command to execute the dynamically created sql statement.
Difference 14:
Stored procedure allows getdate () or other non-deterministic functions can be allowed.

The stored procedure will allow all the sql server built-in functions like getdate(),DB_ID(),
DB_NAME (), etc..,
But the function won't allow the non-deterministic functions.
The function will not allow using non-deterministic functions like GETDATE ()
Conclusion
I believe that the above mentioned differences are valid. If you find any mistakes then please correct that. Give your feedback comments so that I can improve my writing skills.