Learning Practical SSIS
Transcript of Learning Practical SSIS
-
7/23/2019 Learning Practical SSIS
1/70
SSIS Exercise(Part-1)With Mr. Joydeep Das
Help you to understand the power of Microsoft SSIS
Date: 21-04-2013
-
7/23/2019 Learning Practical SSIS
2/70
Hello friends,
Here I decide to introduce a practical SSIS e-learning material for all of my friends wo want to
learn te !icrosoft "I tools li#e SSIS$
%is e-learning material is dedicated to te &unior professions$ %is e-learning material contains
te e'ample only not any definition$ %is e-learning material is useful for tose professional wo
already #now SSIS (ut need practical e'ample to understand it properly$
Hope you en&oy tis and it is )ery muc useful for your professional life$
If you a)e you any *uery please feel free communicate wit me$
+it egards
oydeep Das
das$&oydeep2.gmail$com
http://www.sqlnowled!e"an."lo!spot.in
Table of Contents
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
http://www.sqlknowledgebank.blogspot.in/http://www.sqlknowledgebank.blogspot.in/ -
7/23/2019 Learning Practical SSIS
3/70
Exercise No Contents Name1 Importing Data from a Test file to SQL Server Database2 Exporting the SQL Server data to Excel sheet
Dataflo! Error "andling
# Set$p %rea& point in SSIS 'ac&age
( Set$p the Chec& 'oints in SSIS 'ac&age
Exercise ) 1
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
4/70
mporting Data from a Test file to SQL Server Database
Case St$d*
/lease follow te mentioned steps to Import data from a %est file to S Ser)er Data(ase$
Step )1
%e name of te te't file is mployeeecord$t't
It contains columns li#e !/ID, !/!, !/5D
Step)2
6pen te !S S Ser)er "IDS (y
Start +ll 'rogram ,icrosoft SQL Server 2--. SQL Server %aseness Intelligent
Development st$dio /%IDS0
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
The Objective of this exercise is to extract data form a Text le
!ith .T"T exte#sio#$ a#d %oad it to my MS S&% Server Table
-
7/23/2019 Learning Practical SSIS
5/70
Step)
ow create a new /ac#age wit te name of SSIS 'ample$
ileNe!'roect
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
-
7/23/2019 Learning Practical SSIS
6/70
Step)#
In te solution e'plorer of te "IDS, in te SSIS /ac#age folder rename te /ac#age$dts' to
%e't7ileImport$dts'$ 8lic# o# on 9Do you want to rename te pac#age o(&ects as well; to
-
7/23/2019 Learning Practical SSIS
7/70
Step)3
In te data flow ta( drag te flat file source from te data flow source of te tool (ars$ igt clic#
it and select dit$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
8/70
8lic# on te ew= (utton 7lat file connection manager editor windows appears$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
9/70
8lic# on te "rowse= (utton to coose te %e't file$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
10/70
Here I am coosing my mployeeecord$t't file and clic# te 6pen (utton$ In te connection
manager editor window we select 1 for Header row to s#ip$ It elp us to s#ip te columns name
wen importing data from my te't file$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 10
-
7/23/2019 Learning Practical SSIS
11/70
ow select te 8olumns from te left and side$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 11
-
7/23/2019 Learning Practical SSIS
12/70
Select te d)ance from te left-and side and gi)e te proper name of te columns and data
type and si>e of te columns$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1
-
7/23/2019 Learning Practical SSIS
13/70
+e can see te pre)iew (y selecting /re)iew from left and side$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1
-
7/23/2019 Learning Practical SSIS
14/70
ow clic# 6? (utton
8lic# on te 8olumns from left and side of te 7lat file source editor$ 7rom )aila(le 'ternal
columns we can de-select te columns tat we do not want to appear or migrate$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1*
-
7/23/2019 Learning Practical SSIS
15/70
ow clic# o# to finis it$
Step)4
Drag te 6D" Destination from te %ool(ars of Data 7low destination to Data 7low ta( wor#
area$ Drag te data flow pat @green color arrowA to 6D" Destination$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1+
-
7/23/2019 Learning Practical SSIS
16/70
igt clic# te 6D" destination and select te dit$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1,
-
7/23/2019 Learning Practical SSIS
17/70
6n te 6D" 8onnection manager of 6D" Destination ditor select te ew= (utton$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1
-
7/23/2019 Learning Practical SSIS
18/70
In 8onfigure 6D" 8onnection manager select te ew= (utton$ In te connection manager
window select te ati)e 6 D" B S Ser)er ati)e 8lint 10$0 pro)iders$ /ro)ide te S
Ser)er Instance name and coose te autentication mode$ %en select te data(ase name$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1
-
7/23/2019 Learning Practical SSIS
19/70
8lic# on te %est 8onnection (utton to cec# te data(ase connecti)ity$
8lic# on te 6? (utton$
In te 6 D" data(ase editor clic# on te ew= (utton of ame of %a(le or Ciew$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1
-
7/23/2019 Learning Practical SSIS
20/70
+rite down te 8% %" statement on te 8reate ta(le window$ Here we gi)e te ta(le
name is %"!/86D$
8% %" E%"!/86DF @
E!/IDF )arcar@G0A,
E!/7!F )arcar@G0A,
E!/5DF )arcar@G0A
A
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 0
-
7/23/2019 Learning Practical SSIS
21/70
8lic# 6? on it$
In 6 D" Destination editor select te mappings from te rigt and side and loo# at te
mapping of te )aila(le Input 8olumns and )aila(le Destination 8olumns$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1
-
7/23/2019 Learning Practical SSIS
22/70
8lic# 6? on it$
Step).
ow run te pac#age (y clic#ing te 7G (utton$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
23/70
Here 3 rows is mo)ing from 7lat file Source to 6 D" Destination$
ow open te S Ser)er !anagement Studio and e'ecute te following S Statement$
SELECT*FROMTBLEMP_RECORD;
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
24/70
Exercise)2
Exporting the SQL Server data to Excel sheet
Here we must learn a(out te Import 'port +i>ard of SSIS$ Here in tis 'ample we are ta#ing
te 'port +i>ard$
Case St$d*
Step)1
7rom te "IDS open te SSIS pro&ect and ten select te /ro&ect menu and ten select SSISImport and 'port +i>ard$
"IDS6pen SSIS /ro&ect/ro&ect menuSSIS Import and 'port +i>ard
Step)2
+elcome to S Ser)er Import 'port wi>ard windows appears$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
The mai# objective is to Export the MS S&% Data from a Table
objects to a# Excel spread sheet.
-
7/23/2019 Learning Practical SSIS
25/70
/lease read te instruction to #now a(out it$ %en clic# te e't (utton
Step)
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
-
7/23/2019 Learning Practical SSIS
26/70
In 8oose a Data source window select te data source$ In our case we are going to connect
wit !S S Ser)er 200 as our source data(ase so we select 9S Ser)er ati)e 8lient
10$0;$ %en pro)ide te Ser)er name$ In our case te ser)er name is 96
-
7/23/2019 Learning Practical SSIS
27/70
In coose destination window we must pro)ide te destination$ In our case it is !icrosoft 'cel$
%en select te 'cel file pat$ In our case te name of te e'cel file it 9Destination$'ls'; and
te pat is 97:B/racticeSBSSISBSSIS 'amplesBDestination$'ls';$ %en we select te )ersion
of te 'cel$ In our case it is !icrosoft 'cel 200J$
Step)(
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
28/70
Specify %a(le 8opy or uery window we a)e two options$ 6ne is 8opy data from one or more
ta(les or )iews and second is +rite a *uery to specify te data to transfer$
Step)3
If we coose te first options 8opy data from one or more ta(les or )iew$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
29/70
Here we can coose one or more ta(les or )iews from source columns and in destination
columns we must specify te name of 'cel wor# (oo# seet name$
In our case we coose 9!
-
7/23/2019 Learning Practical SSIS
30/70
8lic# e't$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 0
-
7/23/2019 Learning Practical SSIS
31/70
8lic# e't
Step)4
#$a%ple SSIS with Mr. &oydeep 'as Pa!e 1
-
7/23/2019 Learning Practical SSIS
32/70
In te 8omplete te +i>ard window, cec# att te acti)ity you done in tis wi>ard and clic# on
te 7inis "utton
Step).
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
33/70
Step)5
6(ser)e te 'cel file$
SELECT*FROMMY_EMPDETAILS
EMPID E MPNAME DEPT
1 JOYDEEP DAS Team Lead2 SUDIP DAS Manager
3 TUI! SI!A De"e#$%er
& SA!'RAM JIT SR(De"e#$%er
) DEBAYA! BISAS De"e#$%er+ RUOOL AMI! SAR,AR SR(De"e#$%er
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
34/70
Step)1-
If we loo# at te SSIS /ac#age
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
-
7/23/2019 Learning Practical SSIS
35/70
Exercise )
Dataflow Error Handling
Case St$d*
Step)1
In te control flow ta( drag a data flow tas#s from te 8ontrol flow Item tool (ar$
Dou(le clic# it or igt clic# and dit$
Step)2
In te data flow ta( drag a 7lat file source$ Here we e'tract data form a faulty flat file wic angi)es us error$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
'ere !e read a Text le as a data so(rce a#d mi)rate the data
to a MS S&% Server database Table Objects. If a#y error fo(#d
to read the Text le it redirect the error records or data to a
Text le desti#atio# !ith error descri tio#.
-
7/23/2019 Learning Practical SSIS
36/70
%e faulty flat file structure is mentioned (ellow
/lease loo# ere !/ID, instead of numerical 3 we use 9%H; and ence it generate error in
case of data type mismatc$
Step)
8onfigure te 7lat 7ile Source
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,
-
7/23/2019 Learning Practical SSIS
37/70
8lic# te ew "utton$ 8lic# on "rows (utton to coose te 7lat file form 7lat file 8onnection
manager window$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
38/70
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
39/70
Select d)ance from te rigt and side section$ Here we define te column name and data
type of te columns and si>e of te columns$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e
-
7/23/2019 Learning Practical SSIS
40/70
8lic# on 6? (utton$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *0
-
7/23/2019 Learning Practical SSIS
41/70
In error 6utput @It is ImportantA ma#e te rror and %runcation to edirect row$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *1
-
7/23/2019 Learning Practical SSIS
42/70
8lic# 6? (utton$
Step)#
ow we a)e to ta#e te Data flow destination$ Here we ta#e two data flow destination$ +e use
6 D" Destination and connect te 7lat 7ile Source 6utput in it and for 7lat file destination
connect te 7lat file source output$ fter tat we a)e to configure te 6 D" destination and
7lat file destination mentioned (ellow$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
-
7/23/2019 Learning Practical SSIS
43/70
Step)(
ow we are going to configure te 6 D" destination$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
-
7/23/2019 Learning Practical SSIS
44/70
Select te 6 D" connection manager$ In our case it is 96
-
7/23/2019 Learning Practical SSIS
45/70
8lic# on 6? (utton$ ow loo# at te mapping section$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *+
-
7/23/2019 Learning Practical SSIS
46/70
%en clic# 6? (utton$
Step)3
ow we are going to configure te 7lat file destination$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *,
-
7/23/2019 Learning Practical SSIS
47/70
8lic# on new (utton$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
-
7/23/2019 Learning Practical SSIS
48/70
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
-
7/23/2019 Learning Practical SSIS
49/70
8lic# on "rows (utton
#$a%ple SSIS with Mr. &oydeep 'as Pa!e *
-
7/23/2019 Learning Practical SSIS
50/70
8oose te rror6utput$t't file
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +0
-
7/23/2019 Learning Practical SSIS
51/70
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +1
-
7/23/2019 Learning Practical SSIS
52/70
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
-
7/23/2019 Learning Practical SSIS
53/70
ow go to te !apping section of te flat file destination editor$
Step)4
ow run te pac#age$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
-
7/23/2019 Learning Practical SSIS
54/70
If we loo# at te rror file
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +*
-
7/23/2019 Learning Practical SSIS
55/70
Exercise ) #
Setup Brea point in SS S !acage
"rea# point is noting (ut a point were te de)eloper can old te e'ecution to see ow te
code is e'ecuted at tat point$ In SSIS it needs to cec# te status of te tas# at te particular
points$
Case St$d*
Step)1
%o cec# tis e'ercise we are ta#ing te 'ample of Data flow error andling pac#age tas#s$
In te control flow tas# ose te Data flow tas#s rigt clic# it and select dit "rea#points=
Control flo! tabChose Data lo! Tas&s6ight Clic&rom Shortc$t men$Select
Edit %rea&points7
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ++
'ere !e see a simple example to set the *rea+ poi#t i# SSIS
co#trol ,o! tas+s a#d ho! to a#aly-e it.
-
7/23/2019 Learning Practical SSIS
56/70
Here we must understand (rea# 8ondition (efore ena(le it$ %ere are ten e)ents in te control
flow descri(ed (ellow @from (oo# onlineA
8n'reExec$te98alled wen a tas# is a(out to e'ecute$ %is e)ent is raised (y a
tas# or a container immediately (efore it runs$
8n'ostExec$te98alled immediately after te e'ecution logic of te tas# finises$
%is e)ent is raised (y a tas# or container immediately after it runs$
8nError98alled (y a tas# or container wen an error occurs$
8n:arning98alled wen te tas# is in a state tat does not &ustify an error, (ut
does warrant a warning$
8nInformation98alled wen te tas# is re*uired to pro)ide information$
8nTas&ailed98alled (y te tas# ost wen it fails$
8n'rogress98alled to update progress a(out tas# e'ecution$
8nQ$er*Cancel98alled at any time in tas# processing wen you can cancel
e'ecution$
8n;ariable;al$eChanged98alled (y te Integration Ser)ices runtime wen te
)alue of a )aria(le canges$ %e aise8ange)ent of te )aria(le must (e set to
true to raise tis e)ent$
8nC$stomEvent98alled (y tas#s to raise custom tas#-defined e)ents
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +,
-
7/23/2019 Learning Practical SSIS
57/70
Step)2
%o understand it, now run te pac#age$
oo# at te red spot data flow tas#s$ 'ecution is old for te (rea# point and Data flow tas# is
mar#ed (y yellow color$
Step)
%o get te information, first we start wit call stac# window to see weter te (rea# point is
located$ %o open te call stac# window
Deb$g men$ :indo!Call Stac&
6r
Ctrl < +lt < C
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
-
7/23/2019 Learning Practical SSIS
58/70
%en "rea# point window
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
-
7/23/2019 Learning Practical SSIS
59/70
%en 6utput +indow @8trl L lt L 6A to determine wat as (een running at te pac#age wen
te (rea# occurs$
7inally te ocals +indow @8trl L lt L C, A to #now a(out te current status of te pac#age
e'ecution$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e +
-
7/23/2019 Learning Practical SSIS
60/70
Exercise ) (
Setup the "hec !oints in SS S !acage
"efore starting tis e'ercise letMs ta#e a *uic# loo# a(out 8ec# /oint$
+en we are wor#ing wit a complicated and long running SSIS pac#age and we want te
a(ility to restart te pac#age if it fails and a)e it starts at te point of failure$ In oters words if
we donNt want to e'ecute te tas#s tat are already successful if te pac#age restarted$ %is is
done (y esta(lising cec# points$
%o understand it, letNs assume tat we a)e 10 tas#s in te pac#age$ +en te pac#age is
e'ecuted %e %as#s -1 to %as#s -G runs success fully at %as#s-O it gi)es an error$ +en te
pac#age restarted for esta(lising cec# points it starts from %as#s -O not from %as#s-1$
%o ena(ling restart a(ility witin a pac#age re*uired first ena(ling a pac#age to use cec#
points, and second settings te specific tas#s and containers to write cec#points$
Case St$d*
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,0
'ere !e have a simple demo#stratio# a# Exec(te S&% Tas+s
reate a Table Objects a#d Three Other Exec(te S&% Tas+s have
I/SE0T Stateme#ts to I#sert data o# this table objects. 'ere
the 1#dS&% stateme#t have some data type mismatch a#d
-
7/23/2019 Learning Practical SSIS
61/70
Step)1
!icrosoft Distri(uted %ransaction 8oordinator @!SD%8A ser)ices are an important factor for
paying transaction wit SSIS pac#age$
%o start it
Control 'anel+dministrative ToolsServices Console
Step)2
In control flow ta( drag an 'ecute S tas#s and ten se*uence container and drag tree
'ecute S tas#s in it$
Drag te precedence constraint of te 'ecute S tas# named 8reate "ase to Se*uence
container$
Step)
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,1
-
7/23/2019 Learning Practical SSIS
62/70
dit te 'ecute S %as#s @8reate "aseA
Set 8onnection property, ere it is 6
-
7/23/2019 Learning Practical SSIS
63/70
CREATETABLET-#_STUDE!T_DETAILS
.ID!O I!T !OT!ULLPRIMARY,EY/ STUDE!T!AME 0ARCAR.)!OT!ULL/
SUBJECT 0ARCAR.)!OT!ULL
Step)#
diting te 7irst 'ecute S %as#, tis is located witin te Se*uence 8ontainer$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,
-
7/23/2019 Learning Practical SSIS
64/70
or Exec$te SQL Tas& )1
I!SERTI!TOT-#_STUDE!T_DETAILS
.ID!O/STUDE!T!AME/SUBJECT40ALUES.1/5JOYDEEP DAS5/5I!DI5
or Exec$te SQL Tas& )2
I!SERTI!TOT-#_STUDE!T_DETAILS .ID!O/STUDE!T!AME/SUBJECT4
0ALUES.5T6$5/5SU,AMAL JA!A5/5MAT5
or Exec$te SQL Tas& )
I!SERTI!TOT-#_STUDE!T_DETAILS
.ID!O/STUDE!T!AME/SUBJECT4
0ALUES.3/5SUDIP C DAS5/5E!'LIS5
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,*
-
7/23/2019 Learning Practical SSIS
65/70
/lease loo# at 'ecute S %as# -2 ere an error e'ists in IS% statement due to data type
mismatc$
Step)(
ow set te 8ec#points property of te pac#age$
Setting te 8ec#point7ileame property$ Here te file name is 8ec#/oint%rac#er
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,+
-
7/23/2019 Learning Practical SSIS
66/70
8lic# 6pen (utton
ow set te 8ec#pointsage property to if'ists
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,,
-
7/23/2019 Learning Practical SSIS
67/70
ow te Sa)e8ec#point property to %rue$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,
-
7/23/2019 Learning Practical SSIS
68/70
ow set te 'ecute S Statement tas# 7ailed/ac#age6n7ailure property to %rue$
Step)3
ow e'ecute te pac#age$ /lease loo# te 'ecute S %as# P 2 7ailed due to error in IS%
statement @Data type !ismatcA$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,
-
7/23/2019 Learning Practical SSIS
69/70
Step)4
ow 7i' te rror of S statement in 'ecute S %as# -2 and run te pac#age$
/lease loo# only 'ecute S %as#-2 is e'ecuted not te ntire pac#age$
#$a%ple SSIS with Mr. &oydeep 'as Pa!e ,
-
7/23/2019 Learning Practical SSIS
70/70
If we open te cec# point file we can see te 'ml code$