12.07.2015 Views

Solution Guide for Migrating Oracle on UNIX to SQL Server - Willy .Net

Solution Guide for Migrating Oracle on UNIX to SQL Server - Willy .Net

Solution Guide for Migrating Oracle on UNIX to SQL Server - Willy .Net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> WindowsPublished April 2005


ivC<strong>on</strong>tentsBuild the Physical Design ................................................................................................................48Incorporate Design C<strong>on</strong>siderati<strong>on</strong>s.........................................................................................................50Hardware Design C<strong>on</strong>siderati<strong>on</strong>s ....................................................................................................50Validate the Technology .........................................................................................................................50<strong>SQL</strong> <strong>Server</strong> Editi<strong>on</strong>s and Features ..................................................................................................51Windows <strong>Server</strong> 2003......................................................................................................................52Technical Proof of C<strong>on</strong>cept .............................................................................................................52Develop the Project Plans.......................................................................................................................53Development Plan ...........................................................................................................................53Stabilizing Phase Plans ...................................................................................................................55Test Plan .........................................................................................................................................55Pilot Plan .........................................................................................................................................59Deployment Plan .............................................................................................................................60Create the Project Schedules .................................................................................................................63Estimating the Ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t ........................................................................................................................63Set Up the Development and Test Envir<strong>on</strong>ments ...................................................................................65Developing: Databases — Introducti<strong>on</strong> .................................................................................... 67Introducti<strong>on</strong> and Goals............................................................................................................................67<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database...........................................................................................................................68Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Architecture ........................................... 71Introducti<strong>on</strong> and Goals............................................................................................................................71Build the <strong>SQL</strong> <strong>Server</strong> Instance................................................................................................................71Pre-Installati<strong>on</strong> Planning..................................................................................................................72Installati<strong>on</strong> .......................................................................................................................................72C<strong>on</strong>figure the <strong>Server</strong>...............................................................................................................................73C<strong>on</strong>figure Memory ...........................................................................................................................74Set the CPU Affinity.........................................................................................................................76C<strong>on</strong>figure the Listener .....................................................................................................................77Migrate the S<strong>to</strong>rage Architecture ............................................................................................................77Blocks ..............................................................................................................................................77Extents and Segments.....................................................................................................................78Tablespaces and Datafiles ..............................................................................................................79S<strong>to</strong>rage Definiti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> Tables and Indexes.......................................................................................81Migrate System S<strong>to</strong>rage Structures.................................................................................................82Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas ........................................................................ 83Introducti<strong>on</strong> and Goals............................................................................................................................83Scripting Migrated Schema Objects........................................................................................................84Script Everything..............................................................................................................................84Provide Support Documentati<strong>on</strong>......................................................................................................84Protect the Scripts ...........................................................................................................................84Migrate the Schema................................................................................................................................85Map the S<strong>to</strong>rage Architecture ..........................................................................................................85Create Databases <str<strong>on</strong>g>for</str<strong>on</strong>g> the Schema...................................................................................................87Create Filegroups <str<strong>on</strong>g>for</str<strong>on</strong>g> the Tablespaces............................................................................................90Add Datafiles <strong>to</strong> Filegroups..............................................................................................................90Add Transacti<strong>on</strong> Logs......................................................................................................................91Sample Schema Migrati<strong>on</strong>...............................................................................................................91Migrate the Schema Objects...................................................................................................................98Create the Schema Owner ..............................................................................................................98Create the Schema Objects...........................................................................................................102Comments .....................................................................................................................................111C<strong>on</strong>straints ....................................................................................................................................111Triggers .........................................................................................................................................119Indexes ..........................................................................................................................................121Views .............................................................................................................................................123S<strong>to</strong>red Programs............................................................................................................................126<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s <str<strong>on</strong>g>for</str<strong>on</strong>g> Objects not Found in <strong>SQL</strong> <strong>Server</strong> .............................................................................129Sample Schema Object Migrati<strong>on</strong> .................................................................................................132


C<strong>on</strong>tentsvDeveloping: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Users .................................................... 143Introducti<strong>on</strong> and Goals..........................................................................................................................143Create User Accounts...........................................................................................................................143Create Roles and Grant Privileges .......................................................................................................145Sample User Migrati<strong>on</strong> .........................................................................................................................147Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data........................................................................ 153Introducti<strong>on</strong> and Goals..........................................................................................................................153Planning the Data Migrati<strong>on</strong>..................................................................................................................153Opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> Migrati<strong>on</strong> .....................................................................................................................153Fac<strong>to</strong>rs in Migrati<strong>on</strong> .......................................................................................................................155Migrati<strong>on</strong> Strategy..........................................................................................................................156Executing the Data Migrati<strong>on</strong>................................................................................................................157Pre-Implementati<strong>on</strong> Tasks.............................................................................................................158Implementati<strong>on</strong> Tasks....................................................................................................................160Post-Implementati<strong>on</strong> Tasks ...........................................................................................................165Validating the Data Migrati<strong>on</strong>.........................................................................................................165Developing: Databases — Unit Testing the Migrati<strong>on</strong>........................................................... 167Introducti<strong>on</strong> and Goals..........................................................................................................................167Objectives of Testing ............................................................................................................................167The Testing Process.............................................................................................................................168Test Database Integrity..................................................................................................................169Test Security..................................................................................................................................169Validate Data .................................................................................................................................170Validate the Migrati<strong>on</strong> ....................................................................................................................170Developing: Applicati<strong>on</strong>s — Introducti<strong>on</strong>............................................................................... 173Introducti<strong>on</strong> and Goals..........................................................................................................................173Applicati<strong>on</strong> Migrati<strong>on</strong> Strategies ...........................................................................................................174Interoperati<strong>on</strong> ................................................................................................................................174Port or Rewrite <strong>to</strong> .NET Framework...............................................................................................175Port or Rewrite <strong>to</strong> Win32................................................................................................................175Quick Port Using Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>...............................................................................176Scenarios and Cases............................................................................................................................176Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>............................................ 177Introducti<strong>on</strong> ...........................................................................................................................................177<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Data Access..........................................................................................................................177Sample Tables...............................................................................................................................179Migrati<strong>on</strong> Process Overview ..........................................................................................................181Step 1: Extracti<strong>on</strong> of Data Access .................................................................................................182Step 2: Transacti<strong>on</strong> Management..................................................................................................202Step 3: Fetch Strategy ...................................................................................................................203Step 4: Subprograms C<strong>on</strong>versi<strong>on</strong>..................................................................................................206Step 5: Job Scheduling..................................................................................................................213Step 6: Interface File C<strong>on</strong>versi<strong>on</strong>...................................................................................................217Step 7: Workflow Au<strong>to</strong>mati<strong>on</strong> ........................................................................................................217Step 8: Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Tuning..........................................................................................................218Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Perl............................................................................ 223Introducti<strong>on</strong> and Goals..........................................................................................................................223Introducti<strong>on</strong> <strong>to</strong> the Perl DBI Architecture...............................................................................................224Scenario 1: Interoperati<strong>on</strong> of Perl <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong>................................................................225Case 1: Interoperating an ODBC DBD Applicati<strong>on</strong>........................................................................226Case 2: Interoperating an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBD Applicati<strong>on</strong>........................................................................228Scenario 2: Porting the Perl Applicati<strong>on</strong> <strong>to</strong> Windows ............................................................................232Case 1: Porting a Perl Applicati<strong>on</strong> using ODBC DBD....................................................................232Case 2: Porting a Perl Applicati<strong>on</strong> Using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBD...................................................................234Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHP ........................................................................... 237Introducti<strong>on</strong> and Goals..........................................................................................................................237PHP Modules........................................................................................................................................238Scenario 1: Interoperating PHP <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong>...................................................................240Case 1: Interoperating a PHP Applicati<strong>on</strong> Using ORA Functi<strong>on</strong>s ..................................................240


viC<strong>on</strong>tentsCase 2: Interoperating a PHP Applicati<strong>on</strong> Using OCI8 Functi<strong>on</strong>s.........................................................244Case 3: Interoperating a PHP Applicati<strong>on</strong> Using ODBC Functi<strong>on</strong>s.......................................................246Comm<strong>on</strong> Functi<strong>on</strong> Translati<strong>on</strong> Issues ..................................................................................................249Handling Transacti<strong>on</strong>s ...................................................................................................................249<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Cursors ..........................................................................................................................250C<strong>on</strong>necti<strong>on</strong> Pooling........................................................................................................................251S<strong>to</strong>red Procedures.........................................................................................................................251Scenario 2: Porting the Applicati<strong>on</strong> <strong>to</strong> Win32........................................................................................252Case 1: Porting a PHP Applicati<strong>on</strong> using ORA Functi<strong>on</strong>s .............................................................252Case 2: Porting a PHP Applicati<strong>on</strong> Using OCI8 Functi<strong>on</strong>s ............................................................252Case 3: Porting a PHP Applicati<strong>on</strong> Using ODBC Functi<strong>on</strong>s ..........................................................253Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Java .......................................................................... 255Introducti<strong>on</strong> and Goals..........................................................................................................................255Scenario 1: Interoperating Java <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong>...................................................................256Case 1: Interoperating a Java Applicati<strong>on</strong> Using the JDBC Driver ................................................256Scenario 2 — Porting the Applicati<strong>on</strong> <strong>to</strong> Win32 ....................................................................................259Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Pyth<strong>on</strong> ...................................................................... 261Introducti<strong>on</strong> and Goals..........................................................................................................................261Scenario 1: Interoperating Pyth<strong>on</strong> <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong> ...............................................................263Case 1: Interoperating Using the mxODBC Module ......................................................................263Scenario 2: Port the Pyth<strong>on</strong> Applicati<strong>on</strong> <strong>to</strong> Win32 ................................................................................266Case 1: Porting a Pyth<strong>on</strong> Applicati<strong>on</strong> using mxODBC...................................................................266Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*C ............................................................ 269Introducti<strong>on</strong> and Goals..........................................................................................................................269Understanding the Technology .............................................................................................................270Understanding Pro*C.....................................................................................................................270Understanding .NET and ADO.NET ..............................................................................................270Scenario 1: Rewriting Pro*C <strong>to</strong> the .NET Plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m................................................................................271Case 1: Rewrite the Applicati<strong>on</strong> using Visual Basic.NET...............................................................271Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms ........................................................... 279Introducti<strong>on</strong> and Goals..........................................................................................................................279Migrati<strong>on</strong> Approach...............................................................................................................................279Examining <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms ......................................................................................................................281Object Library ................................................................................................................................284PL/<strong>SQL</strong> Library ..............................................................................................................................284Form Module .................................................................................................................................285Menu Module.................................................................................................................................288Windows and Canvases ................................................................................................................288Understanding Visual Basic .NET.........................................................................................................290Scenario 1: Rewriting <strong>to</strong> Visual Basic .NET ..........................................................................................291Case 1: Using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Designer .....................................................................................................291Case 2: Manually Redesigning the Applicati<strong>on</strong>..............................................................................291Testing the Visual Basic .NET Applicati<strong>on</strong> ............................................................................................295Stabilizing Phase ....................................................................................................................... 297Introducti<strong>on</strong> and Goals..........................................................................................................................297Testing the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> ..............................................................................................................................298Best Practices................................................................................................................................299Preparing <str<strong>on</strong>g>for</str<strong>on</strong>g> Testing .....................................................................................................................299Types of Testing ............................................................................................................................301Bug Tracking and Reporting ..........................................................................................................305User Acceptance Testing and Signoff............................................................................................308Piloting the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> ..............................................................................................................................308Preparing <str<strong>on</strong>g>for</str<strong>on</strong>g> the Pilot ....................................................................................................................309C<strong>on</strong>ducting the Pilot.......................................................................................................................309Evaluating the Pilot ........................................................................................................................310Finalizing the Release...........................................................................................................................310Deploying Phase........................................................................................................................ 313


C<strong>on</strong>tentsviiIntroducti<strong>on</strong> and Goals..........................................................................................................................313Deploying the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>..........................................................................................................................313Deploying the Database <strong>Server</strong>.....................................................................................................314Deploying the <strong>Server</strong> Side Applicati<strong>on</strong>s.........................................................................................317Deploying the Client Applicati<strong>on</strong> ....................................................................................................318Change Management ....................................................................................................................320Stabilizing the Deployment ...................................................................................................................320Deployment Checklist ....................................................................................................................320Quiet Period...................................................................................................................................323Transferring Ownership <strong>to</strong> Operati<strong>on</strong>s..................................................................................................324Project Team Tasks.......................................................................................................................324Operati<strong>on</strong>s Team Tasks ................................................................................................................325C<strong>on</strong>ducting Project Review and Closure...............................................................................................325Operati<strong>on</strong>s.................................................................................................................................. 327Introducti<strong>on</strong> and Goals..........................................................................................................................327Operati<strong>on</strong>al Framework ........................................................................................................................327Windows Envir<strong>on</strong>ment Operati<strong>on</strong>s........................................................................................................328System Administrati<strong>on</strong> ...................................................................................................................328Security Administrati<strong>on</strong> ..................................................................................................................328M<strong>on</strong>i<strong>to</strong>ring......................................................................................................................................329Additi<strong>on</strong>al Links .............................................................................................................................329<strong>SQL</strong> <strong>Server</strong> Envir<strong>on</strong>ment Operati<strong>on</strong>s ...................................................................................................329Administrati<strong>on</strong>................................................................................................................................329Security..........................................................................................................................................330M<strong>on</strong>i<strong>to</strong>ring......................................................................................................................................330Additi<strong>on</strong>al Links .............................................................................................................................330APPENDICES ............................................................................................................................. 331Appendix A: <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Professi<strong>on</strong>als................................................................................331Architecture ...................................................................................................................................331Administrati<strong>on</strong>................................................................................................................................343Appendix B: Getting the Best Out of <strong>SQL</strong> <strong>Server</strong> 2000 and Windows ..................................................348Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance ..................................................................................................................................348Scalability ......................................................................................................................................349High Availability .............................................................................................................................349Features and Tools........................................................................................................................351Appendix C: Baselining.........................................................................................................................353Creating Baselines.........................................................................................................................353Capturing Statistics........................................................................................................................357Comparing and Reporting Results.................................................................................................357Appendix D: Installing Comm<strong>on</strong> Drivers and Applicati<strong>on</strong>s ....................................................................358Installing FreeTDS ................................................................................................................................358C<strong>on</strong>figuring FreeTDS.....................................................................................................................358Testing the FreeTDS C<strong>on</strong>figurati<strong>on</strong> ...............................................................................................358Installing unixODBC..............................................................................................................................359Installing ActiveState Perl .....................................................................................................................360Appendix E: Reference Resources.......................................................................................................362


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> WindowsixPrefaceOverviewThe <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows Migrati<strong>on</strong> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> provides practicalguidance <strong>on</strong> the processes and procedures <strong>to</strong> be followed while migrating from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>databases (versi<strong>on</strong>s 8i and later) <strong>on</strong> <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms <strong>to</strong>Microsoft® Windows® <strong>Server</strong> 2003 and Microsoft <strong>SQL</strong> <strong>Server</strong> 2000. This guide alsopresents strategies and procedural guidance <strong>to</strong> c<strong>on</strong>vert existing applicati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> usewithin the <strong>SQL</strong> <strong>Server</strong> 2000 and Microsoft Windows <strong>Server</strong> envir<strong>on</strong>ment. This guideprovides additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> and references <strong>to</strong> <strong>on</strong>line resources about migrating othercomp<strong>on</strong>ents of your applicati<strong>on</strong> ecosystem, including the server and networkinfrastructure, development and test envir<strong>on</strong>ment, and user accounts.The guide is based <strong>on</strong> the experience of c<strong>on</strong>sultants working in the field andorganizati<strong>on</strong>s that have successfully migrated from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong><strong>on</strong> Windows envir<strong>on</strong>ment, and it comprises the best lab-tested, cus<strong>to</strong>mer-proven, crossproducttechnical guidance from Microsoft <strong>on</strong> planning, building, deploying, and operatingthe migrati<strong>on</strong> soluti<strong>on</strong>. All processes and procedures c<strong>on</strong>tained in this guide have beenvalidated through the Microsoft Technology Adopti<strong>on</strong> Program (TAP), which is a betaprogram that c<strong>on</strong>sists of cus<strong>to</strong>mers and partners who have evaluated and validated thevarious technologies and practices described in this guide.An important assumpti<strong>on</strong> made in this guide is that your organizati<strong>on</strong> has decided <strong>to</strong>migrate all or parts of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database and applicati<strong>on</strong> envir<strong>on</strong>ment from <strong>UNIX</strong> <strong>to</strong><strong>SQL</strong> <strong>Server</strong> 2000 in a Windows envir<strong>on</strong>ment. Because of this assumpti<strong>on</strong>, this guidedoes not present a competitive analysis of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> versus <strong>SQL</strong> <strong>Server</strong> 2000, or <strong>UNIX</strong>versus Windows. This guide does help you decide which migrati<strong>on</strong> strategy is best <str<strong>on</strong>g>for</str<strong>on</strong>g>your organizati<strong>on</strong> given your specific business and technical requirements, and itexplains how <strong>to</strong> plan <str<strong>on</strong>g>for</str<strong>on</strong>g> and execute that strategy.This process-driven approach <strong>to</strong> migrati<strong>on</strong> is applied <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database, the <strong>UNIX</strong>applicati<strong>on</strong>s that rely <strong>on</strong> the database, and the applicati<strong>on</strong> programming interfaces (APIs)that c<strong>on</strong>nect the applicati<strong>on</strong>s <strong>to</strong> the database. The strategies and methods <str<strong>on</strong>g>for</str<strong>on</strong>g> migratingthese comp<strong>on</strong>ents vary according <strong>to</strong> the size and complexity of the database, applicati<strong>on</strong>,and infrastructure of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> source system. The strategies and methods also varyaccording <strong>to</strong> any new business or technical requirements your organizati<strong>on</strong> develops as aresult of migrating <strong>to</strong> the Microsoft Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.Because there is so much variance in the possible approaches <strong>to</strong> migrati<strong>on</strong>, this guideprovides numerous examples and best practices <strong>to</strong> help you better understand both thec<strong>on</strong>cepts and detailed processes involved in migrati<strong>on</strong>. A series of job aids (templates,spreadsheets, and questi<strong>on</strong>naires) are included as part of this soluti<strong>on</strong> guide <strong>to</strong> help youbetter analyze, plan, structure, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the migrati<strong>on</strong>.The in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> under the following two headings outlines the technical scope of themigrati<strong>on</strong> strategies and methods provided in this guide.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windowsxi● Migrati<strong>on</strong> of the operating system <strong>to</strong> Microsoft Windows <strong>Server</strong> 2003●●Support <str<strong>on</strong>g>for</str<strong>on</strong>g> Open Management Group (OMG), an open-source, java-basedstandard <str<strong>on</strong>g>for</str<strong>on</strong>g> metadataData extracti<strong>on</strong> from enterprise resource planning (ERP) systemsWhile these technical subjects are not explicitly discussed in this guide, in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> aboutmany of them is available from Microsoft. Where appropriate throughout this guide, links<strong>to</strong> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> are provided.Intended AudiencesGenerally, the intended audience <str<strong>on</strong>g>for</str<strong>on</strong>g> this soluti<strong>on</strong> guide includes medium and large-sizedIT organizati<strong>on</strong>s that want <strong>to</strong> migrate their database and applicati<strong>on</strong>s from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong><strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> 2000 <strong>on</strong> Windows. More specifically, this guide is written <str<strong>on</strong>g>for</str<strong>on</strong>g> all ofthe members of the migrati<strong>on</strong> team, from business decisi<strong>on</strong> makers <strong>to</strong> development <strong>to</strong>operati<strong>on</strong>s. As a result, not all chapters in this guide are relevant <strong>to</strong> all team members,and the knowledge prerequisites <str<strong>on</strong>g>for</str<strong>on</strong>g> using this guide are expressed as an aggregate ofthe knowledge required of the team. The rest of this secti<strong>on</strong> provides brief descripti<strong>on</strong>s ofthe typical audiences <str<strong>on</strong>g>for</str<strong>on</strong>g> this guide, followed by a brief statement of the aggregateknowledge prerequisites <str<strong>on</strong>g>for</str<strong>on</strong>g> developing the soluti<strong>on</strong> described in this guide. The intendedaudience <str<strong>on</strong>g>for</str<strong>on</strong>g> individual chapters is identified in the "How <strong>to</strong> Use This <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g>"secti<strong>on</strong> later in this Preface.The following list organizes comm<strong>on</strong> job titles and organizati<strong>on</strong>al resp<strong>on</strong>sibilities underthe Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework (MSF) role most comm<strong>on</strong>ly associated with that titleor resp<strong>on</strong>sibility. The relati<strong>on</strong>ship between this soluti<strong>on</strong> guide and MSF is discussed inmore detail in the "How <strong>to</strong> Use This <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g>" secti<strong>on</strong>. In some organizati<strong>on</strong>s, arole may be filled by a single team member or many.● Stakeholders and High Level Decisi<strong>on</strong> Makers. These team members can besubdivided in<strong>to</strong> two groups:● Business Decisi<strong>on</strong> Makers (BDMs). This group often includes the CIO and ITdirec<strong>to</strong>r of an organizati<strong>on</strong>. These pers<strong>on</strong>nel decide the business priorities <str<strong>on</strong>g>for</str<strong>on</strong>g>purchasing and implementing soluti<strong>on</strong>s within the organizati<strong>on</strong>s. IT BDMsrequire a high-level understanding of the technical soluti<strong>on</strong>s being explored sothat they can assess the value that the soluti<strong>on</strong> can provide <strong>to</strong> theorganizati<strong>on</strong>.● Technical Decisi<strong>on</strong> Makers (TDMs). The focus of TDMs is <strong>to</strong> determine thetechnology used <strong>to</strong> solve business problems. IT TDMs must understand thebusiness drivers the organizati<strong>on</strong>s face al<strong>on</strong>g with the functi<strong>on</strong>ality delivered bymultiple technology scenarios.●●Product Management Role. This role usually includes team members with thefollowing job title and resp<strong>on</strong>sibilities:● Product Manager. This team member acts as a link between the teammembers of the project and the cus<strong>to</strong>mers of the soluti<strong>on</strong> by handling highlevelcommunicati<strong>on</strong> and managing the cus<strong>to</strong>mer's expectati<strong>on</strong>s. The ProductManager ensures that the team addresses the cus<strong>to</strong>mer's needs, c<strong>on</strong>cerns,questi<strong>on</strong>s, and feedback throughout the project. Product managers mustunderstand the business needs of the soluti<strong>on</strong>, including operati<strong>on</strong>s, businessprocesses, and policies.User Experience Role. This role usually includes team members with thefollowing job titles and resp<strong>on</strong>sibilities:


xiiPreface●Usability Expert or Technical Writer/Edi<strong>to</strong>r. Ensures that the new soluti<strong>on</strong> iseasy <str<strong>on</strong>g>for</str<strong>on</strong>g> cus<strong>to</strong>mers <strong>to</strong> use. The Usability Experts ensure that documentati<strong>on</strong>and training is provided <strong>to</strong> end users <strong>to</strong> use the new soluti<strong>on</strong> effectively.●●●●Program Management Role. This role usually includes team members with thefollowing job title and resp<strong>on</strong>sibilities:●Project Managers. These pers<strong>on</strong>nel are resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> managing theresources and schedule <str<strong>on</strong>g>for</str<strong>on</strong>g> the migrati<strong>on</strong> project from start <strong>to</strong> end.Development Role. This role usually includes team members with the followingjob titles and resp<strong>on</strong>sibilities:●●●●●●●●IT Architect. The primary role of the IT architect is <strong>to</strong> carry out decisi<strong>on</strong>s madeby the TDMs. Team members with this resp<strong>on</strong>sibility are most involved duringthe Planning, Developing, and Stabilizing Phases of the migrati<strong>on</strong> project.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Database Administra<strong>to</strong>rs. These pers<strong>on</strong>nel are knowledgeable aboutthe physical characteristics, logical characteristics, per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, and servicerequirements of the source database. These pers<strong>on</strong>nel also have knowledgeof any scripts and <strong>to</strong>ols that are used in database administrati<strong>on</strong>.<strong>SQL</strong> <strong>Server</strong> Database Administra<strong>to</strong>rs. These pers<strong>on</strong>nel are expert inarchitecting and implementing <strong>SQL</strong> <strong>Server</strong> databases. These team memberswill design the target <strong>SQL</strong> <strong>Server</strong> database envir<strong>on</strong>ment and per<str<strong>on</strong>g>for</str<strong>on</strong>g>m key tasksduring the actual migrati<strong>on</strong>.<strong>UNIX</strong> System Administra<strong>to</strong>rs. These pers<strong>on</strong>nel have complete knowledge ofthe <strong>UNIX</strong> servers and the operating system installati<strong>on</strong>s, such as versi<strong>on</strong>s,packages, c<strong>on</strong>figurati<strong>on</strong>, and security.Windows System Administra<strong>to</strong>rs. These pers<strong>on</strong>nel have completeknowledge of the Windows operating system and the Microsoft applicati<strong>on</strong>product line. These team members should have some experience in definingand implementing server technologies in Windows.<strong>UNIX</strong> Applicati<strong>on</strong> Developers. These pers<strong>on</strong>nel have knowledge of theapplicati<strong>on</strong>s that are running in the current <strong>UNIX</strong> envir<strong>on</strong>ment and theirimplementati<strong>on</strong> details.Windows Applicati<strong>on</strong> Developers. These pers<strong>on</strong>nel have per<str<strong>on</strong>g>for</str<strong>on</strong>g>meddevelopment in the Windows envir<strong>on</strong>ment <str<strong>on</strong>g>for</str<strong>on</strong>g> the technologies involved in thesoluti<strong>on</strong>.Security Specialists. These pers<strong>on</strong>nel have a wide base of knowledge aboutsecurity issues, including how security relates <strong>to</strong> networks, servers, databases,and applicati<strong>on</strong>s.Test Role. This role usually includes team members with the following job titlesand resp<strong>on</strong>sibilities:● Test Engineering Managers. These pers<strong>on</strong>nel have knowledge about testingapplicati<strong>on</strong> and database soluti<strong>on</strong>s and also have managerial experience.● <strong>UNIX</strong> Database and Applicati<strong>on</strong>s Testers. These pers<strong>on</strong>nel have knowledgeabout all databases and applicati<strong>on</strong>s that are running in the current <strong>UNIX</strong>envir<strong>on</strong>ment and provide input when test plans are created <str<strong>on</strong>g>for</str<strong>on</strong>g> the migratedenvir<strong>on</strong>ment.● Windows Database and Applicati<strong>on</strong>s Testers. These team members haveknowledge of databases and applicati<strong>on</strong>s in both <strong>UNIX</strong> and Windows. Thesepers<strong>on</strong>nel are experienced at creating and executing test plans.Release Management Role. This role usually includes team members with thefollowing job titles and resp<strong>on</strong>sibilities:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windowsxiii●●Deployment Manager. These pers<strong>on</strong>nel have knowledge of managing thedeployment of the new database and applicati<strong>on</strong>s in the producti<strong>on</strong>envir<strong>on</strong>ment.Technology Specialist. These pers<strong>on</strong>nel have knowledge of the technologyand processes in a data center operati<strong>on</strong>. They have intimate knowledge of thesoluti<strong>on</strong> being developed and will aid in transiti<strong>on</strong>ing them in<strong>to</strong> the producti<strong>on</strong>envir<strong>on</strong>ment.Knowledge PrerequisitesIt is assumed that the technically-oriented audience <str<strong>on</strong>g>for</str<strong>on</strong>g> this guide has, in aggregate, thefollowing specific technology competencies and proficiencies:● Expert level of <strong>UNIX</strong> development and administrati<strong>on</strong>● Expert level of Windows development and administrati<strong>on</strong>● Expert level of <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> administrati<strong>on</strong>● Knowledgeable staff <strong>to</strong> maintain the new envir<strong>on</strong>ment and the technologiesinvolved● Knowledgeable staff that understand any interacti<strong>on</strong> between the <strong>UNIX</strong> andWindows envir<strong>on</strong>ment when interoperability is created and maintainedHow <strong>to</strong> Use This <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g>The organizati<strong>on</strong> of this guide is based <strong>on</strong> the industry-proven need <strong>to</strong> manage ITprojects according <strong>to</strong> a disciplined process that improves the likelihood of the project'ssuccess. It is designed <strong>to</strong> be used with a compani<strong>on</strong> guide, the <strong>UNIX</strong> Migrati<strong>on</strong> Project<str<strong>on</strong>g>Guide</str<strong>on</strong>g> (UMPG). While this guide c<strong>on</strong>tains the technical and soluti<strong>on</strong>-specific in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>needed <str<strong>on</strong>g>for</str<strong>on</strong>g> the project, the UMPG provides the disciplined process steps <str<strong>on</strong>g>for</str<strong>on</strong>g> using thisin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in the c<strong>on</strong>text of a migrati<strong>on</strong> project and a team organizati<strong>on</strong> model ("peopleand process" guidance).To facilitate their side-by-side use, both guides use project phases as an organizati<strong>on</strong>aldevice. Specifically, they follow the structure of the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework(MSF), which defines five distinct phases <str<strong>on</strong>g>for</str<strong>on</strong>g> IT projects: Envisi<strong>on</strong>ing, Planning,Developing (or <str<strong>on</strong>g>Migrating</str<strong>on</strong>g>), Stabilizing, and Deploying. Each guide presents thein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> (process or technical) needed <str<strong>on</strong>g>for</str<strong>on</strong>g> a phase within chapters named <str<strong>on</strong>g>for</str<strong>on</strong>g> thatphase. For example, in the soluti<strong>on</strong> guide, business and technical in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> needed <str<strong>on</strong>g>for</str<strong>on</strong>g>the initial decisi<strong>on</strong>-making is in the Envisi<strong>on</strong>ing chapter and detailed procedures andscripts are in the <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> chapters.The UMPG is essentially "MSF applied <strong>to</strong> <strong>UNIX</strong> migrati<strong>on</strong> projects." It begins with anoverview of MSF and then describes the processes that bel<strong>on</strong>g <strong>to</strong> each phase and theteam roles resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> them — it is not, however, meant <strong>to</strong> serve as a comprehensiveintroducti<strong>on</strong> <strong>to</strong> MSF. In-depth in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about MSF is available <strong>to</strong> interested readers <strong>on</strong>the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Frameworks Web site at http://www.microsoft.com/msf.The reas<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> separating the process guidance from technical and project-specificguidance is <strong>to</strong> keep this guide as lean as possible. It is recognized that some readersneed <strong>to</strong> focus narrowly <strong>on</strong> project tasks, while pers<strong>on</strong>s with project management andteam lead resp<strong>on</strong>sibilities need <strong>to</strong> digest the UMPG guidance and apply it <strong>to</strong> the project.Because organizati<strong>on</strong>al pers<strong>on</strong>nel and project team members tend <strong>to</strong> have differentlevels of involvement during different phases, the divisi<strong>on</strong> of c<strong>on</strong>tent according <strong>to</strong> projectphase also supports the ability <strong>to</strong> focus <strong>on</strong> the material that is most relevant <strong>to</strong> aparticular resp<strong>on</strong>sibility.


xivPrefaceIt is important <str<strong>on</strong>g>for</str<strong>on</strong>g> you <strong>to</strong> note the c<strong>on</strong>tent scope of this guidance. The applicati<strong>on</strong>migrati<strong>on</strong> and interoperati<strong>on</strong>-related in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in this soluti<strong>on</strong> <strong>on</strong>ly discusses issuespertaining <strong>to</strong> the database c<strong>on</strong>nectivity logic. It does not discuss general applicati<strong>on</strong>porting issues between <strong>UNIX</strong> and Windows such as mapping <strong>UNIX</strong> system calls <strong>to</strong>Windows APIs and migrating the graphical user interface (GUI). For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>about <strong>UNIX</strong> <strong>to</strong> Windows applicati<strong>on</strong> migrati<strong>on</strong>, refer <strong>to</strong> the <strong>UNIX</strong> Applicati<strong>on</strong> Migrati<strong>on</strong><str<strong>on</strong>g>Guide</str<strong>on</strong>g> (UAMG) available at http://msdn.microsoft.com/library/default.asp?url=/library/enus/dnucmg/html/ucmglp.asp.Note Although the two guides are designed <strong>to</strong> be used <strong>to</strong>gether, it is not necessary <strong>to</strong>follow the MSF processes and team guidance described in the UMPG if theorganizati<strong>on</strong> has an alternative project methodology in place. In that case, the UMPGwould be used merely <strong>to</strong> map the MSF phases and team structure <strong>to</strong> the elements ofthe organizati<strong>on</strong>'s methodology. Readers who will use this guide <strong>to</strong> implement a projectshould read at least the overview of MSF in the UMPG <strong>to</strong> familiarize themselves withthe MSF Process Model, the MSF Team Model, and MSF terminology.Figure 0.1 represents the chapters of interest <strong>to</strong> readers with different areas ofresp<strong>on</strong>sibility.Figure 0.1Chapters of interest by team role


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> WindowsxvOrganizati<strong>on</strong> by ChapterThe following chapter list provides an overview of the c<strong>on</strong>tent and structure of this guide.●●●●●●●●●●●●●●●Preface.Chapter 1: Introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework. This chapterprovides a brief introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework (MSF) and howit is applied <strong>to</strong> migrati<strong>on</strong> projects.Chapter 2: Envisi<strong>on</strong>ing Phase. This chapter provides guidance <strong>to</strong> carry out thevarious activities of the Envisi<strong>on</strong>ing Phase in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows migrati<strong>on</strong> project. These activities include understanding your businessand technical goals, assessing your current situati<strong>on</strong> at a high level, building ahigh-level soluti<strong>on</strong> c<strong>on</strong>cept, setting up the project team, and assessing projectrisks.Chapter 3: Planning Phase. This chapter provides guidance <strong>to</strong> carry out thevarious activities of the Planning Phase in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows migrati<strong>on</strong> project. These activities include creating a detailed assessmen<strong>to</strong>f the current envir<strong>on</strong>ment, developing the soluti<strong>on</strong> design and architecture, andproducing detailed project plans and project schedule.Chapter 4: Developing: Databases — Introducti<strong>on</strong>. This chapter introduces thedifferent tasks in migrating the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> 2000.Chapter 5: Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Architecture.This chapter describes the steps <str<strong>on</strong>g>for</str<strong>on</strong>g> creating an instance of <strong>SQL</strong> <strong>Server</strong> which isequivalent in architecture <strong>to</strong> the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.Chapter 6: Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas. This chapter showshow <strong>to</strong> migrate a schema owner and its objects <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database.Chapter 7: Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Users. Thischapter c<strong>on</strong>tains detailed steps <str<strong>on</strong>g>for</str<strong>on</strong>g> creating users in the <strong>SQL</strong> <strong>Server</strong> databasesand granting them the same kind of privileges they had in the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database.Chapter 8: Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data. This chapter exploresthe different opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating the applicati<strong>on</strong> data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.It provides details in the usage of each of the opti<strong>on</strong>s.Chapter 9: Developing: Databases — Unit Testing the Migrati<strong>on</strong>. This chapterc<strong>on</strong>tains the processes <str<strong>on</strong>g>for</str<strong>on</strong>g> testing the migrated database, its objects, and data.Chapter 10: Developing: Applicati<strong>on</strong>s — Introducti<strong>on</strong>. This chapter introducesthe procedures <strong>to</strong> migrate the applicati<strong>on</strong> and the API (the c<strong>on</strong>nectivity tierbetween the database and the applicati<strong>on</strong>) from the existing soluti<strong>on</strong> <strong>to</strong> theproposed soluti<strong>on</strong>.Chapter 11: Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>.This chapter provides specific steps and procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>verting <strong>SQL</strong>statements and PL/<strong>SQL</strong> code <str<strong>on</strong>g>for</str<strong>on</strong>g> use with <strong>SQL</strong> <strong>Server</strong>.Chapter 12: Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Perl. This chapter providesspecific steps and procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating Perl applicati<strong>on</strong>s <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows envir<strong>on</strong>ment.Chapter 13: Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHP. This chapter providesspecific steps and procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating PHP applicati<strong>on</strong>s <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows envir<strong>on</strong>ment.Chapter 14: Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Java. This chapter providesspecific steps and procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating Java applicati<strong>on</strong>s <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows envir<strong>on</strong>ment.


xviPreface●●●●●●●●●●Chapter 15: Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Pyth<strong>on</strong>. This chapterprovides specific steps and procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating Pyth<strong>on</strong> applicati<strong>on</strong>s <strong>to</strong> the<strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows envir<strong>on</strong>ment.Chapter 16: Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*C. This chapterprovides specific steps and procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating Pro*C applicati<strong>on</strong>s <strong>to</strong> the <strong>SQL</strong><strong>Server</strong> <strong>on</strong> Windows envir<strong>on</strong>ment.Chapter 17: Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms. This chapterdiscusses the opti<strong>on</strong>s available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms-based applicati<strong>on</strong>.Chapter 18: Stabilizing Phase. In this chapter, the soluti<strong>on</strong> is tested in anenvir<strong>on</strong>ment similar <strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment. This chapter describes thevarious testing opti<strong>on</strong>s and processes that can be implemented <strong>to</strong> ensure thequality of the soluti<strong>on</strong>.Chapter 19: Deploying Phase. This chapter describes the procedure <str<strong>on</strong>g>for</str<strong>on</strong>g> movingthe soluti<strong>on</strong> in<strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment and transferring ownership of thesoluti<strong>on</strong> <strong>to</strong> operati<strong>on</strong>s. The chapter also identifies the tests that need <strong>to</strong> beper<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong> the soluti<strong>on</strong> during deployment.Chapter 20: Operati<strong>on</strong>s. This chapter provides references <strong>to</strong> existing operati<strong>on</strong>alguides <strong>to</strong> administer a Windows-based server infrastructure and <strong>SQL</strong> <strong>Server</strong> 200based databases.Appendix A: <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Professi<strong>on</strong>als. This appendix providesin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>to</strong> help <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBAs who do not have <strong>SQL</strong> <strong>Server</strong> experience learnabout its administrati<strong>on</strong>.Appendix B: Getting the Best Out of <strong>SQL</strong> <strong>Server</strong> 2000 and Windows. Thisappendix provides reference <strong>to</strong> material <strong>to</strong> optimize and take advantage of <strong>SQL</strong><strong>Server</strong> and Windows.Appendix C: Baselining. This appendix provides detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> aboutcollecting statistics in <strong>SQL</strong> <strong>Server</strong>.Appendix D: Installing Comm<strong>on</strong> Applicati<strong>on</strong>s and Drivers. This appendixprovides installati<strong>on</strong> instructi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong>s and drivers that may be usedwhile migrating the applicati<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> WindowsxviiDocument C<strong>on</strong>venti<strong>on</strong>sThis guide uses the style c<strong>on</strong>venti<strong>on</strong>s shown in Table 0.1.Table 0.1: Document C<strong>on</strong>venti<strong>on</strong>sText ElementMeaningBold textBold text is used in the c<strong>on</strong>text ofparagraphs <str<strong>on</strong>g>for</str<strong>on</strong>g> commands; literalarguments <strong>to</strong> commands (including pathswhen they <str<strong>on</strong>g>for</str<strong>on</strong>g>m part of the command);switches; and programming elements,such as methods, functi<strong>on</strong>s, data types,and data structures. User interfaceelements are also identified with bold f<strong>on</strong>t.Italic textItalic text is used in the c<strong>on</strong>text ofparagraphs <str<strong>on</strong>g>for</str<strong>on</strong>g> variables <strong>to</strong> be replaced bythe user. It is also used <strong>to</strong> emphasizeimportant in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.M<strong>on</strong>ospace f<strong>on</strong>tUsed <str<strong>on</strong>g>for</str<strong>on</strong>g> excerpts from c<strong>on</strong>figurati<strong>on</strong> files,code examples, and terminal sessi<strong>on</strong>s.M<strong>on</strong>ospace bold f<strong>on</strong>tUsed <strong>to</strong> represent commands or other textthat the user types.M<strong>on</strong>ospace italic f<strong>on</strong>tUsed <strong>to</strong> represent variables the readersupplies in command line examples andterminal sessi<strong>on</strong>s.UPPERCASETransact-<strong>SQL</strong> keywords and <strong>SQL</strong>elements.%SystemRoot% The folder in which Windows <strong>Server</strong> 2003is installed.Job AidsThe job aids included with this guide can be used <strong>to</strong> support the various tasks per<str<strong>on</strong>g>for</str<strong>on</strong>g>medduring the different phases of the migrati<strong>on</strong>. The aids are in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m of questi<strong>on</strong>naires,<strong>to</strong>ols, and templates used <str<strong>on</strong>g>for</str<strong>on</strong>g> designing, planning, and managing the migrati<strong>on</strong> project.The job aids are either in Microsoft Excel spreadsheet or Microsoft Word document<str<strong>on</strong>g>for</str<strong>on</strong>g>mat. They are available in the Tools and Templates folder in the zip file download ofthis guidance at http://go.microsoft.com/fwlink/?LinkId=45289.The purpose of providing job aids is <strong>to</strong> help you speed up the development of yourproject documents. New or additi<strong>on</strong>al guidance is not provided in the job aids. Instead,the job aids are generic templates that you should cus<strong>to</strong>mize <strong>to</strong> fit your requirements.


xviiiPrefaceTable 1.2: Job Aids Descripti<strong>on</strong>sJob AidVisi<strong>on</strong>/ScopeProject StructureMigrati<strong>on</strong> Risk Exposure Rating FormAssessing the Current Envir<strong>on</strong>mentTemplateDevelopment PlanTest PlanPilot PlanDeployment PlanDescripti<strong>on</strong>Use this template <strong>to</strong> describe the goals ofthe project and the approaches that theteam will use <strong>to</strong> achieve those goals.Use this template <strong>to</strong> define how the projectis structured and managed and how thesoluti<strong>on</strong> will be created. This template willhelp you c<strong>on</strong>trol and coordinate the entireproject.This spreadsheet will help you identify thepossible migrati<strong>on</strong> risks and theirc<strong>on</strong>sequences. In additi<strong>on</strong>, this documentalso helps you <strong>to</strong> prioritize the risks andprepare a mitigati<strong>on</strong> plan <str<strong>on</strong>g>for</str<strong>on</strong>g> each risk.This template provides separatespreadsheets <strong>to</strong> assist in assessing theapplicati<strong>on</strong>, database, and serverenvir<strong>on</strong>ments.This template helps you <strong>to</strong> describe thesoluti<strong>on</strong> development process used <str<strong>on</strong>g>for</str<strong>on</strong>g> theproject. This plan provides the technicaldetails of what will be built, and it providesc<strong>on</strong>sistent guidelines and processes <strong>to</strong> theteams creating the soluti<strong>on</strong>.This template helps you <strong>to</strong> describe thestrategy and approach used <strong>to</strong> plan,organize, and manage the project’s testingactivities. It identifies testing objectives,methodologies and <strong>to</strong>ols, expected results,resp<strong>on</strong>sibilities, and resourcerequirements.This template c<strong>on</strong>tains in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>to</strong> helpprepare and execute a successful pilot. Itincludes pilot scope, user interacti<strong>on</strong>s andpilot evaluati<strong>on</strong>This template helps you <strong>to</strong> describe theacti<strong>on</strong>s necessary <str<strong>on</strong>g>for</str<strong>on</strong>g> a smoothdeployment and transiti<strong>on</strong> <strong>to</strong> <strong>on</strong>goingoperati<strong>on</strong>s. It covers the processes ofpreparing, installing, testing, training, andtransferring the soluti<strong>on</strong> <strong>to</strong> operati<strong>on</strong>s.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> WindowsxixC<strong>on</strong>tribu<strong>to</strong>rsThe following organizati<strong>on</strong>s and individuals c<strong>on</strong>tributed <strong>to</strong> this project.Program ManagerDhilip Gopalakrishnan (Microsoft)AuthorScalability ExpertsEdi<strong>to</strong>rsThomas Olsen (Volt Technical Services)Gaile Simm<strong>on</strong>s (Microsoft)ArchitectsPeter Skjøtt Larsen (Microsoft)Jas<strong>on</strong> Zi<strong>on</strong>s (Microsoft)TestSandor Kiss (Microsoft)Infosys TechnologiesFeedbackPlease direct questi<strong>on</strong>s and comments about this guide <strong>to</strong> cisfdbk@microsoft.com.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 11Introducti<strong>on</strong> <strong>to</strong> the Microsoft<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s FrameworkIntroducti<strong>on</strong> and GoalsFor large-scale projects, such as database migrati<strong>on</strong>s, it is vital <strong>to</strong> have a cohesive andstructured project framework in place. This foundati<strong>on</strong> ensures that projects are carefullyplanned, roles and tasks are clearly identified and defined, and that the thousands ofcrucial details are addressed <str<strong>on</strong>g>for</str<strong>on</strong>g> a successful migrati<strong>on</strong>.In this chapter, you will learn about Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework (MSF), which hasbeen used successfully <strong>on</strong> numerous IT projects. This adaptable and robust projectframework provides a comprehensive structure that assists in guiding the project from theinitial planning stages until after the project has been completed. If you are familiar withMSF, skip this chapter and c<strong>on</strong>tinue with Chapter 2, "Envisi<strong>on</strong>ing Phase."Overview of MSFEvery successful project follows a methodology <strong>to</strong> achieve its objectives. Themethodology employed in this migrati<strong>on</strong> guide is the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework. Avast amount of in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about MSF is available from Microsoft, and the <strong>UNIX</strong>Migrati<strong>on</strong> Project <str<strong>on</strong>g>Guide</str<strong>on</strong>g> provides a thorough explanati<strong>on</strong> of MSF <str<strong>on</strong>g>for</str<strong>on</strong>g> specific audiences ofthis migrati<strong>on</strong> guide, such as the team members that fulfill the Program Managementrole. Yet not every team member <strong>on</strong> your migrati<strong>on</strong> project needs in-depth knowledge ofMSF <strong>to</strong> successfully per<str<strong>on</strong>g>for</str<strong>on</strong>g>m their team functi<strong>on</strong>. Because this is the case, the followingbrief overview is intended <strong>to</strong> provide all team members with a high-level overview of MSFthat will familiarize them with basic c<strong>on</strong>cepts and terminology and help them <strong>to</strong> betterunderstand the specific secti<strong>on</strong>s of this migrati<strong>on</strong> guide that they will need <strong>to</strong> read,understand, and execute.MSF was created <strong>to</strong> maximize the success of IT projects throughout the entire IT lifecycle. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is derived from the experience gained within Microsoft <strong>on</strong> largescalesoftware development and service operati<strong>on</strong> projects, the experience of Microsoft’sc<strong>on</strong>sultants, and comm<strong>on</strong> best practices from the worldwide IT industry.As opposed <strong>to</strong> a prescriptive methodology, MSF provides a flexible and scalableframework <strong>to</strong> meet the needs of any sized organizati<strong>on</strong> or project team. MSF guidancec<strong>on</strong>sists of principles, models, and disciplines <str<strong>on</strong>g>for</str<strong>on</strong>g> managing the people, process, and


2Introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Frameworktechnology elements that most projects encounter. A detailed introducti<strong>on</strong> <strong>to</strong> the MSFmodels and disciplines is available at http://www.microsoft.com/msf.MSF Foundati<strong>on</strong>al PrinciplesAt the core of MSF are eight foundati<strong>on</strong>al principles. For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the eightfoundati<strong>on</strong>al principles, download the MSF Versi<strong>on</strong> 3 Overview fromhttp://msdn.microsoft.com/vstudio/enterprise/msf/.The eight foundati<strong>on</strong>al principles of MSF are:● Foster open communicati<strong>on</strong>s. The MSF Process Model enables an open andfree flow of in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> am<strong>on</strong>g the team members and key stakeholders <strong>to</strong> preventmisunderstandings and reduce the probability that work will have <strong>to</strong> be red<strong>on</strong>e.Documenting the progress of the project and making it available <strong>to</strong> the teammembers, stakeholders, and cus<strong>to</strong>mers can best achieve this.● Work <strong>to</strong>ward a shared visi<strong>on</strong>. The MSF Process Model provides a phase (theEnvisi<strong>on</strong>ing Phase) and a separate milest<strong>on</strong>e (Visi<strong>on</strong>/Scope Approved) <str<strong>on</strong>g>for</str<strong>on</strong>g> creatinga shared visi<strong>on</strong>. A visi<strong>on</strong> includes detailed understanding of the goals andobjectives that the soluti<strong>on</strong> needs <strong>to</strong> achieve. A shared visi<strong>on</strong> highlights theassumpti<strong>on</strong>s that the team members and cus<strong>to</strong>mers have <str<strong>on</strong>g>for</str<strong>on</strong>g> the soluti<strong>on</strong>.● Empower team members. Empowering the team members implies that themembers accept resp<strong>on</strong>sibility and ownership of work assigned <strong>to</strong> them. Teamempowerment can be achieved by preparing schedules where the team memberscommit <strong>to</strong> complete their work <strong>on</strong> a fixed date. This makes the team members feelaccountable and also provides a method <str<strong>on</strong>g>for</str<strong>on</strong>g> identifying any potential delays earlyin the project.● Establish clear accountability and shared resp<strong>on</strong>sibility. The MSF TeamModel is based <strong>on</strong> the principle that each role is accountable <str<strong>on</strong>g>for</str<strong>on</strong>g> the quality of thesoluti<strong>on</strong>. All the team members share the overall resp<strong>on</strong>sibility of the projectbecause the project can fail due <strong>to</strong> a mistake made by a single member.● Focus <strong>on</strong> delivering business value. The soluti<strong>on</strong> must deliver value <strong>to</strong> theorganizati<strong>on</strong> in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m of business value. This business value is achieved <strong>on</strong>lyafter the soluti<strong>on</strong> is completely deployed in<strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment.● Stay agile, expect change. MSF assumes that the soluti<strong>on</strong> will encounterc<strong>on</strong>tinuous changes be<str<strong>on</strong>g>for</str<strong>on</strong>g>e being deployed <strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment. Theteam should be aware and prepared <strong>to</strong> manage such changes.● Invest in quality. In MSF, each team member is resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> the quality of thesoluti<strong>on</strong>. To c<strong>on</strong>firm the quality throughout the project's durati<strong>on</strong>, a test team is<str<strong>on</strong>g>for</str<strong>on</strong>g>med. This ensures that the soluti<strong>on</strong> meets the quality level of the stakeholders.● Learn from all experiences. MSF states that the experiences derived from <strong>on</strong>eproject should be used and shared with teams in other projects. Theseexperiences can also help <strong>to</strong> identify the best practices that should be followed inyour organizati<strong>on</strong>.The MSF Team Model — OverviewThe MSF Team Model was developed over a period of several years <strong>to</strong> compensate <str<strong>on</strong>g>for</str<strong>on</strong>g>some of the disadvantages imposed by the <strong>to</strong>p-down, hierarchical structure of traditi<strong>on</strong>alproject teams. Teams organized under the MSF Team Model are small andmultidisciplinary teams of peers, although the model is scalable <str<strong>on</strong>g>for</str<strong>on</strong>g> both small and largeprojects. Team members share resp<strong>on</strong>sibilities and balance each other’s competencies<strong>to</strong> keenly focus <strong>on</strong> the project at hand. They are expected <strong>to</strong> share a comm<strong>on</strong> project


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 3visi<strong>on</strong>, a focus <strong>on</strong> deploying the project, high standards <str<strong>on</strong>g>for</str<strong>on</strong>g> quality and communicati<strong>on</strong>,and a willingness <strong>to</strong> learn. Figure 1.1 shows the role clusters of the MSF Team Model.Figure 1.1The MSF Team ModelThe MSF Team Model emphasizes the importance of aligning role clusters (comm<strong>on</strong>lyreferred <strong>to</strong> simply as "roles") <strong>to</strong> business needs. It does this by organizing each rolearound a quality goal that the project must meet <strong>to</strong> be successful. Each role aggregates a"cluster" of related functi<strong>on</strong>al areas and resp<strong>on</strong>sibilities. The functi<strong>on</strong>al areas eachrequire a different discipline and focus, but are related in that they c<strong>on</strong>tribute <strong>to</strong>wardmeeting the quality goal.The result is a well-balanced team whose skills and perspective represent all of thefundamental project goals. For team members, possessing a clearly defined role andowning a clearly defined goal is motivati<strong>on</strong>al. It increases the understanding ofresp<strong>on</strong>sibilities, and ultimately leads <strong>to</strong> a better soluti<strong>on</strong>. Because each goal is critical <strong>to</strong>the success of a project, the roles that represent these goals are c<strong>on</strong>sidered <strong>to</strong> be equallyimportant. Pers<strong>on</strong>s filling the roles are given equal say in critical decisi<strong>on</strong>s and arethought of as peers. MSF teams are known as "teams of peers." Table 1.1 associateseach role cluster with a quality goal.Table 1.1: Role Clusters and Quality GoalsRole ClusterProgram ManagementDevelopmentTestUser ExperienceRelease ManagementProduct ManagementGoalDeliver the soluti<strong>on</strong> within project c<strong>on</strong>straintsBuild <strong>to</strong> specificati<strong>on</strong>Approve <str<strong>on</strong>g>for</str<strong>on</strong>g> release <strong>on</strong>ly after all product qualityissues are identified and addressedEnhance user effectivenessAchieve smooth deployment and <strong>on</strong>going operati<strong>on</strong>sSatisfy cus<strong>to</strong>mersThe MSF Process Model — OverviewThe MSF Process Model describes a high-level sequence of activities <str<strong>on</strong>g>for</str<strong>on</strong>g> building anddeploying IT soluti<strong>on</strong>s. Rather than prescribing a specific series of procedures, it isflexible enough <strong>to</strong> accommodate a broad range of IT projects. MSF combines twoindustry standard models: the waterfall model, which emphasizes the achievement ofmilest<strong>on</strong>es, and the spiral model, which focuses <strong>on</strong> the c<strong>on</strong>tinual need <strong>to</strong> refine the


4Introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Frameworkrequirements and estimates <str<strong>on</strong>g>for</str<strong>on</strong>g> a project. An innovative aspect of the MSF processmodel is that it covers the life cycle of a soluti<strong>on</strong> from project incepti<strong>on</strong> <strong>to</strong> live deployment.This helps project teams focus <strong>on</strong> cus<strong>to</strong>mer business value, because no value is realizeduntil the soluti<strong>on</strong> is deployed and in operati<strong>on</strong>.Figure 1.2The MSF Process Model showing phases and major milest<strong>on</strong>esMSF is a milest<strong>on</strong>e-driven process. Milest<strong>on</strong>es fall at the end of each phase and c<strong>on</strong>taincriteria <str<strong>on</strong>g>for</str<strong>on</strong>g> completing the phase. Important deliverables must have been completed andcritical questi<strong>on</strong>s, such as: Does the team agree <strong>on</strong> the project scope? Have we plannedenough <strong>to</strong> proceed? Have we built what we said we would build? Is the soluti<strong>on</strong> workingproperly <str<strong>on</strong>g>for</str<strong>on</strong>g> the cus<strong>to</strong>mer? must be satisfac<strong>to</strong>rily answered. The project team and keystakeholders review the deliverables and reach agreement that the project can proceed<strong>to</strong> the next phase in a milest<strong>on</strong>e meeting.MSF is also an iterative process. The process model is designed <strong>to</strong> accommodatechanging project requirements by iterating through short development cycles andincremental versi<strong>on</strong>s of the soluti<strong>on</strong>.The iterative aspect of the MSF process applies well <strong>to</strong> migrati<strong>on</strong> projects, which arefrequently driven by an iterative process. In some cases, the migrati<strong>on</strong> task itself isapproached iteratively. The first cycle migrates limited, basic functi<strong>on</strong>ality <strong>to</strong> the newplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m; and subsequent cycles add additi<strong>on</strong>al capabilities <strong>to</strong> the new envir<strong>on</strong>ment untilit is equivalent <strong>to</strong> the original, unmigrated technology. In some other migrati<strong>on</strong> projects,the first cycle completely migrates some technology <strong>to</strong> a new envir<strong>on</strong>ment, whilesubsequent cycles extend the technology bey<strong>on</strong>d its original capabilities. Iterativeapproaches <strong>to</strong> migrati<strong>on</strong> projects provide a means <strong>to</strong> c<strong>on</strong>trol project risk and creategreater flexibility <strong>to</strong> accommodate changing requirements.The MSF Process Model originated with the process used by Microsoft <strong>to</strong> developapplicati<strong>on</strong>s. This model may be applied <strong>to</strong> traditi<strong>on</strong>al applicati<strong>on</strong> developmentenvir<strong>on</strong>ments, but is equally appropriate <str<strong>on</strong>g>for</str<strong>on</strong>g> the development and deployment ofenterprise infrastructure soluti<strong>on</strong>s, Web development, e-commerce, and distributedapplicati<strong>on</strong>s.Although the Program Management Role orchestrates the overall process within eachphase, the successful achievement of each milest<strong>on</strong>e requires special leadership andaccountability from each of the other team roles. As a project moves sequentially througheach phase, the level of ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the roles varies. The use of milest<strong>on</strong>es helps <strong>to</strong>manage this ebb and flow of involvement in the project.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 5Table 1.2: Major Milest<strong>on</strong>es and Primary DriversMilest<strong>on</strong>eVisi<strong>on</strong>/Scope ApprovedProject Plans ApprovedScope CompleteRelease Readiness ApprovedDeployment CompletePrimary Driver(s)Product ManagementProgram ManagementDevelopment and User ExperienceTest and Release ManagementRelease ManagementEach phase also has interim milest<strong>on</strong>es that lead <strong>to</strong> the achievement of the final phasemilest<strong>on</strong>e. Recommended interim milest<strong>on</strong>es are shown in Figure 1.3, but they may need<strong>to</strong> be modified <str<strong>on</strong>g>for</str<strong>on</strong>g> a particular project.Figure 1.3MSF Process Model with interim milest<strong>on</strong>esThe MSF Disciplines — OverviewMSF makes use of three classic disciplines, Risk Management, Readiness Management,and Project Management, which it has adapted <strong>to</strong> fit the framework. They are reflected inboth the Process Model and the role resp<strong>on</strong>sibilities defined in the Team Model. Thissecti<strong>on</strong> describes each discipline briefly. For a thorough discussi<strong>on</strong> of each discipline andits applicati<strong>on</strong> within MSF, see the respective white papers available athttp://msdn.microsoft.com/vstudio/enterprise/msf/.Risk ManagementThe MSF Risk Management Discipline advocates proactive risk management, c<strong>on</strong>tinuousrisk assessment, and integrati<strong>on</strong> in<strong>to</strong> decisi<strong>on</strong>-making throughout the project andoperati<strong>on</strong>al life cycle. Risks are c<strong>on</strong>tinuously assessed, m<strong>on</strong>i<strong>to</strong>red, and actively manageduntil they are either resolved or the possible negative event happens and the risks have


6Introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Frameworkbecome real problems <strong>to</strong> be handled as such. The MSF risk management processdefines six logical steps the team uses <strong>to</strong> manage current risks, plan and execute riskmanagement strategies, and capture knowledge <str<strong>on</strong>g>for</str<strong>on</strong>g> the enterprise. Figure 1.4 illustratesthe relati<strong>on</strong>ship between the six steps.Figure 1.4The MSF risk management processThe following list provides detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about each of the six risk managementsteps.● Identify. The process of risk identificati<strong>on</strong> calls <str<strong>on</strong>g>for</str<strong>on</strong>g> all team members <strong>to</strong> participatein surfacing risks <strong>to</strong> make the team aware of potential problems. As the input <strong>to</strong> therisk management process, risk identificati<strong>on</strong> should be undertaken as early aspossible and repeated frequently throughout the project life cycle.● Analyze and Prioritize. Risk analysis trans<str<strong>on</strong>g>for</str<strong>on</strong>g>ms the estimates or data aboutspecific project risks that surface during risk identificati<strong>on</strong> in<strong>to</strong> a <str<strong>on</strong>g>for</str<strong>on</strong>g>m that the teamcan use <strong>to</strong> make decisi<strong>on</strong>s regarding prioritizati<strong>on</strong>. Risk prioritizati<strong>on</strong> enables theteam <strong>to</strong> commit project resources <strong>to</strong> manage the most important risks.● Plan and Schedule. Risk planning takes the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> obtained from riskanalysis and prioritizati<strong>on</strong> and uses it <strong>to</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>mulate strategies, plans, and acti<strong>on</strong>s.Risk scheduling ensures that these plans are approved and then incorporated in<strong>to</strong>the project management process and infrastructure <strong>to</strong> ensure that riskmanagement is carried out as part of the day-<strong>to</strong>-day activities of the team. Riskscheduling explicitly c<strong>on</strong>nects risk planning with project planning.● Track and Report. Risk tracking m<strong>on</strong>i<strong>to</strong>rs the status of specific risks and theprogress in their respective acti<strong>on</strong> plans. Risk tracking also includes m<strong>on</strong>i<strong>to</strong>ring theprobability, impact, exposure, and other measures of risk <str<strong>on</strong>g>for</str<strong>on</strong>g> changes that couldalter priority, risk plans, and project features, resources, or schedule. Risk trackingenables visibility of the risk management process within the project from theperspective of risk levels as opposed <strong>to</strong> the task completi<strong>on</strong> perspective of thestandard operati<strong>on</strong>al project management process. Risk reporting ensures that theteam, sp<strong>on</strong>sor, and other stakeholders are aware of the status of project risks andthe plans <strong>to</strong> manage them.● C<strong>on</strong>trol. Risk c<strong>on</strong>trol is the process of executing risk acti<strong>on</strong> plans and theirassociated status reporting. Risk c<strong>on</strong>trol also includes initiati<strong>on</strong> of project changec<strong>on</strong>trol requests when changes in risk status or risk plans could result in changesin project features, resources, or schedule.● Learn. Risk learning <str<strong>on</strong>g>for</str<strong>on</strong>g>malizes the less<strong>on</strong>s learned from the project, collects therelevant project artifacts and <strong>to</strong>ols, and captures that knowledge in reusable <str<strong>on</strong>g>for</str<strong>on</strong>g>m.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 7Readiness ManagementThe MSF Readiness Management Discipline defines readiness as a measurement of thecurrent state versus the desired state of knowledge, skills, and abilities (KSAs) ofindividuals in an organizati<strong>on</strong>. This measurement is the real or perceived capabilities ofthe individuals at any point during the <strong>on</strong>going process of planning, building, andmanaging soluti<strong>on</strong>s.Each role <strong>on</strong> a project team includes key functi<strong>on</strong>al areas that the individuals undertakingthose roles must be capable of fulfilling. Individual readiness is the measurement of thestate of an individual with regard <strong>to</strong> the KSAs needed <strong>to</strong> meet the resp<strong>on</strong>sibilities requiredof their particular role. The MSF Readiness Management Discipline includes a process <strong>to</strong>help teams prepare <str<strong>on</strong>g>for</str<strong>on</strong>g> the KSAs needed <strong>to</strong> build and manage projects and soluti<strong>on</strong>s.The most basic approach <strong>to</strong> the readiness process is simply <strong>to</strong> assess skills and makeappropriate changes through training. On projects that are small or have shorttimeframes, this streamlined approach is quite effective. For l<strong>on</strong>ger term or serialprojects, organizati<strong>on</strong>s can benefit from per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the steps of defining the skillsneeded, evaluating the results of change produced by training, and keeping track ofKSAs. This allows <str<strong>on</strong>g>for</str<strong>on</strong>g> the full realizati<strong>on</strong> of readiness management, and is typically whereorganizati<strong>on</strong>s reap the rewards of investments in readiness activities.The readiness management process is composed of four steps: Define, Assess, Change,and Evaluate. Each process step includes a series of tasks <strong>to</strong> help reach the next step.Figure 1.5The readiness management processDefineThis step focuses <strong>on</strong> defining requirements. It identifies and describes the scenarios,competencies, and proficiency levels needed <strong>to</strong> successfully plan, build, and manage thesoluti<strong>on</strong>s. It also determines which roles in the team should be proficient in the definedcompetencies. Depending <strong>on</strong> the role, the individual filling it may need <strong>to</strong> be proficient in<strong>on</strong>e or many of the defined competencies.Scenarios describe the different types of activities that occur in a typical enterprise.Scenarios generally fall in<strong>to</strong> <strong>on</strong>e of four categories defined in terms of the business valuethey offer the organizati<strong>on</strong> — High Potential, Strategic, Key Operati<strong>on</strong>al, and Support.Different scenarios call <str<strong>on</strong>g>for</str<strong>on</strong>g> different types of skills and knowledge and distinct approaches<strong>to</strong> obtaining the appropriate resources and skills <str<strong>on</strong>g>for</str<strong>on</strong>g> that project type.


8Introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework●●●●High Potential. These focus <strong>on</strong> the situati<strong>on</strong>s an IT department encounters whenplanning and designing <strong>to</strong> deploy, upgrade, or implement a new product,technology, or service in its organizati<strong>on</strong>. These are typically research typesituati<strong>on</strong>s in which the technology is brand new or in beta <str<strong>on</strong>g>for</str<strong>on</strong>g>m. The organizati<strong>on</strong>needs <strong>to</strong> have a high degree of agility and the capability <strong>to</strong> investigate andevaluate new technologies. For these scenarios, it needs <strong>to</strong> be prepared <strong>to</strong> obtain(<str<strong>on</strong>g>for</str<strong>on</strong>g> a short period) the best expertise available.Strategic. Scenarios in this category focus <strong>on</strong> the situati<strong>on</strong>s an IT department islikely <strong>to</strong> encounter when exploiting new technologies, products, or services. Theseare typically market-leading soluti<strong>on</strong>s that could lead <strong>to</strong> business trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>defining the <strong>to</strong>-be l<strong>on</strong>g-term architecture. Here the organizati<strong>on</strong> needs in-house, indepthexpertise at the soluti<strong>on</strong> architect level and the capability of bridging skillsacross technology <strong>to</strong> the business.Key Operati<strong>on</strong>al. Scenarios in this category focus <strong>on</strong> the situati<strong>on</strong>s an ITdepartment is likely <strong>to</strong> encounter <strong>on</strong>ce it has deployed, upgraded, or implementeda new product, technology, or service that has <strong>to</strong> coexist, or c<strong>on</strong>tinue <strong>to</strong> seamlesslyinteract with legacy software and systems. These are typically <strong>to</strong>day's businesscriticalsystems, aligned with the as-is technology architecture. Quality of technicalknowledge and process are critical, as is ready availability of the skills applicable <strong>to</strong>the relevant technologies. The challenges are easier <strong>to</strong> plan <str<strong>on</strong>g>for</str<strong>on</strong>g> when thetechnologies are proven. Typically, organizati<strong>on</strong>s obtain the readiness and skillsneeded in this scenario by out-sourcing or by developing str<strong>on</strong>g in-housecapability.Support. Scenarios in this category focus <strong>on</strong> situati<strong>on</strong>s in which it is necessary <strong>to</strong>extend the product <strong>to</strong> fit the needs of a cus<strong>to</strong>mer’s envir<strong>on</strong>ment. These aretypically valuable but not business-critical soluti<strong>on</strong>s and often involve legacytechnology. Here, cost of delivery becomes paramount and the organizati<strong>on</strong> maydecide <strong>to</strong> rely <strong>on</strong> external skills (particularly <str<strong>on</strong>g>for</str<strong>on</strong>g> legacy) <strong>on</strong> a reactive basis.When determining the most appropriate scenario <str<strong>on</strong>g>for</str<strong>on</strong>g> a migrati<strong>on</strong> project, keep in mindthat the technology being migrated was initially deployed under <strong>on</strong>e scenario. Forexample, it might have been implemented when the technology was new, or it might havebeen a key operati<strong>on</strong>al technology. As the new migrated envir<strong>on</strong>ment is envisi<strong>on</strong>ed,though, a different scenario may apply. If the technology has matured, <str<strong>on</strong>g>for</str<strong>on</strong>g> example, whatwas a “high potential” project may be treated, in migrati<strong>on</strong>, as a “key operati<strong>on</strong>al”scenario. Alternatively, what might have originally been a classical support-scenarioproject might involve, as a result of migrati<strong>on</strong> <strong>to</strong> newer technology, something more akin<strong>to</strong> the high potential scenario. Identifying the most appropriate scenario helps <strong>to</strong> map theappropriate competencies and proficiencies required <str<strong>on</strong>g>for</str<strong>on</strong>g> the migrati<strong>on</strong>.● Competencies describe the measurable objectives, or tasks, in a given scenariothat an individual needs <strong>to</strong> be able <strong>to</strong> complete with proficiency. A singlecompetency is used <strong>to</strong> define a major part of an individual’s job or job resp<strong>on</strong>sibilityrelating <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. A competency can be c<strong>on</strong>sidered a combinati<strong>on</strong> of skills,knowledge, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance requirements● Proficiencies are the measure of the capability <strong>to</strong> execute tasks associated with aparticular competency within a given scenario. An individual's proficiency levelprovides a baseline <str<strong>on</strong>g>for</str<strong>on</strong>g> analyzing the gap between that individual's current skill setand the necessary skills <str<strong>on</strong>g>for</str<strong>on</strong>g> completi<strong>on</strong> of the tasks associated with the givenscenario.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 9AssessThe assess step focuses <strong>on</strong> the individual team members. It determines thecompetencies that these individuals currently possess. It is during this step that analysisof the competencies as they relate <strong>to</strong> the various job roles is undertaken <strong>to</strong> determine theskills of individuals within each of these roles. The desired competencies are thenanalyzed against the current competencies — the “<strong>to</strong>-be" versus the “as-is.” This workenables the development of learning plans, so that desired competency levels can bereached. The following tasks need <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> complete the assess step:● Measure individuals' knowledge, skills, and abilities through self-assessments orskills assessments (tests).● Analyze gaps by comparing the individual's KSA measurements <strong>to</strong> the expectedproficiency level <str<strong>on</strong>g>for</str<strong>on</strong>g> the role. Individuals can then c<strong>on</strong>centrate <strong>on</strong> bridging thesegaps through the use of learning plans.● Create learning plans that identify the appropriate resources and methods (such astraining materials, courseware, white papers, computer based training, men<strong>to</strong>ring,<strong>on</strong>-the-job, and self-directed training) <strong>to</strong> fill the gaps. Learning plans should c<strong>on</strong>sis<strong>to</strong>f both <str<strong>on</strong>g>for</str<strong>on</strong>g>mal and in<str<strong>on</strong>g>for</str<strong>on</strong>g>mal learning activities, and guide individuals through theprocess of moving from <strong>on</strong>e proficiency level <strong>to</strong> the next.ChangeIn this step, individuals advance their skills through learning in order <strong>to</strong> bridge the gapbetween their current proficiency and desired proficiency levels. In this step, the followingtasks are accomplished:● Train individuals using the actual training, hands-<strong>on</strong> learning, and men<strong>to</strong>ringtechniques described in the learning plans.● Track the learning of each individual. M<strong>on</strong>i<strong>to</strong>r and report the progress of individualsand their skills by scenario and competency. Tracking progress enables individualand overall readiness <strong>to</strong> be determined at any time in the life cycle.EvaluateThis step determines whether the learning plans were effective and whether the less<strong>on</strong>slearned were successfully implemented <strong>on</strong> the job. At this point it is time <strong>to</strong>:● Review results <strong>to</strong> see if more training is necessary or if what was learned is beingimplemented <strong>on</strong> the job.● Manage knowledge <strong>to</strong> foster the sharing of the new intellectual resources. Thissharing of knowledge enhances the collective knowledge of the soluti<strong>on</strong> team andthe enterprise and fosters a learning community. Additi<strong>on</strong>ally, a <str<strong>on</strong>g>for</str<strong>on</strong>g>mal knowledgemanagement system can provide a way <strong>to</strong> share comm<strong>on</strong> and repeatable bestpractices that help reduce costs and risks <str<strong>on</strong>g>for</str<strong>on</strong>g> other project teams.The MSF Readiness Management Discipline is c<strong>on</strong>sidered an <strong>on</strong>going, iterativeapproach <strong>to</strong> readiness. Following the steps in the process helps manage the varioustasks required <strong>to</strong> align individual, project team, or organizati<strong>on</strong>al KSAs. It can lead <strong>to</strong>better individual, project team, and strategic planning success.


10Introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s FrameworkProject ManagementThe third important discipline adopted by MSF is the Project Management Discipline. Todeliver a soluti<strong>on</strong> within project c<strong>on</strong>straints, str<strong>on</strong>g project management skills areessential. The MSF Team Model does not c<strong>on</strong>tain a role known as Project Manager;however, most project management functi<strong>on</strong>s are c<strong>on</strong>ducted by the MSF ProgramManagement Role.Project management is a set of skills and techniques that include:● Integrating planning d<strong>on</strong>e <str<strong>on</strong>g>for</str<strong>on</strong>g> each aspect of the project.● C<strong>on</strong>ducting change c<strong>on</strong>trol.● Defining and managing the scope of the project.● Preparing a budget and managing costs.● Preparing and tracking schedules.● Getting the right resources allocated <strong>to</strong> the project.● Managing c<strong>on</strong>tracts and vendors, and procuring project resources.● Facilitating team and external communicati<strong>on</strong>s.● Facilitating the risk management process.● Documenting and tracking the team’s quality management process.Three distinctive characteristics of the MSF approach <strong>to</strong> project management stand out:● Most of the resp<strong>on</strong>sibilities of the role comm<strong>on</strong>ly known as "Project Manager" areencompassed in the MSF Program Management Role Cluster. As the size andcomplexity of a project grows, this role cluster is broken out in<strong>to</strong> two branches ofspecializati<strong>on</strong>: <strong>on</strong>e dealing with architecture and specificati<strong>on</strong>s and the otherdealing with project management.● In larger projects requiring scaled-up MSF teams, project management activitiesoccur at multiple levels. As the teams grow in number, the project managementactivities become distributed am<strong>on</strong>g the team leads <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the MSF teamroles. The Program Management Role is then resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> management of the“rolled up” work from the leads in order <strong>to</strong> manage the entire soluti<strong>on</strong>.● Some large or complex projects require a specialist Project Manager or projectmanagement team. As the size, complexity, or risk becomes very large, oftenspecialist roles or teams are created <strong>to</strong> focus <strong>on</strong> <strong>on</strong>e particular area. For theProgram Management Role, this can be d<strong>on</strong>e <strong>to</strong> break the many projectmanagement tasks in<strong>to</strong> smaller, more manageable resp<strong>on</strong>sibility areas. Thesecould include a specialist project manager, risk manager, soluti<strong>on</strong> architect,schedule administra<strong>to</strong>r, and so <strong>on</strong>.The differentiating fac<strong>to</strong>r of the MSF approach <strong>to</strong> project management is that the projectmanagement job functi<strong>on</strong> and activities do not impose a hierarchical structure <strong>on</strong> thedecisi<strong>on</strong>-making process. MSF advocates against a rigid, “dicta<strong>to</strong>r” project managementstyle because it works against an effective team of peers.The team of peers approach is a key success fac<strong>to</strong>r of MSF. All roles in MSF arec<strong>on</strong>sidered equally important and major decisi<strong>on</strong>s are arrived at by c<strong>on</strong>sensus of the coreteam. If that c<strong>on</strong>sensus cannot be achieved, the Program Management Role plays atiebreaker functi<strong>on</strong>, making the final decisi<strong>on</strong> <strong>on</strong> the issue by transiti<strong>on</strong>ing in<strong>to</strong> a decisi<strong>on</strong>leader <strong>to</strong> drive the project <str<strong>on</strong>g>for</str<strong>on</strong>g>ward. This decisi<strong>on</strong> is made from the perspective of meetingthe cus<strong>to</strong>mer’s requirements and delivering the soluti<strong>on</strong> within the c<strong>on</strong>straints. Afterward,the team immediately resumes their normal peer relati<strong>on</strong>ships.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 11Overview of MSF PhasesThe in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in this secti<strong>on</strong> describes the MSF phases that structure the organizati<strong>on</strong>of this migrati<strong>on</strong> guide. These phases create the structure used <str<strong>on</strong>g>for</str<strong>on</strong>g> the project throughoutthe rest of this guide.Envisi<strong>on</strong>ing PhaseIn the Envisi<strong>on</strong>ing Phase, the team identifies the visi<strong>on</strong> and scope of the project bypreparing a visi<strong>on</strong> and scope document.During this phase, goals <str<strong>on</strong>g>for</str<strong>on</strong>g> the project are <str<strong>on</strong>g>for</str<strong>on</strong>g>med and a visi<strong>on</strong> statement is created thatdefines the entire project. This shared visi<strong>on</strong> helps the team <strong>to</strong> work <strong>to</strong>wards a comm<strong>on</strong>objective. The project team is assembled and the team members are empowered byhaving roles and resp<strong>on</strong>sibilities assigned <strong>to</strong> them.Another important activity in this phase is the identificati<strong>on</strong> of risks and preparati<strong>on</strong> ofmitigati<strong>on</strong> and c<strong>on</strong>tingency plans. The risks identified and the mitigati<strong>on</strong> plans are usedthroughout the life cycle of the project. Refer <strong>to</strong> Chapter 2, "Envisi<strong>on</strong>ing Phase," <str<strong>on</strong>g>for</str<strong>on</strong>g> moredetails <strong>on</strong> the tasks and deliverables of the Envisi<strong>on</strong>ing Phase.Planning PhaseDuring this phase, the existing envir<strong>on</strong>ment is assessed <strong>to</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>m a soluti<strong>on</strong> design. Themain activity of this phase is <strong>to</strong> do a detailed planning <strong>to</strong> ensure success of the project. Inthis phase, a master project plan deliverable is created that c<strong>on</strong>sists of all sub-plans,such as the test plan, and development plan.The plan focuses <strong>on</strong> budgets, quality, schedule, and the technical implementati<strong>on</strong> of thesoluti<strong>on</strong>. The project team follows these plans in the subsequent phases. Refer <strong>to</strong>Chapter 3, "Planning Phase," <str<strong>on</strong>g>for</str<strong>on</strong>g> more details <strong>on</strong> the tasks and deliverables of thePlanning Phase.Developing PhaseDuring this phase, the applicati<strong>on</strong> comp<strong>on</strong>ents undergo trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> based <strong>on</strong> thedevelopment plans.Comp<strong>on</strong>ents that need a rewrite are developed. In comp<strong>on</strong>ents that are ported, changesbased <strong>on</strong> syntax compliancy, per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, and security are carried out. The source codeand executables help <strong>to</strong> create the deliverables of this stage. Refer <strong>to</strong> Chapter 4,"Developing: Databases — Introducti<strong>on</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> how <strong>to</strong> migrate adatabase. Chapter 10, "Developing: Applicati<strong>on</strong>s — Introducti<strong>on</strong>," provides differentscenarios <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating an applicati<strong>on</strong>.Stabilizing PhaseDuring this phase, all the comp<strong>on</strong>ents are tested collectively <strong>to</strong> ensure that the entiresoluti<strong>on</strong> operates properly.The testing criteria include achieving the desired functi<strong>on</strong>ality, security, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancerequirements. To ensure this, both white box and black box testing are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med. Thetested database and comp<strong>on</strong>ents <str<strong>on</strong>g>for</str<strong>on</strong>g>m the deliverables of this stage.Once testing is complete, the soluti<strong>on</strong> must be stabilized <strong>to</strong> ensure that it meets definedquality levels. If the migrati<strong>on</strong> is complex, a pilot test of the applicati<strong>on</strong> can also beper<str<strong>on</strong>g>for</str<strong>on</strong>g>med during the Stabilizing Phase. Refer <strong>to</strong> Chapter 18, "Stabilizing Phase," <str<strong>on</strong>g>for</str<strong>on</strong>g>more details <strong>on</strong> the tasks and deliverables of the Stabilizing Phase.


12Introducti<strong>on</strong> <strong>to</strong> the Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s FrameworkDeploying PhaseIn this phase, the team deploys the soluti<strong>on</strong> and ensures that it is stable and can beused. The tested soluti<strong>on</strong> is moved in<strong>to</strong> producti<strong>on</strong> and transferred <strong>to</strong> operati<strong>on</strong>s.During this phase, the soluti<strong>on</strong> comp<strong>on</strong>ents are tuned in the producti<strong>on</strong> envir<strong>on</strong>ment. Asoluti<strong>on</strong> signoff is obtained from all stakeholders that c<strong>on</strong>firms that the applicati<strong>on</strong> meetsthe requirements developed during the Envisi<strong>on</strong>ing and Planning Phases. Refer <strong>to</strong>Chapter 19, "Deploying Phase," <str<strong>on</strong>g>for</str<strong>on</strong>g> more details <strong>on</strong> the tasks and deliverables of theDeploying Phase. The migrati<strong>on</strong> project and the guidance are deeply rooted in the MSFmethodology, and the chapters are in chr<strong>on</strong>ological order of the MSF phases startingfrom Chapter 2, "Envisi<strong>on</strong>ing Phase, through Chapter 19, "Deploying Phase."


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 132Envisi<strong>on</strong>ing PhaseIntroducti<strong>on</strong> and GoalsThis chapter provides the process and technical in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> required <strong>to</strong> complete theEnvisi<strong>on</strong>ing Phase of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows® migrati<strong>on</strong> project.The Envisi<strong>on</strong>ing Phase is an early stage of planning. This is the period during which theteam, the cus<strong>to</strong>mer, and the sp<strong>on</strong>sors define the high-level requirements and overallgoals of the project. The main purpose of the work per<str<strong>on</strong>g>for</str<strong>on</strong>g>med during the phase is <strong>to</strong>ensure a comm<strong>on</strong> visi<strong>on</strong> and reach c<strong>on</strong>sensus am<strong>on</strong>g the team members that the projectis both valuable <strong>to</strong> the organizati<strong>on</strong> and likely <strong>to</strong> succeed. During the Envisi<strong>on</strong>ing Phase,the focus is <strong>on</strong> creating clear definiti<strong>on</strong>s of the problem and understanding the high levelapproach <strong>to</strong> solving the problem. This sets a solid foundati<strong>on</strong> from which specific planscan be developed during the Planning Phase and executed during all subsequent phases<strong>to</strong> achieve the migrati<strong>on</strong> objectives. The Envisi<strong>on</strong>ing Phase culminates in theVisi<strong>on</strong>/Scope Approved Milest<strong>on</strong>e.The key deliverables <str<strong>on</strong>g>for</str<strong>on</strong>g> the project team during the Envisi<strong>on</strong>ing Phase are:● Visi<strong>on</strong>/scope document. The visi<strong>on</strong>/scope document describes the project goalsand c<strong>on</strong>straints. It outlines the soluti<strong>on</strong> being developed, the requirements thesoluti<strong>on</strong> will meet, and the approach that the team will take <strong>to</strong> complete the project.The visi<strong>on</strong>/scope document is an early <str<strong>on</strong>g>for</str<strong>on</strong>g>m of the functi<strong>on</strong>al specificati<strong>on</strong> that isdeveloped during the Planning Phase. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> creating yourvisi<strong>on</strong>/scope document, refer <strong>to</strong> the visi<strong>on</strong>/scope template.● Project structure document. The project structure document defines the approachthe team will take <strong>to</strong> manage the project. It defines the team’s administrativestructure, standards, processes (such as versi<strong>on</strong> c<strong>on</strong>trol and change c<strong>on</strong>trol),project resources, and c<strong>on</strong>straints. The document identifies the team leadresp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> each MSF role.● Risk assessment document. The risk assessment document provides an initialidentificati<strong>on</strong> and analysis of risks associated with a project. This analysis includesmitigati<strong>on</strong> and c<strong>on</strong>tingency plans <strong>to</strong> help the team manage specific risks. Refer <strong>to</strong>the Risk Assessment template <str<strong>on</strong>g>for</str<strong>on</strong>g> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.Templates <str<strong>on</strong>g>for</str<strong>on</strong>g> each of these key deliverables are available in the Tools and Templatesfolder in the zip file download of this guidance athttp://go.microsoft.com/fwlink/?LinkId=45289.Table 2.1 lists the key activities that the team undertakes in the Envisi<strong>on</strong>ing Phase. Theresults of these activities are documented in this phase's deliverables.


14Envisi<strong>on</strong>ing PhaseTable 2.1: Major Tasks, Deliverables, and Primary OwnersTasks Project Deliverable Primary OwnerUnderstand the goals of the Visi<strong>on</strong>/scope document Product Managementmigrati<strong>on</strong> project (businessand design)Create the problemVisi<strong>on</strong>/scope document Product ManagementstatementCreate the visi<strong>on</strong> statement Visi<strong>on</strong>/scope document Product ManagementDefine end user profiles Visi<strong>on</strong>/scope document Product ManagementAssess the current situati<strong>on</strong> Visi<strong>on</strong>/scope document Program Management(high level)Identify high levelVisi<strong>on</strong>/scope document Product ManagementrequirementsDefine the project scope Visi<strong>on</strong>/scope document Program ManagementDefine the soluti<strong>on</strong> c<strong>on</strong>cept Visi<strong>on</strong>/scope document Program ManagementSet up a team Project structure document Program ManagementProduct ManagementDefine the project structure Project structure document Program ManagementAssess risk Risk assessment document Program ManagementNote This chapter provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the essential tasks of the Envisi<strong>on</strong>ingPhase <str<strong>on</strong>g>for</str<strong>on</strong>g> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows migrati<strong>on</strong> project. The chapteris not exhaustive. For a detailed descripti<strong>on</strong> of all the activities and deliverables <str<strong>on</strong>g>for</str<strong>on</strong>g> theMSF Envisi<strong>on</strong>ing Phase, refer <strong>to</strong> the <strong>UNIX</strong> Migrati<strong>on</strong> Project <str<strong>on</strong>g>Guide</str<strong>on</strong>g> (UMPG) available athttp://go.microsoft.com/fwlink/?LinkId=19832.Understand the Goals of the Migrati<strong>on</strong> ProjectAn early, clear understanding of the goals of the migrati<strong>on</strong> project by the project team isimperative <str<strong>on</strong>g>for</str<strong>on</strong>g> its success. These high level goals are not defined by the project team;they are defined by the business managers and major stakeholders. The reas<strong>on</strong>ing <str<strong>on</strong>g>for</str<strong>on</strong>g>reaching an early c<strong>on</strong>sensus <strong>on</strong> the goals includes:● The migrati<strong>on</strong> goals, <strong>on</strong>ce identified, are used <strong>to</strong> create a visi<strong>on</strong> statement <str<strong>on</strong>g>for</str<strong>on</strong>g> themigrati<strong>on</strong> project. This visi<strong>on</strong> statement is the key driver <str<strong>on</strong>g>for</str<strong>on</strong>g> all acti<strong>on</strong>s anddecisi<strong>on</strong>s made by the team during the course of the migrati<strong>on</strong> project.● The goals determine the aggregate skill set required by the project team <strong>to</strong>successfully execute the migrati<strong>on</strong> project.● The project team uses these goals <strong>to</strong> scope specific requirements that, in turn,serve as the basis <str<strong>on</strong>g>for</str<strong>on</strong>g> detailed soluti<strong>on</strong> designs and plans.● The goals serve as the basis <str<strong>on</strong>g>for</str<strong>on</strong>g> rec<strong>on</strong>ciling c<strong>on</strong>flicts and establishing priorities thatguide any trade-off decisi<strong>on</strong>s (schedule, features, resources, budgetaryrestricti<strong>on</strong>s) that need <strong>to</strong> be made later in the project.The project goals can be classified as business goals and design goals. Both types ofgoals are described in detail in the following secti<strong>on</strong>s.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 15Define the Business GoalsBusiness goals are established either <strong>to</strong> take advantage of an opportunity or <strong>to</strong> solve aproblem in the current business. Each organizati<strong>on</strong> has business goals specific <strong>to</strong> them.For example, a business goal <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>on</strong>e organizati<strong>on</strong> could be <strong>to</strong> “c<strong>on</strong>solidate the ERPapplicati<strong>on</strong>s across all worldwide units <strong>on</strong> <strong>on</strong>e software plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m after a merger withanother company,” while a different organizati<strong>on</strong> may have compliance with new federalregulati<strong>on</strong>s as its primary business goal. Because business goals can vary widely, thisguide does not provide a specific, comprehensive list of business goals. Yourorganizati<strong>on</strong> will have <strong>to</strong> determine the business goals specific <strong>to</strong> it. However, the twomost comm<strong>on</strong> business goals <str<strong>on</strong>g>for</str<strong>on</strong>g> IT projects are:● Reduce <strong>to</strong>tal cost of ownership (TCO) of the IT plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m● Maximize return <strong>on</strong> investment (ROI)Because these two business goals are so comm<strong>on</strong>, they are discussed in more detailunder the following headings.Reduce TCO of IT Plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mTCO of a system includes not <strong>on</strong>ly the price of purchasing software and hardware, butalso the cost of training users and supporting and maintaining the system. There<str<strong>on</strong>g>for</str<strong>on</strong>g>e,while evaluating the TCO of any system, there are several fac<strong>to</strong>rs <strong>to</strong> c<strong>on</strong>sider.● Cost of hardware. Evaluate the cost of server hardware, networking equipmentsuch as hubs and routers, and other equipment. Also include facilities cost <str<strong>on</strong>g>for</str<strong>on</strong>g>hosting the hardware.● Cost of software. Evaluate the cost of all software including the operating systemand applicati<strong>on</strong>s, such as database systems, developer <strong>to</strong>ols, and managementsoftware.● Reliability of the system. If the system fails or crashes often, the support cost <str<strong>on</strong>g>for</str<strong>on</strong>g>such a system would increase.● Cost of system maintenance. System administrati<strong>on</strong> is single highest cost fac<strong>to</strong>r<str<strong>on</strong>g>for</str<strong>on</strong>g> any IT organizati<strong>on</strong>. Evaluate the staff strength needed and associated costs<str<strong>on</strong>g>for</str<strong>on</strong>g> maintaining the system.● Cost of supporting the users. Users may need extensive training and frequentsupport, significantly adding <strong>to</strong> the TCO.● Projected cost of the migrati<strong>on</strong> project itself. Fac<strong>to</strong>rs such as availability ofskills in-house versus hiring external c<strong>on</strong>sultants will influence the project cost. Youwill be able <strong>to</strong> estimate these costs better after completing the Planning Phase.Microsoft offers several soluti<strong>on</strong>s <strong>to</strong> help reduce TCO.For example, Microsoft Visual Studio .NET provides an Integrated DevelopmentEnvir<strong>on</strong>ment (IDE) <str<strong>on</strong>g>for</str<strong>on</strong>g> rapid development of applicati<strong>on</strong>s that reduces the cost ofdeveloping and upgrading applicati<strong>on</strong>s. The Windows graphical user interface (GUI)envir<strong>on</strong>ment provides an easy-<strong>to</strong>-use interface <str<strong>on</strong>g>for</str<strong>on</strong>g> Windows users. The Windowsstandard GUI and GUI-based management applicati<strong>on</strong>s simplify server administrati<strong>on</strong>and thus c<strong>on</strong>tribute <strong>to</strong> reducing support costs.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about TCO <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, refer <strong>to</strong>http://www.microsoft.com/business/reducecosts/efficiency/c<strong>on</strong>solidate/tco.mspx.For cus<strong>to</strong>mer case studies about reduced TCO <strong>on</strong> a Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, refer <strong>to</strong>http://www.microsoft.com/business/reducecosts/efficiency/c<strong>on</strong>solidate/casestudies.mspx#EBAA.


16Envisi<strong>on</strong>ing PhaseMaximize ROITCO is c<strong>on</strong>cerned with an organizati<strong>on</strong>’s bot<strong>to</strong>m-line (cutting costs), and ROI is related <strong>to</strong>the <strong>to</strong>p line (increasing revenue). A lowered TCO and increased ROI scenario is theultimate goal of any migrati<strong>on</strong> project. To estimate the ROI due <strong>to</strong> the migrati<strong>on</strong> ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t,you should take in<strong>to</strong> account the following c<strong>on</strong>siderati<strong>on</strong>s:● Creati<strong>on</strong> of new business opportunities. The migrati<strong>on</strong> may provide newtechnological capabilities and drive new business innovati<strong>on</strong>s that lead <strong>to</strong>increased revenue.● Opportunities created by improved per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. For example, a fasterresp<strong>on</strong>se time <strong>to</strong> <strong>on</strong>line users <strong>on</strong> a Web site can drive more satisfied cus<strong>to</strong>mers <strong>to</strong>the site and increase profitability.● Total downtime required <strong>to</strong> complete the migrati<strong>on</strong>. System downtime canaffect revenue and should be minimized.● Reliability of the system. Unplanned system downtime can negatively affectproductivity and revenue.● Time <strong>to</strong> recover investment costs. The business needs <strong>to</strong> understand how l<strong>on</strong>git expects <strong>to</strong> realize a return <strong>on</strong> the investment in the project.● Impact <strong>on</strong> user productivity due <strong>to</strong> the migrati<strong>on</strong>. If users are going <strong>to</strong> take al<strong>on</strong>g time <strong>to</strong> ramp up <strong>on</strong> the new technology, it can impact the near termproductivity and profitability of the organizati<strong>on</strong>. Productivity can also be affectedpositively by easing the integrati<strong>on</strong> between the database applicati<strong>on</strong> and otheroffice software.● Managing risk. The organizati<strong>on</strong> needs <strong>to</strong> evaluate the risk of doing the project aswell as not doing the project. Not taking the risk may be the path of leastresistance, but it may deprive you of significant revenue opportunities. Proven bestpractices and processes can minimize risk and make the migrati<strong>on</strong> morepredictable. Several system integra<strong>to</strong>rs (SIs) offer service offerings that can greatlymitigate the risk. The SIs who are known <strong>to</strong> offer <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> migrati<strong>on</strong>offerings, as of publishing this soluti<strong>on</strong>, are listed in the "Set Up a Team" secti<strong>on</strong>later in this chapter.Some of the questi<strong>on</strong>s that result from these c<strong>on</strong>siderati<strong>on</strong>s can be answered byanalysis. However, a proof-of-c<strong>on</strong>cept or a limited pilot exercise can help providequantifiable answers <strong>to</strong> these questi<strong>on</strong>s, including estimating applicati<strong>on</strong> migrati<strong>on</strong> costsand determining the reliability of software. More in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is available in the "TechnicalProof of C<strong>on</strong>cept" secti<strong>on</strong> of Chapter 3, "Planning Phase."Identify the Design GoalsDesign goals are similar <strong>to</strong> business goals in many ways. The difference is that designgoals focus more <strong>on</strong> the attributes of the soluti<strong>on</strong> and less <strong>on</strong> what the soluti<strong>on</strong> willaccomplish <str<strong>on</strong>g>for</str<strong>on</strong>g> the business. As with business goals, an organizati<strong>on</strong>'s design goals areunique and specific <strong>to</strong> that organizati<strong>on</strong>. For example, <strong>on</strong>e organizati<strong>on</strong> may determinethat “corporate data should be accessible from the mobile devices issued <strong>to</strong> companyemployees.” A different organizati<strong>on</strong>'s primary design goal may be <strong>to</strong> “reduce the timeand level of ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t required <str<strong>on</strong>g>for</str<strong>on</strong>g> a user <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the server and complete a task.” Thisguide does not provide a specific list of design goals. Your organizati<strong>on</strong> will have <strong>to</strong>determine the design goals specific <strong>to</strong> it. However, the following list provides the six mostcomm<strong>on</strong> and generic design goals <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> <strong>to</strong> Windows migrati<strong>on</strong> projects.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 17●●●●High availability and reliability. The soluti<strong>on</strong> should process requests withoutinterrupti<strong>on</strong>, even in the event of a failure. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> Windowsreliability, refer <strong>to</strong> http://www.microsoft.com/mscorp/twc/reliability/default.mspx<strong>SQL</strong> <strong>Server</strong> allows <str<strong>on</strong>g>for</str<strong>on</strong>g> servers <strong>to</strong> be clustered in<strong>to</strong> groups of c<strong>on</strong>nected nodes. Thesoluti<strong>on</strong> described in this guide provides high availability <str<strong>on</strong>g>for</str<strong>on</strong>g> business applicati<strong>on</strong>s.If there is a failure of the operating system, hardware, or any planned upgradeevent <strong>on</strong> a single machine, <strong>SQL</strong> <strong>Server</strong> can be c<strong>on</strong>figured <strong>to</strong> fail over <strong>to</strong> anothernode, minimizing down time. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about <strong>SQL</strong> <strong>Server</strong> clustering,refer <strong>to</strong> http://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/enus/part4/c1261.mspx.Robust security. In business, data security is vital. Launched under theTrustworthy Computing Initiative, Windows <strong>Server</strong> 2003 was designed with anemphasis <strong>on</strong> security.Many new features have been added, including support <str<strong>on</strong>g>for</str<strong>on</strong>g> str<strong>on</strong>g authenticati<strong>on</strong>pro<strong>to</strong>cols such as Kerberos, 802.11x (WiFi) and Internet Pro<strong>to</strong>col Security (IPSec).For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about Windows <strong>Server</strong> 2003 security, refer <strong>to</strong>http://www.microsoft.com/windowsserver2003/technologies/security.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about <strong>SQL</strong> <strong>Server</strong> 2000 security, refer <strong>to</strong> the following threeresources:http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sp3sec01.mspxhttp://www.microsoft.com/sql/techinfo/administrati<strong>on</strong>/2000/security/default.asphttp://www.microsoft.com/sql/evaluati<strong>on</strong>/features/security.aspHigh per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and scalability. The system should show an acceptable levelof per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance even when the number of users increases.<strong>SQL</strong> <strong>Server</strong> 2000 can support multi-terabyte databases served <strong>to</strong> milli<strong>on</strong>s of users.This scalability is achieved by supporting scale up <strong>on</strong> symmetric multiprocessor(SMP) systems, allowing the installati<strong>on</strong> of additi<strong>on</strong>al processors, memory, disksand networking <strong>to</strong> build a large single node. In additi<strong>on</strong>, <strong>SQL</strong> <strong>Server</strong> supports scaleout, or allowing large databases <strong>to</strong> be split between a cluster of servers. Eachserver s<strong>to</strong>res a porti<strong>on</strong> of the database and assists in processing functi<strong>on</strong>s. Formore in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about Windows per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and scalability, refer <strong>to</strong> the followingtwo resources:http://www.microsoft.com/windowsserver2003/evaluati<strong>on</strong>/per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance/default.mspxhttp://www.microsoft.com/windowsserver2003/techinfo/serverroles/appserver/scale.mspxFor more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about <strong>SQL</strong> <strong>Server</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and scalability, refer <strong>to</strong> thefollowing two resources:http://www.microsoft.com/technet/prodtechnol/sql/2000/plan/ssmsam.mspxhttp://www.microsoft.com/sql/evaluati<strong>on</strong>/compare/benchmarks.aspEasy manageability. The system should provide easy ways <str<strong>on</strong>g>for</str<strong>on</strong>g> the administra<strong>to</strong>rs<strong>to</strong> install, manage, and maintain the operating system, applicati<strong>on</strong> software, andupdates. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> management products from Microsoft, refer <strong>to</strong>http://www.microsoft.com/management/default.mspx.<strong>SQL</strong> <strong>Server</strong> provides a number of robust administrati<strong>on</strong> <strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> managing data.Tools include graphic administrati<strong>on</strong> <strong>to</strong>ols, task wizards, and command line utilities.For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the <strong>SQL</strong> <strong>Server</strong> <strong>to</strong>ol set, refer <strong>to</strong> the following tworesources:http://www.microsoft.com/technet/prodtechnol/sql/2000/books/c01ppcsq.mspx


18Envisi<strong>on</strong>ing Phase●●http://msdn.microsoft.com/library/default.asp?url=/library/enus/use<strong>to</strong>ols/use<strong>to</strong>ols_4ovn.aspC<strong>on</strong>solidati<strong>on</strong> of servers. The new system should allow <str<strong>on</strong>g>for</str<strong>on</strong>g> the c<strong>on</strong>solidati<strong>on</strong> ofexisting databases in<strong>to</strong> a small number of servers. If the existing soluti<strong>on</strong> is based<strong>on</strong> older hardware, a migrati<strong>on</strong> presents an opportunity <strong>to</strong> c<strong>on</strong>solidate <strong>to</strong> fewer andmore powerful servers.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about Windows <strong>Server</strong> 2003 Datacenter Editi<strong>on</strong> — theMicrosoft server operating system optimized <str<strong>on</strong>g>for</str<strong>on</strong>g> server c<strong>on</strong>solidati<strong>on</strong> — refer <strong>to</strong>http://www.microsoft.com/windowsserver2003/datacenter/default.mspx.Interoperability with the existing <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. The new system shouldintegrate with the existing applicati<strong>on</strong>s and infrastructure <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Formore in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about Windows interoperability with <strong>UNIX</strong>, refer <strong>to</strong>http://www.microsoft.com/sfu.For a detailed comparis<strong>on</strong> of the system abilities of existing <strong>UNIX</strong> systems andWindows <strong>Server</strong> 2003 and <strong>SQL</strong> <strong>Server</strong> 2000, refer <strong>to</strong>http://go.microsoft.com/fwlink/?linkid=37907Create the Problem StatementA problem statement is usually a short narrative describing the specific issues that thebusiness hopes <strong>to</strong> address with the project. It relates primarily <strong>to</strong> the current state ofbusiness activities and is a direct result of the business goals or design goals not beingmet adequately. The more precisely the problem statement is recorded, the easier it willbe <strong>to</strong> measure the success of the project.Because the aim of the project is <strong>to</strong> solve a problem, the understanding of the problemdetermines the design of the soluti<strong>on</strong>. A good problem statement provides sufficientin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the business problem <str<strong>on</strong>g>for</str<strong>on</strong>g> a new team member <strong>to</strong> use the problemstatement and the rest of the documentati<strong>on</strong> <strong>to</strong> put the project in<strong>to</strong> c<strong>on</strong>text.The following are some examples of problem statements that may be relevant in an<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows migrati<strong>on</strong> project:● Cus<strong>to</strong>mer support cannot effectively process the high number of cus<strong>to</strong>mer callsbecause of the time it takes <str<strong>on</strong>g>for</str<strong>on</strong>g> them <strong>to</strong> retrieve cus<strong>to</strong>mer data from the existingcus<strong>to</strong>mer database.● Product managers cannot make in<str<strong>on</strong>g>for</str<strong>on</strong>g>med decisi<strong>on</strong>s about sales promoti<strong>on</strong>sbecause they do not have recent sales trends.Create the Visi<strong>on</strong> StatementThe visi<strong>on</strong> statement addresses the problem statement and establishes a comm<strong>on</strong> visi<strong>on</strong>of the end state that can be shared am<strong>on</strong>g team members. While brief, this statementprovides a comm<strong>on</strong> starting point <str<strong>on</strong>g>for</str<strong>on</strong>g> future decisi<strong>on</strong>s throughout the rest of the project.A good visi<strong>on</strong> statement has the following characteristics:● Specific. A visi<strong>on</strong> statement should be specific and include the ideal state of thebusiness problem soluti<strong>on</strong> so that the end result is meaningful.● Measurable. By creating a visi<strong>on</strong> statement that is measurable, the project teamcan determine the degree of success at the completi<strong>on</strong> of the project.● Achievable. Given the resources, the time frame, and the skills of the teammembers, the visi<strong>on</strong> statement should be achievable. An achievable andchallenging visi<strong>on</strong> statement can motivate team members.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 19●●Relevant. The visi<strong>on</strong> statement should relate <strong>to</strong> the business problem beingaddressed. If not, the project team might realize that they are solving the wr<strong>on</strong>gproblem, or <strong>on</strong>e that does not exist, and — in the process — lose sp<strong>on</strong>sorship.Time-based. The visi<strong>on</strong> statement should clearly indicate the estimated time frame<str<strong>on</strong>g>for</str<strong>on</strong>g> the delivery of the soluti<strong>on</strong>.The following two examples are visi<strong>on</strong> statements <str<strong>on</strong>g>for</str<strong>on</strong>g> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong><strong>on</strong> Windows migrati<strong>on</strong> project:● Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the end of the year, our cus<strong>to</strong>mer support staff will be able <strong>to</strong> retrieve allcus<strong>to</strong>mer data and account his<strong>to</strong>ry within three sec<strong>on</strong>ds of the cus<strong>to</strong>mer identifyinghimself or herself.● Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the start of the next fiscal year, our product managers will have access <strong>to</strong>daily sales reports from all the showrooms in the country.Define the User ProfilesUnderstanding the users <str<strong>on</strong>g>for</str<strong>on</strong>g> whom the soluti<strong>on</strong> is being developed is critical <strong>to</strong> theproject's success. To capture a clear descripti<strong>on</strong> of each user, the team creates profilesof each user class. The process of profiling develops a set of user requirements. Thecombinati<strong>on</strong> of these user requirements with the business and design requirements willhelp <strong>to</strong> define the project scope later in the Envisi<strong>on</strong>ing Phase.In an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows migrati<strong>on</strong> project, the most importantprofiles are that of the system managers and users of the migrated applicati<strong>on</strong>. C<strong>on</strong>siderthe following while profiling the user types:● Proficiency of the users in using Microsoft applicati<strong>on</strong>s and the Windowsenvir<strong>on</strong>ment. Administra<strong>to</strong>rs largely use command line <strong>to</strong>ols in the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>/<strong>UNIX</strong>world. While Windows also provides some command line interfaces, Windows<strong>to</strong>ols tend <strong>to</strong> be graphical user interfaces (GUIs). Users new <strong>to</strong> the Windowsenvir<strong>on</strong>ment may need training.● The type of tasks that the users will per<str<strong>on</strong>g>for</str<strong>on</strong>g>m <strong>on</strong> the new system.● Essential expectati<strong>on</strong>s of the end user from the current applicati<strong>on</strong> interface thatwill have <strong>to</strong> be met in the new envir<strong>on</strong>ment.● The language localizati<strong>on</strong> needs <str<strong>on</strong>g>for</str<strong>on</strong>g> the end users, if necessary. C<strong>on</strong>sider the GUIas well as user documentati<strong>on</strong>.● The physical locati<strong>on</strong> of the end users. Fac<strong>to</strong>rs such as locati<strong>on</strong>s, number of usersat each locati<strong>on</strong>, and the bandwidth and usage of network links between the sitesshould be unders<strong>to</strong>od and documented.Assess the Current Situati<strong>on</strong> (High Level)Organizati<strong>on</strong>s planning an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows migrati<strong>on</strong> need <strong>to</strong>c<strong>on</strong>sider the following five entities <str<strong>on</strong>g>for</str<strong>on</strong>g> a successful migrati<strong>on</strong>. While these entities areassessed in detail in the Planning Phase of the project, a high level preliminaryassessment is essential in the Envisi<strong>on</strong>ing Phase <strong>to</strong> evaluate the feasibility of the project.● Applicati<strong>on</strong>This entity includes the target applicati<strong>on</strong>s that are migrati<strong>on</strong> candidates. Whileassessing applicati<strong>on</strong>s, the following questi<strong>on</strong>s should be asked:● Which are the specific applicati<strong>on</strong>s that are <strong>to</strong> be migrated?● What languages are these applicati<strong>on</strong>s written in?


20Envisi<strong>on</strong>ing Phase●●●If there are cus<strong>to</strong>m applicati<strong>on</strong>s <strong>to</strong> be migrated, is the source code available?Are the developers of the applicati<strong>on</strong> still a part of the team?Do the applicati<strong>on</strong>s <strong>to</strong> be migrated interoperate with other applicati<strong>on</strong>s orsystems?●●●●DatabaseThis entity includes the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases that need <strong>to</strong> be migrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.The following are some of the high level questi<strong>on</strong>s you need <strong>to</strong> ask:●●●●Do your existing databases implement specialized features of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or anyother third-party cus<strong>to</strong>mizati<strong>on</strong>s <strong>to</strong> provide additi<strong>on</strong>al database features?Are the databases that need <strong>to</strong> be migrated shared by multiple applicati<strong>on</strong>s?What are the sizes of the databases being migrated?What is the user populati<strong>on</strong> of the databases?Applicati<strong>on</strong> infrastructureThis entity includes server and network-related resources, such as compute nodes,s<strong>to</strong>rage, file systems, routers, firewalls, hubs, and so <strong>on</strong>. The following are some ofthe questi<strong>on</strong>s you need <strong>to</strong> ask <strong>to</strong> assess the current state:● Do you already have an existing infrastructure based <strong>on</strong> Windows that can bereadily used or expanded, or do you have <strong>to</strong> set up the infrastructure fromscratch?● What are the other external systems, such as those of your partners or clients,that would be impacted by the migrati<strong>on</strong>?Microsoft provides a standardized infrastructure architecture named Windows<strong>Server</strong> System Reference Architecture (WSSRA). WSSRA provides lab and realworld tested, architectural blueprints and proven best practices <strong>to</strong> design andimplement enterprise infrastructure soluti<strong>on</strong>s with minimal risk and cost. Theguidance addresses infrastructure issues including availability, security, scalability,and manageability of the plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m in a fully integrated fashi<strong>on</strong>. For detailedin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> WSSRA, refer <strong>to</strong>http://www.microsoft.com/windowsserversystem/overview/referencearchitecture.mspx.Development envir<strong>on</strong>mentThis entity includes software c<strong>on</strong>structi<strong>on</strong> envir<strong>on</strong>ments such as the <strong>UNIX</strong> makeenvir<strong>on</strong>ment, developer <strong>to</strong>ols, and so <strong>on</strong>. Migrati<strong>on</strong> of the database and data canbe achieved by using <strong>to</strong>ols bundled with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, such as<strong>SQL</strong>*Plus, Enterprise Manager, and Query Analyzer. Microsoft offers a set of <strong>to</strong>olscalled <strong>SQL</strong> <strong>Server</strong> Migrati<strong>on</strong> Assistant <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases <strong>to</strong><strong>SQL</strong> <strong>Server</strong>.Questi<strong>on</strong>s <strong>to</strong> ask while assessing the development envir<strong>on</strong>ment include:● What is the software c<strong>on</strong>structi<strong>on</strong> envir<strong>on</strong>ment that you have <strong>to</strong> build the <strong>UNIX</strong>applicati<strong>on</strong>s? A comm<strong>on</strong>ly used software c<strong>on</strong>structi<strong>on</strong> mechanism is the use ofmakefiles. For detailed process and technical guidance <strong>on</strong> using a makebasedbuild envir<strong>on</strong>ment <strong>to</strong> build Windows executables, refer <strong>to</strong>http://go.microsoft.com/fwlink/?LinkId=22225● Are the required licenses <str<strong>on</strong>g>for</str<strong>on</strong>g> the appropriate <strong>SQL</strong> <strong>Server</strong> editi<strong>on</strong> available?● What are the server, s<strong>to</strong>rage, and network resources <strong>to</strong> support thedevelopment and testing activities?Existing documentati<strong>on</strong>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 21This entity includes end user documentati<strong>on</strong>, requirements analysis, functi<strong>on</strong>alspecificati<strong>on</strong>s, design documents, and so <strong>on</strong>. The existing documentati<strong>on</strong> shouldbe scrutinized as part of the task of assessing your current envir<strong>on</strong>ment. This issomething that is often overlooked. Existing design documentati<strong>on</strong> is a valuableresource <str<strong>on</strong>g>for</str<strong>on</strong>g> building project documents and plans, especially when a large porti<strong>on</strong>of the existing functi<strong>on</strong>ality is carried over <strong>to</strong> the new soluti<strong>on</strong>. Developing testplans and test cases <str<strong>on</strong>g>for</str<strong>on</strong>g> the new applicati<strong>on</strong> based up<strong>on</strong> existing documentati<strong>on</strong> isespecially useful. Modificati<strong>on</strong>s <strong>to</strong> existing documentati<strong>on</strong> are almost certainlyneeded <strong>to</strong> support the migrated soluti<strong>on</strong>. One problem often encountered is thatthe existing documentati<strong>on</strong> is incorrect or insufficient, which may <str<strong>on</strong>g>for</str<strong>on</strong>g>ce themigrati<strong>on</strong> project <strong>to</strong> absorb the ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t of bringing it up <strong>to</strong> date.These are some of the questi<strong>on</strong>s that you need <strong>to</strong> ask:● Are the original requirements <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the applicati<strong>on</strong>s <strong>to</strong> be migratedavailable?● Are database and applicati<strong>on</strong> design (high level as well as detailed) documentsavailable?● Are the logical and physical data models available <str<strong>on</strong>g>for</str<strong>on</strong>g> all databases <strong>to</strong> bemigrated?● Is documentati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong> code maintained?● Are user manuals available <str<strong>on</strong>g>for</str<strong>on</strong>g> client applicati<strong>on</strong>s?● Are training documents available <str<strong>on</strong>g>for</str<strong>on</strong>g> support, end users, and operati<strong>on</strong>spers<strong>on</strong>nel?●Applicati<strong>on</strong> usersUser accounts that exist in the <strong>UNIX</strong> domain need <strong>to</strong> be migrated or recreated inthe Windows-based domain al<strong>on</strong>g with the necessary permissi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> users <strong>to</strong> startusing the applicati<strong>on</strong> <strong>on</strong> the Windows domain. Ask the following questi<strong>on</strong>s:● What security services are in use (examples include local, Kerberos, NIS,NIS+, and LDAP)?● What is the authenticati<strong>on</strong> method in use (examples include password, digitalcertificate, and so <strong>on</strong>)?● What authority does the user have <strong>on</strong> the system?● How is authorizati<strong>on</strong> implemented?● What activities of the users are audited?● Are users required <strong>to</strong> use secure communicati<strong>on</strong> methods such as SSH?● Are applicati<strong>on</strong> users authenticated by the operating system as well as by thedatabase?For prescriptive guidance <strong>on</strong> how <strong>to</strong> enable Windows <strong>Server</strong> 2003 <strong>to</strong> be used <str<strong>on</strong>g>for</str<strong>on</strong>g>authenticati<strong>on</strong> and as an identity s<strong>to</strong>re within Windows and <strong>UNIX</strong> envir<strong>on</strong>ments,refer <strong>to</strong> http://go.microsoft.com/fwlink/?LinkId=23120.Note The primary purpose of this soluti<strong>on</strong> is <strong>to</strong> provide guidance <strong>on</strong> migrating theapplicati<strong>on</strong>s and databases from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> envir<strong>on</strong>ment <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows envir<strong>on</strong>ment. The discussi<strong>on</strong>s about migrating the infrastructure, developmentenvir<strong>on</strong>ment, user accounts, and documentati<strong>on</strong> are, there<str<strong>on</strong>g>for</str<strong>on</strong>g>e, limited in this soluti<strong>on</strong>.The discussi<strong>on</strong>s have been included <strong>to</strong> provide readers a holistic perspective of themigrati<strong>on</strong>. Pointers <strong>to</strong> other resources that provide more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, includingprescriptive guidance, are provided when relevant.


22Envisi<strong>on</strong>ing PhaseFigure 2.1 represents the primary entities involved in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong><strong>on</strong> Windows migrati<strong>on</strong>. To reiterate: this guide provides prescriptive guidance <str<strong>on</strong>g>for</str<strong>on</strong>g>migrating the applicati<strong>on</strong>, database, and applicati<strong>on</strong> infrastructure entities <strong>on</strong>ly.In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the other entities is available from the sources cited earlier.Figure 2.1Primary Migrati<strong>on</strong> EntitiesCapture High Level RequirementsAn important task in the Envisi<strong>on</strong>ing Phase is <strong>to</strong> document the high-level business, user,and design requirements. These requirements are refined further in the c<strong>on</strong>ceptualdesign stage of the Planning Phase (discussed in Chapter 3, "Planning Phase").A comm<strong>on</strong> way of gathering and analyzing in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is through developing use-casesand building usage scenarios <strong>to</strong> document the business processes and userrequirements. While use cases describe the high level interacti<strong>on</strong>s between an individualand the system, usage scenarios provide additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the activities andtask sequences that c<strong>on</strong>stitute a process.A detailed discussi<strong>on</strong> of use-case analysis is out of scope of this soluti<strong>on</strong>. Please refer <strong>to</strong>the following resource <str<strong>on</strong>g>for</str<strong>on</strong>g> additi<strong>on</strong>al guidance: Advanced Use Case Modeling (Armourand Miller, 2000).Define the Project ScopeOne of the critical fac<strong>to</strong>rs in the success of a project is clearly defining the scope of theproject. Scope defines what will be and what will not be included in the project. Thescope uses the high level requirements gathered earlier in the Envisi<strong>on</strong>ing Phase andincorporates the c<strong>on</strong>straints imposed <strong>on</strong> the project by resources, schedule, budget, andother limiting fac<strong>to</strong>rs. A good way of scoping is <strong>to</strong> address use cases and usagescenarios that impact the business the most.As with the business and design goals, the scope <str<strong>on</strong>g>for</str<strong>on</strong>g> projects is organizati<strong>on</strong>-specific,and you will need <strong>to</strong> determine the scope <str<strong>on</strong>g>for</str<strong>on</strong>g> your project and document it in the


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 23visi<strong>on</strong>/scope document. However, when producing the scope <str<strong>on</strong>g>for</str<strong>on</strong>g> your <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong><strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows migrati<strong>on</strong> project, some general guidelines should be followed:●●●●●●●C<strong>on</strong>sider a multiphase approach <strong>to</strong> the migrati<strong>on</strong>. In the first phase, c<strong>on</strong>sidermigrating <strong>on</strong>ly the database and rec<strong>on</strong>nect the <strong>UNIX</strong> applicati<strong>on</strong>s <strong>to</strong> c<strong>on</strong>nect <strong>to</strong><strong>SQL</strong> <strong>Server</strong>. Limiting the scope <str<strong>on</strong>g>for</str<strong>on</strong>g> each phase of the migrati<strong>on</strong> increases yourability <strong>to</strong> m<strong>on</strong>i<strong>to</strong>r and measure the migrati<strong>on</strong> project's success.C<strong>on</strong>sider migrating the portable applicati<strong>on</strong>s first. These include applicati<strong>on</strong>swritten using Java, Perl, PHP, and Pyth<strong>on</strong>. Portable applicati<strong>on</strong>s can usually beported or c<strong>on</strong>figured <strong>to</strong> interoperate with relative ease, and this helps build userand management c<strong>on</strong>fidence.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms and Pro*C applicati<strong>on</strong>s are the hardest <strong>to</strong> migrate because theyhave <strong>to</strong> be rewritten; per<str<strong>on</strong>g>for</str<strong>on</strong>g>m them in a later phase, if possible.The migrati<strong>on</strong> of code present in the database in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m of triggers, functi<strong>on</strong>s,s<strong>to</strong>red procedures, and packages impacts the migrati<strong>on</strong> of applicati<strong>on</strong>s that aredependent <strong>on</strong> them. As a result, these have <strong>to</strong> be migrated first.Databases using advanced <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> functi<strong>on</strong>ality, such as advanced queuing, Javapackages, objects, and so <strong>on</strong> are more difficult <strong>to</strong> migrate, and a proof-of-c<strong>on</strong>ceptshould be created <strong>to</strong> verify the soluti<strong>on</strong>.Smaller databases with less stringent requirements <strong>on</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and availabilityshould be migrated be<str<strong>on</strong>g>for</str<strong>on</strong>g>e attempting larger <strong>on</strong>es.To reduce the complexity, migrati<strong>on</strong> at the schema level should be c<strong>on</strong>sideredwhere feasible instead of entire databases.Define the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> C<strong>on</strong>ceptThe soluti<strong>on</strong> c<strong>on</strong>cept outlines the high level approach the team will take <strong>to</strong> meet the goalsof the project and provides the basis <str<strong>on</strong>g>for</str<strong>on</strong>g> proceeding <strong>to</strong> the Planning Phase. Thisapproach includes the assessment of technologies, development, test, quality assurance,training, deployment, release, operati<strong>on</strong>s and so <strong>on</strong>. These approaches can bedeveloped in<strong>to</strong> full-fledged plans in the Planning Phase. Because the soluti<strong>on</strong> c<strong>on</strong>ceptfocuses <strong>on</strong> the c<strong>on</strong>cepts and not the details, it is not very technical.The soluti<strong>on</strong> c<strong>on</strong>cept also includes a high-level soluti<strong>on</strong> design strategy <str<strong>on</strong>g>for</str<strong>on</strong>g> all thesoftware and hardware comp<strong>on</strong>ents of the system. Because the primary focus of thissoluti<strong>on</strong> is migrating the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases and associated applicati<strong>on</strong>s <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows, the rest of this secti<strong>on</strong> discusses <strong>on</strong>ly soluti<strong>on</strong> design strategies <str<strong>on</strong>g>for</str<strong>on</strong>g> thedatabase and applicati<strong>on</strong>s.Applicati<strong>on</strong> and Database Migrati<strong>on</strong> <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> DesignStrategyFor the purposes of explanati<strong>on</strong>, the applicati<strong>on</strong> and database ecosystem can be viewedin terms of three comp<strong>on</strong>ents:● Applicati<strong>on</strong>. This comp<strong>on</strong>ent includes applicati<strong>on</strong>s written in a variety ofprogramming languages, including <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms, Perl, Pyth<strong>on</strong>, and so <strong>on</strong>.● C<strong>on</strong>nectivity interface. This is the intermediate tier between the applicati<strong>on</strong> and thedatabase. The c<strong>on</strong>nectivity tier is also referred <strong>to</strong> as the applicati<strong>on</strong> programminginterface (API). This layer facilitates the communicati<strong>on</strong> between the applicati<strong>on</strong>and the database. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> support different c<strong>on</strong>nectivity interfaces,some proprietary and some standard. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Call Interface (OCI) is an example ofa proprietary interface <str<strong>on</strong>g>for</str<strong>on</strong>g> an applicati<strong>on</strong> <strong>to</strong> communicate with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Object


24Envisi<strong>on</strong>ing Phase●Database C<strong>on</strong>nectivity (ODBC) is an example of a standards-based interface. Theavailable API also differs from <strong>UNIX</strong> <strong>to</strong> Windows.Database. The database tier c<strong>on</strong>sists of the database management system andthe objects that s<strong>to</strong>re and facilitate access <strong>to</strong> the data in the database.The relati<strong>on</strong>ship between these three comp<strong>on</strong>ents is shown in Figure 2.2. Thec<strong>on</strong>nectivity interface binds the applicati<strong>on</strong> <strong>to</strong> the database and allows in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>to</strong>pass between them.Figure 2.2Applicati<strong>on</strong>, database, and c<strong>on</strong>nectivity tiersOnce the database is migrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, there are four differentapproaches <strong>to</strong> c<strong>on</strong>nect the applicati<strong>on</strong> <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database using an appropriatec<strong>on</strong>nectivity layer.1. Interoperati<strong>on</strong>The applicati<strong>on</strong> comp<strong>on</strong>ents remain <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.2. Port or rewrite applicati<strong>on</strong> <strong>to</strong> the .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mThe.NET framework is the next generati<strong>on</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m from Microsoft <str<strong>on</strong>g>for</str<strong>on</strong>g> building,deploying, and running Windows applicati<strong>on</strong>s. It provides a standards-based, multilanguageenvir<strong>on</strong>ment <str<strong>on</strong>g>for</str<strong>on</strong>g> integrating existing investments with next-generati<strong>on</strong>applicati<strong>on</strong>s and services.3. Port or rewrite applicati<strong>on</strong> <strong>to</strong> Win32 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mThe Win32 API is <strong>on</strong>e of the primary programming interfaces <strong>to</strong> the Windowsoperating system family, including Windows 2003. The Win32 API providesfuncti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> processes, memory management, security, windowing, and graphics.4. Quick port: port applicati<strong>on</strong> <strong>to</strong> the Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mPort applicati<strong>on</strong>s <strong>to</strong> an envir<strong>on</strong>ment <strong>on</strong> Windows named Interix, which is similar <strong>to</strong><strong>UNIX</strong>. Interix is a complete, POSIX-compliant development envir<strong>on</strong>ment that istightly integrated with the Windows kernel. It is a part of the MicrosoftWindows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 product suite from Microsoft.Each of these four opti<strong>on</strong>s c<strong>on</strong>stitutes a separate design strategy <str<strong>on</strong>g>for</str<strong>on</strong>g> your migrati<strong>on</strong>project, and each of the four is discussed in more detail under the following headings.One, some, or all of these soluti<strong>on</strong> design strategies will <str<strong>on</strong>g>for</str<strong>on</strong>g>m the basis of the soluti<strong>on</strong>c<strong>on</strong>cept you will produce as a part of completing the Envisi<strong>on</strong>ing Phase. Even when thegoal is <strong>to</strong> standardize <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, some of these strategies may beemployed as intermediary steps in a multi-phased migrati<strong>on</strong>. This soluti<strong>on</strong> c<strong>on</strong>cept —documented in the visi<strong>on</strong>/scope document — will be used <strong>to</strong> develop detailed plansduring the Planning Phase and code during the Developing Phase.Note Due <strong>to</strong> the complexities inherent in a migrati<strong>on</strong> project, it may not be possible <strong>to</strong>immediately select a migrati<strong>on</strong> strategy. Proof-of-c<strong>on</strong>cept testing may need <strong>to</strong> occurbe<str<strong>on</strong>g>for</str<strong>on</strong>g>e the design strategy is decided up<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 25<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> Design Strategy A: InteroperabilityIn this strategy, the applicati<strong>on</strong>s remain <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m while the database al<strong>on</strong>e ismigrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.Interoperati<strong>on</strong> is preferred in the following situati<strong>on</strong>s:●●●●The migrati<strong>on</strong> ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t and risks need <strong>to</strong> be minimized at the expense of not beingable <strong>to</strong> fully realize the benefits of migrating the applicati<strong>on</strong> <strong>to</strong> Windows.A multiphased approach <str<strong>on</strong>g>for</str<strong>on</strong>g> migrati<strong>on</strong> is more appropriate. The first phase ofmigrati<strong>on</strong> could involve migrating the database <strong>on</strong>ly, and later phases could focus<strong>on</strong> migrating the applicati<strong>on</strong>s.The needs served by the applicati<strong>on</strong> are static; the evoluti<strong>on</strong> of the applicati<strong>on</strong> isnot a business or design goal of the project.Maintaining a tight or complex integrati<strong>on</strong> of <strong>UNIX</strong> applicati<strong>on</strong>s with other servicesis required.Interoperati<strong>on</strong> is not recommended in the following situati<strong>on</strong>s:●●●●●The cost of maintaining two envir<strong>on</strong>ments is prohibitive.The goals of the project include changing the applicati<strong>on</strong> <strong>to</strong> take advantage of thegreater business value of Windows technologies.Comp<strong>on</strong>ents being <strong>on</strong> two different plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms do not produce acceptableper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance or service levels.The required measure of security cannot be achieved because of disparatetechnologies.When the interoperati<strong>on</strong> is complex and requires huge ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t in development andimplementati<strong>on</strong> as compared <strong>to</strong> employing <strong>on</strong>e of the other methods.<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> Design Strategy B: Port or Rewrite <strong>to</strong> .NET FrameworkWhen migrating an applicati<strong>on</strong> <strong>to</strong> the .NET framework, there are two different opti<strong>on</strong>s.One is <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m a full port of the applicati<strong>on</strong>, and the other is <strong>to</strong> rewrite the applicati<strong>on</strong>using the .NET applicati<strong>on</strong> programming interfaces (APIs).A full port is defined as the capability <strong>to</strong> execute the applicati<strong>on</strong> in the Windowsenvir<strong>on</strong>ment in its native <str<strong>on</strong>g>for</str<strong>on</strong>g>m. Applicati<strong>on</strong>s written using languages such as Java, Perl,PHP, and Pyth<strong>on</strong>, which are available <strong>on</strong> both the <strong>UNIX</strong> and Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms, cantake advantage of a full port. In most cases, <strong>SQL</strong> <strong>Server</strong> database drivers are available<str<strong>on</strong>g>for</str<strong>on</strong>g> the specific applicati<strong>on</strong> languages. A full port requires minimum changes <strong>to</strong> be d<strong>on</strong>e <strong>to</strong>the source code, and a full port uses standard libraries and utilities that exist <strong>on</strong> theWindows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. New documentati<strong>on</strong> and user training is not required in the case of afull port because the business logic and the user interface remain the same.A full port <strong>to</strong> the .NET framework is preferred in the following situati<strong>on</strong>s:● The programming envir<strong>on</strong>ment in which the applicati<strong>on</strong> was written is fullysupported in the .NET framework.● Appropriate .NET database drivers are available and support all the functi<strong>on</strong> callsmade in the applicati<strong>on</strong> code.● Rewriting an applicati<strong>on</strong> c<strong>on</strong>sumes <strong>to</strong>o much time and increases cost prohibitively.● When ported in<strong>to</strong> the .NET framework, the applicati<strong>on</strong> successfully interacts withother applicati<strong>on</strong>s.A rewrite of the applicati<strong>on</strong> would be required when there are no equivalents <strong>on</strong> the .NETplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m <str<strong>on</strong>g>for</str<strong>on</strong>g> the language in use. An example of this would be applicati<strong>on</strong>s based <strong>on</strong>


26Envisi<strong>on</strong>ing Phase<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms. The best opti<strong>on</strong> in this case would be <strong>to</strong> rewrite the applicati<strong>on</strong> <strong>on</strong>Windows using Visual Basic .NET.A rewrite of the applicati<strong>on</strong> is preferred in the following situati<strong>on</strong>s:● The cost and complexity of porting is prohibitively high. It may be easier <strong>to</strong> recreatethe applicati<strong>on</strong> rapidly using Visual Basic.NET, rather than porting the applicati<strong>on</strong>.● The business logic is likely <strong>to</strong> change significantly in the new envir<strong>on</strong>ment, whichwould limit the amount of code reused from the source plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.● The applicati<strong>on</strong> requires new features and code that is specific <strong>to</strong> the Windowsenvir<strong>on</strong>ment.● Tight integrati<strong>on</strong> with Windows features is required in the new applicati<strong>on</strong>.● The best possible integrati<strong>on</strong> with other Windows-based applicati<strong>on</strong>s is required.● A port is not possible either because the language is not supported or API libraries<str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> do not exist.Potentially, rewriting an applicati<strong>on</strong> can be challenging. It can be a time-c<strong>on</strong>suming, risky,and costly opti<strong>on</strong>. The risk inherent in a rewrite is that the business logic or an importantfuncti<strong>on</strong>ality is changed while rewriting the code. Careful testing and stabilizing of therewritten applicati<strong>on</strong> needs <strong>to</strong> be c<strong>on</strong>ducted <strong>to</strong> ensure proper business logic andfuncti<strong>on</strong>ality.When porting or rewriting <strong>to</strong> Windows, migrati<strong>on</strong> <strong>to</strong> the .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m is preferred. .NETtechnology provides the ability <strong>to</strong> build, deploy, manage, and use c<strong>on</strong>nected, securityenhancedsoluti<strong>on</strong>s with Web services. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mand its key capabilities, refer <strong>to</strong> the following two resources:http://www.microsoft.com/net/basics/http://msdn.microsoft.com/netframework/programming/fundamentals/default.aspxThere are situati<strong>on</strong>s when moving <strong>to</strong> .NET may not be feasible. For instance, at the timethat this guide was published no producti<strong>on</strong>-ready implementati<strong>on</strong>s of Pyth<strong>on</strong> <strong>on</strong> the.NET framework existed. However, this technology is currently available in a beta <str<strong>on</strong>g>for</str<strong>on</strong>g>mat,and investigati<strong>on</strong> of current technologies is recommended.<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> Design Strategy C: Port or Rewrite <strong>to</strong> Win32The.NET Framework offers the next generati<strong>on</strong> of applicati<strong>on</strong>s and services. Migrati<strong>on</strong> <strong>to</strong>the Win32 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m should be c<strong>on</strong>sidered when migrati<strong>on</strong> <strong>to</strong> .NET is not technicallyfeasible <str<strong>on</strong>g>for</str<strong>on</strong>g> your organizati<strong>on</strong>. As with strategy B, two migrati<strong>on</strong> opti<strong>on</strong>s are availablewhen moving <strong>to</strong> a Win32-based plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. The first is <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m a full port of theapplicati<strong>on</strong>, and the other is <strong>to</strong> rewrite the applicati<strong>on</strong> using the Win32 APIs. The rati<strong>on</strong>ale<str<strong>on</strong>g>for</str<strong>on</strong>g> deciding whether <strong>to</strong> port or rewrite the applicati<strong>on</strong> <strong>to</strong> functi<strong>on</strong> with Win32 is the sameas the rati<strong>on</strong>ale <str<strong>on</strong>g>for</str<strong>on</strong>g> using .NET. Please refer <strong>to</strong> the descripti<strong>on</strong> in the "<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> DesignStrategy B: Port or Rewrite <strong>to</strong> .NET Framework" secti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> more details.<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> Design Strategy D: Quick Port by <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <strong>to</strong>Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>One of the quickest migrati<strong>on</strong> paths possible is <strong>to</strong> port the code directly <strong>to</strong>Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>. Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> includes Microsoft Interix, whichprovides a <strong>UNIX</strong> envir<strong>on</strong>ment that runs <strong>on</strong> <strong>to</strong>p of the Windows kernel. Interix allowsnative <strong>UNIX</strong> applicati<strong>on</strong>s and scripts <strong>to</strong> work al<strong>on</strong>gside Windows applicati<strong>on</strong>s. The bestway <strong>to</strong> view Interix is <strong>to</strong> understand it as a POSIX-compliant versi<strong>on</strong> of <strong>UNIX</strong> built <strong>on</strong> <strong>to</strong>pof the Windows kernel. It is not an emulati<strong>on</strong> of a <strong>UNIX</strong> envir<strong>on</strong>ment <strong>on</strong> the WindowsAPIs. Migrati<strong>on</strong> using Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> involves obtaining the source code,


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 27installing it in the Interix development envir<strong>on</strong>ment, modifying the c<strong>on</strong>figurati<strong>on</strong> scriptsand makefiles, and recompiling the applicati<strong>on</strong>. This strategy is referred <strong>to</strong> as a quickport.The ported applicati<strong>on</strong> may be successful immediately, or it may require modificati<strong>on</strong>s <strong>to</strong>the c<strong>on</strong>figurati<strong>on</strong> scripts or makefiles <strong>to</strong> account <str<strong>on</strong>g>for</str<strong>on</strong>g> the new hardware plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, the targe<strong>to</strong>perating systems, and local c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. A detailed assessment of theapplicati<strong>on</strong> has <strong>to</strong> be c<strong>on</strong>ducted <strong>to</strong> inven<strong>to</strong>ry the various APIs and utilities in use. Thesupport <str<strong>on</strong>g>for</str<strong>on</strong>g> these in the Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> envir<strong>on</strong>ment has <strong>to</strong> be verified.Extensive testing of the applicati<strong>on</strong> is essential after the port <strong>to</strong> ensure that all featureshave been migrated successfully.A quick port is preferred in the following situati<strong>on</strong>s:● A port <str<strong>on</strong>g>for</str<strong>on</strong>g> the language the applicati<strong>on</strong> was written in does not exist in .NET orWin32. An example applicati<strong>on</strong> is X Windows.● Applicati<strong>on</strong> investments <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m need <strong>to</strong> be reused. Interix canoptimize your investments in <strong>UNIX</strong> applicati<strong>on</strong>s by reusing code. New functi<strong>on</strong>alityand value can be added <strong>to</strong> your existing <strong>UNIX</strong> applicati<strong>on</strong>s by integrating the <strong>UNIX</strong>code with .NET or Win32 functi<strong>on</strong>ality.● It is <strong>to</strong>o expensive and time-c<strong>on</strong>suming <strong>to</strong> do a full port or complete rewrite of theapplicati<strong>on</strong>.● A large set of <strong>UNIX</strong> scripts need <strong>to</strong> be ported. Interix allows you <strong>to</strong> get the most ou<strong>to</strong>f existing <strong>UNIX</strong> network administra<strong>to</strong>r <strong>to</strong>ols and skill sets. It provides more than300 <strong>UNIX</strong> utilities, and it provides shells and scripting languages (including Perl)that enable you <strong>to</strong> run existing shell scripts with little or no change <strong>on</strong> Windows.A quick port is not recommended in the following situati<strong>on</strong>s:● A port of the applicati<strong>on</strong> is available in Win32 or .NET.● You can af<str<strong>on</strong>g>for</str<strong>on</strong>g>d the rewrite or port <strong>to</strong> Win32 or .NET and wants <strong>to</strong> tightly integratethe applicati<strong>on</strong> with other Windows technologies.● You want <strong>to</strong> significantly evolve the applicati<strong>on</strong> by using the capabilities of theWindows envir<strong>on</strong>ment.● A quick port requires huge ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t in development and implementati<strong>on</strong> as compared<strong>to</strong> employing <strong>on</strong>e of the other methods. For example, when the required librariesavailable <strong>on</strong> the original <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m are not available <strong>on</strong> Interix.Most <strong>UNIX</strong> database envir<strong>on</strong>ments use scripts <strong>to</strong> support databases and clientapplicati<strong>on</strong>s. You should evaluate the importance of the services that these scriptsper<str<strong>on</strong>g>for</str<strong>on</strong>g>m. <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the scripts <strong>to</strong> Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> is an opti<strong>on</strong>; however,scripts that make use of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> utility programs must be modified <strong>to</strong> use suitablereplacements <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>.Using Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>, organizati<strong>on</strong>s can rapidly c<strong>on</strong>solidate diverseplat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms, maximizing their previous investments in <strong>UNIX</strong> infrastructure, applicati<strong>on</strong>s, andknowledge while capitalizing <strong>on</strong> Windows innovati<strong>on</strong>. Moreover,Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> provides a full range of supported and fully integrated, crossplat<str<strong>on</strong>g>for</str<strong>on</strong>g>mnetwork services <str<strong>on</strong>g>for</str<strong>on</strong>g> blending Windows and <strong>UNIX</strong> networks.For a detailed discussi<strong>on</strong> of Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> in migrati<strong>on</strong> projects, refer <strong>to</strong> the<strong>UNIX</strong> Applicati<strong>on</strong> Migrati<strong>on</strong> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> available athttp://go.microsoft.com/fwlink/?LinkId=30832Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 is available as a complimentary download from Microsoft<str<strong>on</strong>g>for</str<strong>on</strong>g> Windows <strong>Server</strong> 2003, Windows® XP Professi<strong>on</strong>al, and Windows® 2000.Some Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 features include:


28Envisi<strong>on</strong>ing Phase●●●It is designed <strong>to</strong> work well with other major <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms and versi<strong>on</strong>s. It hasbeen tested specifically with Sun Solaris 7 and 8, HP-UX 11i, AIX 5L 5.2, and RedHat Linux 8.0.It includes versi<strong>on</strong> 5.6 of the ActiveState Perl distributi<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> native Windowsscripting and Perl 5.6.1 <str<strong>on</strong>g>for</str<strong>on</strong>g> scripting in the Interix envir<strong>on</strong>ment.It includes more than 300 <strong>UNIX</strong> utilities and <strong>to</strong>ols that per<str<strong>on</strong>g>for</str<strong>on</strong>g>m <strong>on</strong> <strong>UNIX</strong> andWindows systems in a similar manner. In additi<strong>on</strong>, Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5also c<strong>on</strong>tains a Software Development Kit (SDK) that supports more than 1,900<strong>UNIX</strong> APIs and migrati<strong>on</strong> <strong>to</strong>ols, such as make, rcs, yacc, lex, cc, c89, nm, strip,and gbd, as well as the gcc, g++, and g77 compilers.More in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> is available from the following tworesources:http://www.microsoft.com/windows/sfu/productinfo/overview/default.asphttp://www.microsoft.com/windows/sfu/Migrati<strong>on</strong> Strategy ScenariosTables 2.2 through 2.5 show the migrati<strong>on</strong> opportunities <str<strong>on</strong>g>for</str<strong>on</strong>g> several scenarios of thesource <strong>UNIX</strong> envir<strong>on</strong>ment. Each scenario is a combinati<strong>on</strong> of the three comp<strong>on</strong>ents ofdatabase, applicati<strong>on</strong>, and c<strong>on</strong>nectivity (API). The first column of the tables representsthe current state in the <strong>UNIX</strong> envir<strong>on</strong>ment, and the third column shows the migrati<strong>on</strong>possibilities <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the migrati<strong>on</strong> strategies: interoperate, port or rewrite <strong>to</strong> the .NETFramework, port or rewrite <strong>to</strong> Win32, and port <strong>to</strong> Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>.Table 2.2: Applicati<strong>on</strong> Interoperati<strong>on</strong> Strategy<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>/<strong>UNIX</strong>languagePHPAPI<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or OCI8 orODBCInteroperate <strong>SQL</strong><strong>Server</strong>/<strong>UNIX</strong>languagePHPAPIMS <strong>SQL</strong> <strong>Server</strong> orODBCPro*C OCI <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> not availableor feasible<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Forms C or JDAPI <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> not availableor feasiblePerl <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC Perl ODBC or SybasePyth<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC Pyth<strong>on</strong> ODBCJava JDBC Java JDBC


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 29Table 2.3: Applicati<strong>on</strong> Port <strong>to</strong> Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> Strategy<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>/<strong>UNIX</strong>languagePHPAPI<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or OCI8 orODBCPort <strong>SQL</strong><strong>Server</strong>/WindowsServices <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>languagePHPPro*C OCI <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> not availableor feasible<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Forms C or JDAPI <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> not availableor feasibleAPIMS <strong>SQL</strong> <strong>Server</strong> orODBCPerl <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC Perl ODBC or SybasePyth<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC Pyth<strong>on</strong> ODBCJava JDBC Java JDBCTable 2.4: Applicati<strong>on</strong> Port or Rewrite <strong>to</strong> Win32 Strategy<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>/<strong>UNIX</strong>languagePHPAPI<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or OCI8 orODBCPort/rewrite <strong>SQL</strong><strong>Server</strong>/WIN32languagePHPAPIMS <strong>SQL</strong> <strong>Server</strong> orODBCPro*C OCI VB ODBC or ADO<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Forms C or JDAPI VB ODBC or ADOPerl <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC Perl ODBC or ADOPyth<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC Pyth<strong>on</strong> ODBCJava JDBC Java JDBCTable 2.5: Applicati<strong>on</strong> Port or Rewrite <strong>to</strong> .NET Strategy<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>/<strong>UNIX</strong>languagePHPAPI<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or OCI8 orODBCPort/rewrite <strong>SQL</strong><strong>Server</strong>/.NETlanguage<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> not availableor feasiblePro*C OCI VB.NET ODBC or ADO.NET<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Forms C or JDAPI VB.NET ODBC or ADO.NETPerl <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC Perl PerlNETPyth<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or ODBC <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> not availableor feasibleJava JDBC <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> not availableor feasibleAPI


30Envisi<strong>on</strong>ing PhaseOptimal StrategyThe fac<strong>to</strong>rs that need <strong>to</strong> be c<strong>on</strong>sidered while deciding a migrati<strong>on</strong> strategy are:●●●●Business needs. The migrati<strong>on</strong> strategy should meet the present and futureneeds of the organizati<strong>on</strong>.For example, an organizati<strong>on</strong> may need <strong>to</strong> open its existing applicati<strong>on</strong> <strong>to</strong> externalusers. Security needs <strong>to</strong> be implemented <str<strong>on</strong>g>for</str<strong>on</strong>g> the external users. The organizati<strong>on</strong>may select the rewrite strategy.Technical feasibility. <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m may not betechnically feasible. If the new features warrant a lot of change <strong>to</strong> the currentapplicati<strong>on</strong>, the organizati<strong>on</strong> may opt <strong>to</strong> select rewriting as a strategy.Time. The time frame within which the migrati<strong>on</strong> has <strong>to</strong> be planned, developed,tested, and deployed needs <strong>to</strong> be decided. In additi<strong>on</strong>, the actual time taken in themigrati<strong>on</strong> needs <strong>to</strong> be minimized <strong>to</strong> reduce the business risk.For example, an organizati<strong>on</strong> may plan <strong>to</strong> provide access <strong>to</strong> its applicati<strong>on</strong> <strong>to</strong> theexternal users within three m<strong>on</strong>ths. A quick port <strong>to</strong> the Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m may be the best opti<strong>on</strong>.Budget. The budget available needs <strong>to</strong> be planned. According <strong>to</strong> the m<strong>on</strong>eyavailable, the infrastructure, human resources, and cost need <strong>to</strong> be planned.For example, the direct cost of porting may be lower than the cost of a rewrite.Also, porting an applicati<strong>on</strong> minimizes the cost of training, as the same applicati<strong>on</strong>is used in the new envir<strong>on</strong>ment. The indirect cost; such as cost of maintenance,testing, and retraining, will also be lower.Set Up a TeamTo trans<str<strong>on</strong>g>for</str<strong>on</strong>g>m overall business and design goals in<strong>to</strong> a clear visi<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the project, anorganizati<strong>on</strong> needs <strong>to</strong> assemble a multidisciplinary team, based <strong>on</strong> MSF roles, and withdefined skill sets appropriate <strong>to</strong> the project. These roles are Product Management,Program Management, Development, Test, User Experience, and Release Management.Once assembled, this team defines the visi<strong>on</strong> and scope that <strong>to</strong>gether provide a cleardirecti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the project and set expectati<strong>on</strong>s within the organizati<strong>on</strong>. During theEnvisi<strong>on</strong>ing Phase, it is likely that <strong>on</strong>ly the lead pers<strong>on</strong> or pers<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> each team role willbe determined. During the Planning Phase, the entire team should be assembled if it isnecessary <str<strong>on</strong>g>for</str<strong>on</strong>g> your organizati<strong>on</strong> <strong>to</strong> staff each role with more than <strong>on</strong>e pers<strong>on</strong>. Morein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the MSF Team Model is available in the UMPG.Table 2.6 lists each role with its goal and identifies its key functi<strong>on</strong>al areas and projectresp<strong>on</strong>sibilities <str<strong>on</strong>g>for</str<strong>on</strong>g> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows migrati<strong>on</strong> project.Table 2.6: Project Requirements and Resp<strong>on</strong>sibilities by TaskRole Project resp<strong>on</strong>sibilities and tasks Knowledge and skillrequirementsProductManagementRole* Ensure that the team addressesbusiness goals and cus<strong>to</strong>merrequirements* Manage communicati<strong>on</strong>s, launchplanning, and feedback with cus<strong>to</strong>mers(both internal and external)Understanding of theorganizati<strong>on</strong>'s businesspriorities and goalsProgram * Drive soluti<strong>on</strong> design * Project management skills


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 31Role Project resp<strong>on</strong>sibilities and tasks Knowledge and skillrequirementsManagementRoleDevelopmentRoleDevelopmentFuncti<strong>on</strong>alTeam #1(Database)* Manage projects <strong>to</strong> meet budget andschedule* Manage scope and track progress* Provide process leadershipIt is recommended that two teams becreated <str<strong>on</strong>g>for</str<strong>on</strong>g> the Development Role. Onedevelopment team should focus <strong>on</strong>migrating the database, providingdatabase administrati<strong>on</strong> and support.The sec<strong>on</strong>d development team shouldfocus <strong>on</strong> migrating the applicati<strong>on</strong>.* Ensure that requirements of theWindows envir<strong>on</strong>ment are met <str<strong>on</strong>g>for</str<strong>on</strong>g> themigrated database (<str<strong>on</strong>g>for</str<strong>on</strong>g> example, OSsupport <str<strong>on</strong>g>for</str<strong>on</strong>g> amount of memoryrequired).* Identify and provide access <strong>to</strong> shelland other scripts that are used <strong>to</strong>support the database being migrated.* Migrate user accounts and verifiy thatthey have been migrated correctly.* Install DBMS software and databaseapplicati<strong>on</strong>s <strong>on</strong> servers.* Create database in <strong>SQL</strong> <strong>Server</strong> andmigrate data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.* Identify the time and order in whichthe shell scripts are invoked.* Design and implement the appropriatesecurity model <str<strong>on</strong>g>for</str<strong>on</strong>g> migrated databases,based <strong>on</strong> analysis of applicati<strong>on</strong> anddatabase.* Identify and resolve issues associatedwith Windows security and c<strong>on</strong>nectivity.* Validate that the chosen securityc<strong>on</strong>figurati<strong>on</strong> provides at least the samesecurity levels as the existingc<strong>on</strong>figurati<strong>on</strong>.* Apply appropriate permissi<strong>on</strong>s at thedatabase object level.* Work with test groups <strong>to</strong> build testenvir<strong>on</strong>ment.* Work with client developmentfuncti<strong>on</strong>al team <strong>on</strong> issues related <strong>to</strong>c<strong>on</strong>nectivity between database andapplicati<strong>on</strong>* Communicati<strong>on</strong> skills* Adequate knowledge of <strong>UNIX</strong>and Windows envir<strong>on</strong>mentsand of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>databases <strong>to</strong> drive soluti<strong>on</strong>design* Knowledge of securityc<strong>on</strong>figurati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> current <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database and applicati<strong>on</strong>srunning <strong>on</strong> <strong>UNIX</strong>.* Knowledge of shell and otherscripts used <strong>to</strong> support the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.* Knowledge of cr<strong>on</strong> jobs,including times and the orderin which scripts are run.* Understanding of security,c<strong>on</strong>nectivity, software, anddatabase installati<strong>on</strong> issues inthe Windows envir<strong>on</strong>ment.* Understanding of both theWindows and <strong>UNIX</strong>envir<strong>on</strong>ment.* Understanding of <strong>Net</strong>workLibrary <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong>*<strong>Net</strong>, <strong>Net</strong>8,and TCP/IP.* Understanding of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>schema, tables, views, s<strong>to</strong>redprocedures and triggers.*Knowledge of <strong>SQL</strong> <strong>Server</strong>and ability <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m all thesetasks in a Windowsenvir<strong>on</strong>ment


32Envisi<strong>on</strong>ing PhaseRole Project resp<strong>on</strong>sibilities and tasks Knowledge and skillrequirementsDevelopmentFuncti<strong>on</strong>alTeam #2(Applicati<strong>on</strong>)UserExperienceRoleTest Role* Participate in assessment activities <str<strong>on</strong>g>for</str<strong>on</strong>g>client applicati<strong>on</strong>s.* Identify and articulate securityrequirements <str<strong>on</strong>g>for</str<strong>on</strong>g> client applicati<strong>on</strong>s.* Retarget or migrate existing clientapplicati<strong>on</strong>s.* Work with test team <strong>to</strong> ensurerequirements are met and defects arereduced.* Work with database team <strong>on</strong> issuesrelated <strong>to</strong> c<strong>on</strong>nectivity or otherdatabase-related problems.* Manage process of gathering,analyzing, and prioritizing userrequirements.* Help develop usage scenarios anduse cases.* Provide feedback <strong>on</strong> the soluti<strong>on</strong>design.* Drive the creati<strong>on</strong> of user trainingmaterials.* Participate in data gathering relevant<strong>to</strong> Test during all phases of the project.* Design and develop the testenvir<strong>on</strong>ment in c<strong>on</strong>juncti<strong>on</strong> with theDevelopment functi<strong>on</strong>al teams <str<strong>on</strong>g>for</str<strong>on</strong>g>database and client migrati<strong>on</strong>s.* Maintain ownership of the testenvir<strong>on</strong>ment.* Design, create the specificati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>,and refine the test plan and the useracceptance test plan.* Implement and validate the migrati<strong>on</strong>test plan.Implement test cases.* Knowledge of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> clientapplicati<strong>on</strong>s and their securityrequirements.* Proficiency in either Perl,Pyth<strong>on</strong>, PHP, Java, VisualBasic.NET, Windows Services<str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>, or Windows.* Experience with technologies<str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong> interoperati<strong>on</strong>with <strong>SQL</strong> <strong>Server</strong> such asFreeTDS.* Understanding of s<strong>to</strong>redprocedures, database logic,and applicati<strong>on</strong> logic.* Understanding of c<strong>on</strong>nectivityissues with database.* Understanding of theapplicati<strong>on</strong>s being migrated.* Experience in developingusage scenarios and usecases.* Understanding of trainingprinciples.* Understanding of the <strong>UNIX</strong>and Windows operatingsystems (including WindowsServices <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>, ifappropriate).* Expertise with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>databases, applicati<strong>on</strong> andclient development.* Experience withinteroperati<strong>on</strong> between <strong>UNIX</strong>and Windows.* Understanding of tiereddatabase systems inhomogeneous andheterogeneous envir<strong>on</strong>ments.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 33Role Project resp<strong>on</strong>sibilities and tasks Knowledge and skillrequirementsReleaseManagement* Act as primary advocate betweenproject development and operati<strong>on</strong>sgroups.* Manage <strong>to</strong>ol selecti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> releaseactivities and drive optimizingau<strong>to</strong>mati<strong>on</strong>.* Set operati<strong>on</strong>s criteria <str<strong>on</strong>g>for</str<strong>on</strong>g> release <strong>to</strong>producti<strong>on</strong>.* Participate in design, focusing <strong>on</strong>manageability, supportability, and indeployment.* Drive training <str<strong>on</strong>g>for</str<strong>on</strong>g> operati<strong>on</strong>s.* Drive and set up <str<strong>on</strong>g>for</str<strong>on</strong>g> pilot deployments.* Plan and manage soluti<strong>on</strong> deploymentin<strong>to</strong> producti<strong>on</strong>.* Ensure that stabilizati<strong>on</strong>measurements meet acceptancecriteria.* Understanding of standardoperati<strong>on</strong>al procedures in theWindows envir<strong>on</strong>ment.* Understanding ofapplicati<strong>on</strong>s being migrated.* Management andcommunicati<strong>on</strong> skills.Special C<strong>on</strong>siderati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> Setting Up Your Migrati<strong>on</strong> TeamAn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows migrati<strong>on</strong> project can present someunique issues <str<strong>on</strong>g>for</str<strong>on</strong>g> staffing your project team. Keep the following c<strong>on</strong>siderati<strong>on</strong>s in mindwhen staffing your project team:● It is relatively easy <strong>to</strong> find technical staff with a deep knowledge of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>UNIX</strong> or <strong>SQL</strong> and Windows, but it is not easy <strong>to</strong> find technical staff that has a deepunderstanding of all of these areas. Migrati<strong>on</strong> involves creating a metaphoricalbridge between the two envir<strong>on</strong>ments. Make sure you have a senior architect <strong>on</strong>the team who understands both worlds deeply enough <strong>to</strong> engineer the bridge'screati<strong>on</strong>. If the skill is not available in-house, c<strong>on</strong>sider finding a c<strong>on</strong>sultant or ac<strong>on</strong>sulting organizati<strong>on</strong> with experience in this <str<strong>on</strong>g>for</str<strong>on</strong>g>m of migrati<strong>on</strong>. The c<strong>on</strong>sultingorganizati<strong>on</strong>s often offer services <strong>to</strong> complete these migrati<strong>on</strong> projects end-<strong>to</strong>-end.It may be possible <str<strong>on</strong>g>for</str<strong>on</strong>g> you <strong>to</strong> successfully implement the migrati<strong>on</strong> with loweredrisk and reduced cost by engaging a c<strong>on</strong>sulting organizati<strong>on</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>about Microsoft partners that offer <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> services, refer<strong>to</strong> http://www.microsoft.com/sql/partners/migrati<strong>on</strong>.asp● Ensure that the hardware and infrastructure experts from the Development Roleand Test Role are actively engaged during the Envisi<strong>on</strong>ing Phase. The hardware<strong>on</strong> which databases and applicati<strong>on</strong>s are run is comm<strong>on</strong>ly overlooked until later inthe project life cycle than it should be. Involving the experts early in the project willhelp in<str<strong>on</strong>g>for</str<strong>on</strong>g>m more accurate estimates regarding budget, time, and resources.● The Test Role should include, if possible, team members who have worked withthe applicati<strong>on</strong> being migrated. Their experience will help them write better testcases.● The User Experience Role should include, if possible, team members who haveworked with the applicati<strong>on</strong> in the <strong>UNIX</strong> envir<strong>on</strong>ment. They should have a goodunderstanding of the applicati<strong>on</strong>'s user interface so that they will be able <strong>to</strong> defineand provide the training required <str<strong>on</strong>g>for</str<strong>on</strong>g> end users after the applicati<strong>on</strong> migrati<strong>on</strong>.


34Envisi<strong>on</strong>ing Phase●●●●●C<strong>on</strong>sider including in the Test Role team members who have the expertise <strong>to</strong> testthe security of the migrated envir<strong>on</strong>ment. The security of the migrated applicati<strong>on</strong>is often overlooked in migrati<strong>on</strong> projects.Migrati<strong>on</strong> projects are often undertaken using existing technical staff who haveday-<strong>to</strong>-day resp<strong>on</strong>sibilities which impact their availability. Resources should beproperly planned and allocated <strong>to</strong> the project <strong>to</strong> avoid such impact.Technical staff that has experience with the current applicati<strong>on</strong> and databaseshould be involved in the project from design <strong>to</strong> deployment. Any required trainingshould be provided <strong>to</strong> improve their utility in the migrati<strong>on</strong>.Security, hardware, and infrastructure experts from Operati<strong>on</strong>s should also beinvolved in the Envisi<strong>on</strong>ing Phase because they can provide valuable advice aboutthe technical availability, costs, and the capabilities of the organizati<strong>on</strong>.Because moving from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows is a majorparadigm shift, it could impact the employment and careers of existing pers<strong>on</strong>nel.This issue should be c<strong>on</strong>sidered when <str<strong>on</strong>g>for</str<strong>on</strong>g>ming the team and carrying out themigrati<strong>on</strong>. Change is often inevitable and should be perceived as a way <strong>to</strong> expandand develop skills.Define the Project StructureThe project structure defines how the team manages and supports the project anddescribes the administrative structure <str<strong>on</strong>g>for</str<strong>on</strong>g> the project team going in<strong>to</strong> the subsequentproject phases.The main functi<strong>on</strong> of the project structure is <strong>to</strong> define standards the team will use duringthe project. These include communicati<strong>on</strong> standards, documentati<strong>on</strong> standards, andchange c<strong>on</strong>trol procedure standards. Program Management takes the lead in defining theproject structure.Refer <strong>to</strong> the <strong>UNIX</strong> Migrati<strong>on</strong> Project <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about project structure.Use the Project Structure document template <strong>to</strong> assist you in defining and recording theproject structure and pro<strong>to</strong>cols <str<strong>on</strong>g>for</str<strong>on</strong>g> the project team. This template is available in theToolsand Templates folder in the zip file download of this guidance athttp://go.microsoft.com/fwlink/?LinkId=45289.Define Project Communicati<strong>on</strong>sProgram Management should use the project structure <strong>to</strong> define standards <str<strong>on</strong>g>for</str<strong>on</strong>g> teammembers <strong>to</strong> communicate with <strong>on</strong>e another. Am<strong>on</strong>g these standards can be a definiti<strong>on</strong>of the reporting structure under which team members operate, procedures <strong>to</strong> elevateproject issues, regular mandated status meetings, and any other project-specificcommunicati<strong>on</strong> standards that need <strong>to</strong> be defined during the Envisi<strong>on</strong>ing Phase.The document may also include e-mail names, aliases, teleph<strong>on</strong>e lists, mail addresses,server share names, direc<strong>to</strong>ry structures, and other in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> critical <strong>to</strong> teamorganizati<strong>on</strong>. C<strong>on</strong>sider establishing a team collaborati<strong>on</strong> envir<strong>on</strong>ment wherecommunicati<strong>on</strong> can occur and progress be m<strong>on</strong>i<strong>to</strong>red and updated as necessary. Thefollowing list of fac<strong>to</strong>rs needs <strong>to</strong> be c<strong>on</strong>sidered <str<strong>on</strong>g>for</str<strong>on</strong>g> most <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong><strong>on</strong> Windows migrati<strong>on</strong> projects.● The project team will likely include members from the <strong>UNIX</strong> domain of the ITdepartment as well as the Windows domain. There are often work-based culturaldifferences between members of these two domains. The Program Managementrole should ensure that this potential difference is identified and extra attenti<strong>on</strong> ispaid <strong>to</strong> ensure clear communicati<strong>on</strong> between the members of the two domains.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 35●●Similarly, the communicati<strong>on</strong> <strong>to</strong>ols used by the <strong>UNIX</strong> and Windows users are oftenvery different. For example, Windows users use the calendaring features ofOutlook extensively <str<strong>on</strong>g>for</str<strong>on</strong>g> team communicati<strong>on</strong>. The <strong>UNIX</strong> users may be accus<strong>to</strong>med<strong>to</strong> a different set of <strong>to</strong>ols or clients.Different geographical locati<strong>on</strong>s and different cultural backgrounds of teammembers involved in the migrati<strong>on</strong> ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t can cause communicati<strong>on</strong> issues. Extraattenti<strong>on</strong> is required <strong>to</strong> make sure that there is clear communicati<strong>on</strong> between allteam members.Determine secure methods <strong>to</strong> share in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the project am<strong>on</strong>g the teammembers. If your team comprises c<strong>on</strong>sultants and in-house employees, there maybe corporate policies about what in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> can be shared with outsidec<strong>on</strong>sultants.Define Change C<strong>on</strong>trolChange c<strong>on</strong>trol standards and <strong>to</strong>ols help <strong>to</strong> manage both project documents andcomp<strong>on</strong>ents of the soluti<strong>on</strong> that are subject <strong>to</strong> revisi<strong>on</strong> or iterati<strong>on</strong>. The requirementsshould be clearly defined in the project structure. General in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about changec<strong>on</strong>trol is available in the UMPG.Migrati<strong>on</strong> projects have an additi<strong>on</strong>al source of change that is not obvious but must bemanaged: the initial state of the technology being migrated. This could be source code <str<strong>on</strong>g>for</str<strong>on</strong>g>applicati<strong>on</strong>s, hardware and software c<strong>on</strong>figurati<strong>on</strong>, and versi<strong>on</strong>s of applicati<strong>on</strong> software.Although the initial state can be baselined when the migrati<strong>on</strong> project is started,operati<strong>on</strong>al needs may require changes <strong>to</strong> that c<strong>on</strong>figurati<strong>on</strong> while the migrati<strong>on</strong> is underway. These operati<strong>on</strong>al changes are typically subject <strong>to</strong> C<strong>on</strong>figurati<strong>on</strong> Managementstandards imposed by an operati<strong>on</strong>s team.The Program Manager Role and Release Manager Role should work with operati<strong>on</strong>spers<strong>on</strong>nel resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> the existing technology <strong>to</strong> minimize and accommodate thesechanges. L<strong>on</strong>g-lived migrati<strong>on</strong> projects may require a <str<strong>on</strong>g>for</str<strong>on</strong>g>mal process <strong>to</strong> c<strong>on</strong>nec<strong>to</strong>perati<strong>on</strong>al C<strong>on</strong>figurati<strong>on</strong> Management <strong>to</strong> project change c<strong>on</strong>trol. Here are someadditi<strong>on</strong>al points <strong>to</strong> remember:● The major difference between a migrati<strong>on</strong> project and a new development projectis that the initial work has already been per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> create the existing soluti<strong>on</strong>.The existing soluti<strong>on</strong> provides a working example of the goals which the soluti<strong>on</strong>must meet.● Depending <strong>on</strong> the l<strong>on</strong>g term objectives of the project, an existing change c<strong>on</strong>trol<strong>to</strong>ol and reposi<strong>to</strong>ry <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m may be migrated <strong>to</strong> <strong>to</strong>ols in the Windowsplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.● As migrati<strong>on</strong> involves making modificati<strong>on</strong>s <strong>to</strong> objects currently in producti<strong>on</strong>, carehas <strong>to</strong> be taken in how these objects are shared with the new development ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t.As changes are discovered, there is the danger of modifying an object in theproducti<strong>on</strong> thread. Creati<strong>on</strong> of a separate project is recommended. In this situati<strong>on</strong>,any changes made <strong>to</strong> the producti<strong>on</strong> thread should also be applied <strong>to</strong> thedevelopment (migrati<strong>on</strong>) thread. Appropriate c<strong>on</strong>trols have <strong>to</strong> put in place <strong>to</strong> handlethis.


36Envisi<strong>on</strong>ing PhaseC<strong>on</strong>figurati<strong>on</strong> ManagementA major task in any database migrati<strong>on</strong> is the trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> of database objects, such assequences and code within the database, including s<strong>to</strong>red procedures. Thesetrans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>s inherently change the source code. To maintain a known state as workprogresses <strong>to</strong>wards migrati<strong>on</strong>, two aspects of C<strong>on</strong>figurati<strong>on</strong> Management have <strong>to</strong> beaddressed:● As discussed earlier, any change <strong>to</strong> the original envir<strong>on</strong>ment after the baseline iscreated needs <strong>to</strong> be communicated <strong>to</strong> the project team and accounted <str<strong>on</strong>g>for</str<strong>on</strong>g>. Changemanagement in the area of c<strong>on</strong>figurati<strong>on</strong> becomes critical if problems areencountered during the migrati<strong>on</strong> and you are <str<strong>on</strong>g>for</str<strong>on</strong>g>ced <strong>to</strong> return producti<strong>on</strong> <strong>to</strong> thepre-migrati<strong>on</strong> envir<strong>on</strong>ment.● Any changes <strong>to</strong> the soluti<strong>on</strong> that occur during the Developing Phase andStabilizing Phase need <strong>to</strong> be documented and communicated <strong>to</strong> the entire projectteam.During the Stabilizing Phase, knowledge of and c<strong>on</strong>trol over the test envir<strong>on</strong>mentc<strong>on</strong>figurati<strong>on</strong> is critical <strong>to</strong> understanding the results that are received. If documentati<strong>on</strong>exists identifying the aspects that have changed, the results of a given test can bevalidated against both current and future results.Some points <strong>to</strong> remember include:● Every c<strong>on</strong>figurati<strong>on</strong> change should have a fallback or rollback path.● C<strong>on</strong>figurati<strong>on</strong> management <strong>to</strong>ols, such as bug tracking software, should be able <strong>to</strong>operate within the Windows envir<strong>on</strong>ment.Assess RiskMSF stresses assessing project risk c<strong>on</strong>tinuously throughout a project and makes thisthe resp<strong>on</strong>sibility of every team member. Risk is defined as the possibility of suffering aloss or, more specifically, the possibility of a negative outcome that can put the project inperil. The team comes up with an initial set of risks in the Envisi<strong>on</strong>ing Phase. This list isc<strong>on</strong>stantly updated in later phases of the project as new risks begin <strong>to</strong> appear and old<strong>on</strong>es start <strong>to</strong> lose relevance. It is important <strong>to</strong> understand that in a migrati<strong>on</strong> projectissues are sometimes hidden, <str<strong>on</strong>g>for</str<strong>on</strong>g> example, in the design or implementati<strong>on</strong> of a piece ofcode, which will appear <strong>on</strong>ly as the soluti<strong>on</strong> is being trans<str<strong>on</strong>g>for</str<strong>on</strong>g>med. Here are somequesti<strong>on</strong>s that you need <strong>to</strong> ask <strong>to</strong> understand the potential high level risks at the start ofthe project. These questi<strong>on</strong>s can help you generate the risk assessment list that canserve as the basis <str<strong>on</strong>g>for</str<strong>on</strong>g> your <strong>on</strong>going risk assessment and management <str<strong>on</strong>g>for</str<strong>on</strong>g> the project.● Are the project sp<strong>on</strong>sors and stakeholders committed <strong>to</strong> support the project?● Does the migrati<strong>on</strong> team have the aggregate skill set <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the migrati<strong>on</strong>?● Are the project team members adequately motivated <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m their role in theproject?● What will the impact <strong>on</strong> the business be if there is a delay in the projectcompleti<strong>on</strong>?● Do you understand the real problems of the business and users that the project ismeant <strong>to</strong> address?● Have you accounted any possible temporary decrease in productivity due <strong>to</strong>distracti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> the project staff from their daily duties <strong>to</strong> support the migrati<strong>on</strong>project or while the cus<strong>to</strong>mers learn <strong>to</strong> use the new applicati<strong>on</strong>?


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 37●●●●●●●●For the applicati<strong>on</strong> suite <strong>to</strong> be migrated, do the vendors of any third-partyapplicati<strong>on</strong>s provide technical support in the new envir<strong>on</strong>ment?Is the applicati<strong>on</strong> dependent <strong>on</strong> third-party software that is not compatible withWindows?Does the existing <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database c<strong>on</strong>tain technologies that <strong>SQL</strong> <strong>Server</strong> cannotdirectly implement?Have you fully c<strong>on</strong>sidered the impact of the migrati<strong>on</strong> <strong>on</strong> other systems orapplicati<strong>on</strong>s that currently rely <strong>on</strong> or interact with the existing soluti<strong>on</strong>?Does documentati<strong>on</strong> exist <str<strong>on</strong>g>for</str<strong>on</strong>g> all the applicati<strong>on</strong>s and databases, such asrequirements, models (logical, physical), and source code?How will you handle possibly unproductive situati<strong>on</strong>s from staff members (technicaland operati<strong>on</strong>al) who could be displaced by the migrati<strong>on</strong>?How will you handle possible scope creep in the migrati<strong>on</strong> project?Have you c<strong>on</strong>sidered the impact of the migrated applicati<strong>on</strong> failing <strong>to</strong> meet <strong>on</strong>e ormore functi<strong>on</strong>al requirements?Manage RisksA good way <strong>to</strong> manage risks is <strong>to</strong> identify or anticipate potential risks be<str<strong>on</strong>g>for</str<strong>on</strong>g>ehand andcome up with a good mitigati<strong>on</strong> and preventi<strong>on</strong> strategy <strong>to</strong> deal with them in case theyoccur. The list of potential risks <str<strong>on</strong>g>for</str<strong>on</strong>g> a project is likely <strong>to</strong> be l<strong>on</strong>g, and not all potential riskscan be given the same amount of attenti<strong>on</strong> over the course of the project. It is there<str<strong>on</strong>g>for</str<strong>on</strong>g>eimperative <strong>to</strong> prioritize all the risks. This allows the team <strong>to</strong> focus more <strong>on</strong> the high priorityrisks, come up with suitable mitigati<strong>on</strong> plans <strong>to</strong> prevent them from happening, and createc<strong>on</strong>tingency plans <strong>to</strong> deal with them effectively if they materialize.This soluti<strong>on</strong> guide provides a risk assessment spreadsheet <str<strong>on</strong>g>for</str<strong>on</strong>g> you <strong>to</strong> m<strong>on</strong>i<strong>to</strong>r yourproject risks based <strong>on</strong> this methodology.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 393Planning PhaseIntroducti<strong>on</strong> and GoalsIn the Planning Phase, the team defines the soluti<strong>on</strong> in detail — what <strong>to</strong> build, how <strong>to</strong>build it, who will build it, and when it will be built. During this phase, the initial visi<strong>on</strong> andsoluti<strong>on</strong> c<strong>on</strong>cept defined in the Envisi<strong>on</strong>ing Phase is translated in<strong>to</strong> practicalimplementati<strong>on</strong> designs and plans <str<strong>on</strong>g>for</str<strong>on</strong>g> how <strong>to</strong> achieve it. Team members draw up<strong>on</strong> theirexpertise <strong>to</strong> create individual plans and designs in all areas of the project, ranging fromsecurity <strong>to</strong> budget <strong>to</strong> deployment. Likewise, individual team schedules and associateddependencies are identified. These plans and schedules are rolled in<strong>to</strong> a master projectplan by the Program Management Role.The phase c<strong>on</strong>cludes when the project team agrees that the plans are sufficiently welldefined<strong>to</strong> proceed with development, and the team, business sp<strong>on</strong>sor, and keystakeholders approve the functi<strong>on</strong>al specificati<strong>on</strong> and the master project plan andschedule, usually at a milest<strong>on</strong>e meeting. The <str<strong>on</strong>g>for</str<strong>on</strong>g>mal c<strong>on</strong>clusi<strong>on</strong> is marked by the sec<strong>on</strong>dmajor project milest<strong>on</strong>e, Project Plans Approved.The key deliverables <str<strong>on</strong>g>for</str<strong>on</strong>g> the project team <str<strong>on</strong>g>for</str<strong>on</strong>g> the Planning Phase are:● Functi<strong>on</strong>al specificati<strong>on</strong>. The functi<strong>on</strong>al specificati<strong>on</strong> is the virtual reposi<strong>to</strong>ry ofproject and design related artifacts that are created in the Planning Phase. Theartifacts are primarily a result of design activities during the c<strong>on</strong>ceptual design,logical design, and physical design processes of the Planning Phase. The artifactscan include models such as case diagrams, usage scenarios, feature list, userinterface screen shots, database design, and so <strong>on</strong>.The key goals of the functi<strong>on</strong>al specificati<strong>on</strong> are <strong>to</strong> c<strong>on</strong>solidate a comm<strong>on</strong>understanding of the business, design, and user requirements; break down theproblem and modularize the soluti<strong>on</strong> logically; provide a framework <strong>to</strong> plan,schedule, and build the soluti<strong>on</strong>; and <strong>to</strong> serve as a c<strong>on</strong>tract between the team andthe cus<strong>to</strong>mer and stakeholders.● Master project plan. The master project plan is a collecti<strong>on</strong> of individual plans thataddress tasks per<str<strong>on</strong>g>for</str<strong>on</strong>g>med by each of the six team roles <strong>to</strong> achieve the functi<strong>on</strong>alitydefined in the functi<strong>on</strong>al specificati<strong>on</strong>. The master project plan documents thestrategies the team roles will use <strong>to</strong> complete their work. The soluti<strong>on</strong> c<strong>on</strong>cept thatthe team developed in the Envisi<strong>on</strong>ing Phase provides high-level approaches thatare developed in<strong>to</strong> detailed plans in the Planning Phase. See Chapter 2,"Envisi<strong>on</strong>ing Phase," <str<strong>on</strong>g>for</str<strong>on</strong>g> the discussi<strong>on</strong> of team roles.● Master project schedule. The individual team schedules apply a time frame <strong>to</strong> themaster plan. The master project schedule synchr<strong>on</strong>izes project schedules across


40Planning Phase●the teams. Aggregating the individual schedules gives the team an overall view ofthe project schedule and is the first step <strong>to</strong>ward determining a fixed ship date.Updated master risk assessment document. The master risk assessmentdocument that was developed during the Envisi<strong>on</strong>ing Phase is reviewed andupdated regularly during the Planning Phase.All of these deliverables are living documents, evolving as the project progresses.Though these documents can be modified, modificati<strong>on</strong>s must follow the changemanagement policies set up <str<strong>on</strong>g>for</str<strong>on</strong>g> the project during the Envisi<strong>on</strong>ing Phase.Table 3.1 lists the key activities that the team undertakes in the Planning Phase. Theresults of these activities are documented in this phase's deliverables.Table 3.1: Major Tasks, Deliverables, Owners, and Job AidsTasksDeliverablewhere resultsare documentedPrimary ownerJob Aidsprovided in thissoluti<strong>on</strong>Complete detailedassessment of thecurrent envir<strong>on</strong>mentFuncti<strong>on</strong>alspecificati<strong>on</strong>ProgramManagementAssessing theEnvir<strong>on</strong>mentQuesti<strong>on</strong>naireDevelop thesoluti<strong>on</strong> design andarchitectureFuncti<strong>on</strong>alspecificati<strong>on</strong>ProgramManagementValidate thetechnologyDevelop the projectplansFuncti<strong>on</strong>alspecificati<strong>on</strong>Master project planDevelopmentTeam leads <str<strong>on</strong>g>for</str<strong>on</strong>g> allroles; plansc<strong>on</strong>solidated byProgram Manager* Development Plan* Test Plan* Deployment Plan* Pilot PlanCreate the projectschedulesSet up thedevelopment andtest envir<strong>on</strong>mentsReassess currentproject risksMaster projectscheduleRisk assessmentdocumentTeam leads <str<strong>on</strong>g>for</str<strong>on</strong>g> allrolesDevelopment andTestProgramManagementMigrati<strong>on</strong> RiskExposure RatingFormComplete a Detailed Assessment of the ExistingEnvir<strong>on</strong>mentTo begin the migrati<strong>on</strong> process, an accurate and detailed assessment of the existingenvir<strong>on</strong>ment of your organizati<strong>on</strong> is essential. A high level assessment is carried out inthe Envisi<strong>on</strong>ing Phase. The detailed assessment in the Planning Phase is a follow upactivity.The in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> collected by this assessment should be comprehensive enough <strong>to</strong> planthe specific details of the soluti<strong>on</strong> migrati<strong>on</strong>. For instance, a detailed assessment of theapplicati<strong>on</strong> will provide definitive in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> whether existing test plans can be reused


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 41<strong>to</strong> test the soluti<strong>on</strong>. Without this detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the existing envir<strong>on</strong>ment,there is no way <strong>to</strong> accurately estimate the development, test, or deployment plans.The key elements of the envir<strong>on</strong>ment that need <strong>to</strong> be assessed in detail include:●●●Applicati<strong>on</strong>DatabaseApplicati<strong>on</strong> infrastructureRefer <strong>to</strong> the Assessing the Envir<strong>on</strong>ment Questi<strong>on</strong>naire job aid <strong>to</strong> help you assess themain areas of the envir<strong>on</strong>ment.Applicati<strong>on</strong>A detailed assessment should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <str<strong>on</strong>g>for</str<strong>on</strong>g> any applicati<strong>on</strong> that is affected by themigrati<strong>on</strong>. A database applicati<strong>on</strong> migrati<strong>on</strong> project assessment should not be limited <strong>to</strong>assessing the applicati<strong>on</strong> al<strong>on</strong>e; it should also include database c<strong>on</strong>nectivity.Assessment activities related <strong>to</strong> the database should include the following:● Note all database interfaces used by the applicati<strong>on</strong>s and their types (OCI, ODBC,and so <strong>on</strong>).● Note the relati<strong>on</strong>ship between applicati<strong>on</strong>s and databases. For example, note if adatabase supports multiple applicati<strong>on</strong>s, or an applicati<strong>on</strong> c<strong>on</strong>nects <strong>to</strong> multipledatabases.● Identify all the database, schemas, and schema objects that the applicati<strong>on</strong>interacts with.● Note the pro<strong>to</strong>col that is used by the applicati<strong>on</strong> <strong>to</strong> communicate with thedatabase. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> supports TCP/IP, TCP/IP with SSL, and named pipes.● Identify all encrypti<strong>on</strong> methods employed by the applicati<strong>on</strong>s with the databases.● Identify the security features of the database used by the applicati<strong>on</strong>s, such asauthenticati<strong>on</strong>, password features, single sign <strong>on</strong>, and so <strong>on</strong>.● Determine if there are any other network-related security authenticati<strong>on</strong> methodsused with the current applicati<strong>on</strong>. Comm<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> authenticati<strong>on</strong> methods includeKerberos, Radius, DES Algorithm, RSA, and Cybersafe.● Note the data sources in use, such as ODBC, OLE DB, and ADO.In additi<strong>on</strong> <strong>to</strong> questi<strong>on</strong>s related <strong>to</strong> database c<strong>on</strong>nectivity, here are some generalapplicati<strong>on</strong> assessment questi<strong>on</strong>s that you may need <strong>to</strong> ask.● Identify the programming language used <str<strong>on</strong>g>for</str<strong>on</strong>g> the main applicati<strong>on</strong> as well as anysupplementary programs.● Identify the plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m support (hardware and operating system), architecture, andcomp<strong>on</strong>ent interfaces of the existing applicati<strong>on</strong>.● Locate any existing in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the applicati<strong>on</strong>. Is the source codeavailable? Other items that may help plan <str<strong>on</strong>g>for</str<strong>on</strong>g> migrati<strong>on</strong> include test scripts,documentati<strong>on</strong>, process flow charts, and use cases.● Record any dependencies and characteristics, such as third-party libraries, <strong>UNIX</strong>utilities, or path names. Also, determine if the <strong>UNIX</strong> applicati<strong>on</strong> uses X Windows,Motif, or xrt libraries.● Determine the security architecture of the applicati<strong>on</strong>. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is importantbecause features and implementati<strong>on</strong>s are different between Microsoft Windows®and <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms.● Record any encrypti<strong>on</strong> pro<strong>to</strong>cols currently being used. SSL and PGP are twocomm<strong>on</strong> encrypti<strong>on</strong> methods.


42Planning Phase●●Verify if the applicati<strong>on</strong> uses daem<strong>on</strong> processes. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is requiredbecause <strong>UNIX</strong> applicati<strong>on</strong>s can be started in the background and will c<strong>on</strong>tinue <strong>to</strong>run even after a user logs off the system. Using applicati<strong>on</strong> services in Windows2003 provides similar functi<strong>on</strong>ality.Check <str<strong>on</strong>g>for</str<strong>on</strong>g> any file system dependencies. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is required because<strong>UNIX</strong> and Windows use different file access methods.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> assessing the applicati<strong>on</strong> be<str<strong>on</strong>g>for</str<strong>on</strong>g>e migrating from <strong>UNIX</strong> <strong>to</strong>Windows, refer <strong>to</strong> the <strong>UNIX</strong> Applicati<strong>on</strong> Migrati<strong>on</strong> <str<strong>on</strong>g>Guide</str<strong>on</strong>g>, available athttp://go.microsoft.com/fwlink/?LinkId=30832.DatabaseTo migrate an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong> Microsoft <strong>SQL</strong> <strong>Server</strong> successfully, the project teammust assess the technical details of the current system.The following assessment activities should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong> the existing <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database:● Identify and record the database name and all c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.● Determine the type of database being used. Comm<strong>on</strong> database types includeDecisi<strong>on</strong> Support System (DSS), Online Transacti<strong>on</strong> Processing (OLTP), or acombinati<strong>on</strong> of the two.● Locate any existing design documents, such as data models, database creati<strong>on</strong>scripts, or data definiti<strong>on</strong> language (DDL) specificati<strong>on</strong>s.● Record detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> existing database structures, including tables,views, s<strong>to</strong>red procedures, indexes, users, and roles.● Identify and record the current locati<strong>on</strong> of database files, such as S<strong>to</strong>rage Area<strong>Net</strong>work (SAN), <strong>Net</strong>work Attached S<strong>to</strong>rage (NAS), or local attached s<strong>to</strong>rage.● Identify and record the disk space c<strong>on</strong>sumed by the existing database files. Also,obtain estimates of growth rate of the database files.● Evaluate the existing backup soluti<strong>on</strong>, including the frequency and type of backup(full, archive log, and so <strong>on</strong>).● Assess the database c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, including the sort order andcharacter set.● Examine the frequency of data dumps and log dumps.● Determine the dependencies of the database <strong>on</strong> other databases or plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms.Comm<strong>on</strong> examples include distributed databases, replicati<strong>on</strong>, data marts, and datawarehouses.● Identify and analyze the server side scripts in use <str<strong>on</strong>g>for</str<strong>on</strong>g> activities such as data loads,batch processing, reporting, and administrati<strong>on</strong>.The Migrati<strong>on</strong> Analyzer <strong>to</strong>ol, which is a part of the <strong>SQL</strong> <strong>Server</strong> Migrati<strong>on</strong> Assistant(SSMA), analyzes the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases and produces vital statistics <strong>on</strong> the sizeand complexity of the migrati<strong>on</strong>. This <strong>to</strong>ol can be downloaded fromhttp://www.microsoft.com/sql/migrati<strong>on</strong>. The beta versi<strong>on</strong> of this <strong>to</strong>ol is available as of thedate of publishing this soluti<strong>on</strong>. Versi<strong>on</strong> 1.0 of the <strong>to</strong>ol is slated <strong>to</strong> be available in June2005Applicati<strong>on</strong> InfrastructureThe applicati<strong>on</strong> infrastructure can be broadly classified as server-related and networkrelated.<strong>Server</strong>-related infrastructure relates directly <strong>to</strong> the hardware and software <strong>on</strong> theserver. <strong>Server</strong>-related items include operating systems, processors, memory, s<strong>to</strong>rage,


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 43tape drives, and file systems. Examples of network-related infrastructure include routers,firewalls, switches, domain name servers (DNS), and virtual private networks (VPN).Security infrastructure is classified under both server-related and network-relatedinfrastructure. Comm<strong>on</strong> items within the server security infrastructure are <strong>Net</strong>workIn<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> Services (NIS and NIS+) and Lightweight Direc<strong>to</strong>ry Access Pro<strong>to</strong>col (LDAP).The following assessment activities should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <str<strong>on</strong>g>for</str<strong>on</strong>g> server-related infrastructure:●●●●Check the capacity and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of the servers and server clusters of theexisting envir<strong>on</strong>ment. Also verify if the clusters are situated in single or multiplelocati<strong>on</strong>s.The hardware c<strong>on</strong>figurati<strong>on</strong> details need <strong>to</strong> be gathered <str<strong>on</strong>g>for</str<strong>on</strong>g> any dependencies thatmight affect the migrati<strong>on</strong>, including architecture (32-bit versus 64-bit, hyperthreading,hybrid), processor speed, number of CPUs, and the number of availablesockets <str<strong>on</strong>g>for</str<strong>on</strong>g> upgrades.Record any pertinent in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the RAM installed in the server, includingsize, c<strong>on</strong>figurati<strong>on</strong>, and number of open slots available <str<strong>on</strong>g>for</str<strong>on</strong>g> upgrades.Verify disk s<strong>to</strong>rage needs <str<strong>on</strong>g>for</str<strong>on</strong>g> database files and the disk space c<strong>on</strong>sumed <str<strong>on</strong>g>for</str<strong>on</strong>g> theexisting database files. Identify the s<strong>to</strong>rage requirements, such as:● Amount of space needed <str<strong>on</strong>g>for</str<strong>on</strong>g> current and growth fac<strong>to</strong>rs● Spindle RPM (disks: 15000 RPM versus 10000 RPM; SAN: 1 gbps versus 2gbps)● Throughput (theoretical I/O, current I/O, anticipated I/O) <str<strong>on</strong>g>for</str<strong>on</strong>g> each element ofthe s<strong>to</strong>rage system● Disk size(s)● RAID levels● S<strong>to</strong>rage Architecture (SAN, NAS, external s<strong>to</strong>rage, internal s<strong>to</strong>rage)The following assessment activities should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <str<strong>on</strong>g>for</str<strong>on</strong>g> network-relatedinfrastructure:● Identify the existing network pro<strong>to</strong>cols and network bandwidth.● Examine the routers, switches, and firewalls <str<strong>on</strong>g>for</str<strong>on</strong>g> the existing soluti<strong>on</strong>. Verify thec<strong>on</strong>figurati<strong>on</strong> and locati<strong>on</strong> of firewalls and proxies.● Assess the network <strong>to</strong>pology that exists in the organizati<strong>on</strong>.● In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the network infrastructure needs <strong>to</strong> be identified, including thelogical organizati<strong>on</strong> of the network, name and address resoluti<strong>on</strong> methods, andnetwork naming c<strong>on</strong>venti<strong>on</strong>s.● Analyze the network sites and the bandwidth between the sites. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>can be used <strong>to</strong> plan optimum strategies and schedules <str<strong>on</strong>g>for</str<strong>on</strong>g> installati<strong>on</strong> anddeployment.● Assess the trust relati<strong>on</strong>ships and policy restricti<strong>on</strong>s of the existing soluti<strong>on</strong>.Develop the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> Design and ArchitectureThe Planning Phase of the MSF Process Model includes three design processes:c<strong>on</strong>ceptual, logical, and physical. These three processes are not per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in parallel.Instead, their starting and ending points are staggered. These processes are dependent<strong>on</strong> each other. The logical design is dependent <strong>on</strong> the c<strong>on</strong>ceptual design, and thephysical design is dependent <strong>on</strong> the logical design. Table 3.2 compares the three designprocesses.


44Planning PhaseTable 3.2: Comparing C<strong>on</strong>ceptual, Logical, and Physical DesignType of Design Perspective PurposeC<strong>on</strong>ceptual DesignLogical DesignPhysical DesignViews the problem from theperspective of the user andbusinessViews the soluti<strong>on</strong> from theperspective of thedesign/architecture teamViews the soluti<strong>on</strong> from theperspective of thedevelopersDefines the problem andsoluti<strong>on</strong> in terms of usagescenarios and refinedrequirementsDefines the soluti<strong>on</strong> as alogical set of co-operatingobjects and servicesDefines the soluti<strong>on</strong>comp<strong>on</strong>ents andtechnologiesIn a migrati<strong>on</strong> project it is quite likely that you already have detailed design documents <str<strong>on</strong>g>for</str<strong>on</strong>g>the existing system. These documents can provide an excellent starting point <str<strong>on</strong>g>for</str<strong>on</strong>g> yourdesign process. Enhancements can be made <strong>to</strong> account <str<strong>on</strong>g>for</str<strong>on</strong>g> the additi<strong>on</strong>al requirementsand functi<strong>on</strong>ality <str<strong>on</strong>g>for</str<strong>on</strong>g> the new system.Build the C<strong>on</strong>ceptual DesignThe first design process in the Planning Phase is c<strong>on</strong>ceptual design. Once completed,the c<strong>on</strong>ceptual design is used in the creati<strong>on</strong> of the logical and physical designprocesses.C<strong>on</strong>ceptual design is the process of gathering, analyzing, and prioritizing business anduser perspectives of the problem and the soluti<strong>on</strong>, and then creating a high levelrepresentati<strong>on</strong> of the soluti<strong>on</strong> in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m of detailed requirements. The team gathers highlevel requirements during the Envisi<strong>on</strong>ing Phase and documents them in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m of usecases and usage scenarios. While producing the c<strong>on</strong>ceptual design, the team refinesthese requirements.Develop Detailed RequirementsA c<strong>on</strong>ceptual design records the system requirements in terms of the followingrequirements:● Business requirements● User requirements● System requirements● Operati<strong>on</strong>al requirementsEach of these is described under the following headingsBusiness RequirementsBusiness requirements describe the organizati<strong>on</strong>'s needs and expectati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> thesoluti<strong>on</strong>. These requirements exist at the managerial decisi<strong>on</strong>-making level and providethe c<strong>on</strong>text in which the soluti<strong>on</strong> will operate.Some example business requirements include:● The database migrati<strong>on</strong> from <strong>UNIX</strong> <strong>to</strong> Windows should be completed in the giventime frame.● The existing business rules and policies should be maintained <strong>on</strong> the new system.● Ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t required <str<strong>on</strong>g>for</str<strong>on</strong>g> migrati<strong>on</strong> should justify the cost incurred.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 45●The existing level of per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and functi<strong>on</strong>ality should be maintained after themigrati<strong>on</strong>, including disaster recovery, availability, and scalability.User RequirementsUser requirements define the n<strong>on</strong>functi<strong>on</strong>al aspect of the user's interacti<strong>on</strong> with thesoluti<strong>on</strong>. They help you <strong>to</strong> determine the user interface and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance expectati<strong>on</strong>s ofthe soluti<strong>on</strong> in terms of its reliability, availability, and accessibility. In additi<strong>on</strong>, the userrequirements help you identify the training that the users will need <strong>to</strong> effectively use thesoluti<strong>on</strong>.Some example user requirements include:●●●The user should be able <strong>to</strong> use the same or similar interface as the applicati<strong>on</strong>running <strong>on</strong> the <strong>UNIX</strong> system <strong>to</strong> minimize user retraining.The time taken <strong>to</strong> retrieve in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> from the system should not increase.There should be comprehensive user manuals <str<strong>on</strong>g>for</str<strong>on</strong>g> the new system. Trainingmanuals should also be c<strong>on</strong>sidered <str<strong>on</strong>g>for</str<strong>on</strong>g> new users.System RequirementsSystem requirements specify the detailed transacti<strong>on</strong>s and their sequence in the system.The requirements help the project team define how the new soluti<strong>on</strong> will interact with theexisting systems. Some example system requirements include:●●●After the migrati<strong>on</strong>, the new system should c<strong>on</strong>tinue <strong>to</strong> interoperate withapplicati<strong>on</strong>s as it did <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.The system should not require a user credential other than the credentials passedfrom logging <strong>on</strong><strong>to</strong> the corporate network (single sign <strong>on</strong>).The system should support internal and remote users.Operati<strong>on</strong>al RequirementsOperati<strong>on</strong>al requirements describe what the soluti<strong>on</strong> must deliver <strong>to</strong> maximize operabilityand improve service delivery with reduced downtime and risks. Some exampleoperati<strong>on</strong>al requirements include:●●●●●The system should allow administra<strong>to</strong>rs <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m their tasks both <strong>on</strong>-site andremotely.The system should be able <strong>to</strong> recover from critical failure without major impact andwithin service levels.The system should include a process <str<strong>on</strong>g>for</str<strong>on</strong>g> managing the <strong>to</strong>tal throughput andresp<strong>on</strong>se time within the stated service levels.The system should be able <strong>to</strong> handle varying levels of user load and transacti<strong>on</strong>s.In additi<strong>on</strong>, the site should be designed so that it can be modified and upgradedwithout affecting availability and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.Large clients should be separated with respect <strong>to</strong> database infrastructure <strong>to</strong>minimize the impact <strong>on</strong> maintenance and availability.Build the Logical DesignThe logical design is the sec<strong>on</strong>d step in creating the soluti<strong>on</strong> design. After identifying thebusiness and user needs in the c<strong>on</strong>ceptual design, the logical design defines how thedifferent parts of the soluti<strong>on</strong> will coordinate and work <strong>to</strong>gether. The logical designdefines the parts of the system, provides a framework <strong>to</strong> hold all the parts of the system<strong>to</strong>gether, and illustrates how the system interacts with the users and other systems.


46Planning PhaseWhile creating the logical design, the team takes in<strong>to</strong> account all the business, user,operati<strong>on</strong>al and system requirements that state the need <str<strong>on</strong>g>for</str<strong>on</strong>g> security, auditing, logging,scalability, state management, error handling, licensing, globalizati<strong>on</strong>, applicati<strong>on</strong>architecture, integrati<strong>on</strong> with other systems, and so <strong>on</strong>.There are several ways <strong>to</strong> represent the logical design of a system. A comm<strong>on</strong>ly usedvisual modeling language is Unified Modeling Language (UML). A detailed discussi<strong>on</strong> ofUML is out of the scope of this soluti<strong>on</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> UML, refer <strong>to</strong> TheUnified Modeling Language User <str<strong>on</strong>g>Guide</str<strong>on</strong>g> (Booch, Jacobs<strong>on</strong>, and Rumbaugh 1999) andUse Case Driven Object Modeling with UML: A Practical Approach (Rosenberg and Scott1999).Figure 3.1 shows a sample logical design <str<strong>on</strong>g>for</str<strong>on</strong>g> a system using the Logical Object Model, asdefined by UML. The sample design represents the system in terms of:● Objects. These are people or things in the system. "Order" is an example of anobject in Figure 3.1.● Services. These are the behavior or functi<strong>on</strong>ality associated with any object. Forexample, "Track Status()" is a service provided by the "Order" object in Figure 3.1.● Attributes. These are characteristics or properties of the objects. For example,"Order ID" and "Ship Date" are attributes of the "Order" object in Figure 3.1● Relati<strong>on</strong>ships. These represent ways in which objects are linked with each other.For example, the object Order and the object Order line item are shown <strong>to</strong> have anassociative relati<strong>on</strong>ship in Figure 3.1 by a thick line. This shows that they arerelated and a change <strong>to</strong> <strong>on</strong>e affects the other.The objects, services, attributes and relati<strong>on</strong>ships can be obtained from the detailedusage scenarios that were developed in the c<strong>on</strong>ceptual design phase.The logical design represents a logical view of the complete system. Individual teams,such as those <str<strong>on</strong>g>for</str<strong>on</strong>g> User Interface (UI) development, the database development, and theapplicati<strong>on</strong> development can take this representati<strong>on</strong> and start <strong>to</strong> build the detaileddesigns <str<strong>on</strong>g>for</str<strong>on</strong>g> their domain when making the physical design.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 47Figure 3.1Creating a logical design <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong>Logical Design C<strong>on</strong>siderati<strong>on</strong>sThe logical design <str<strong>on</strong>g>for</str<strong>on</strong>g> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database migrati<strong>on</strong> project must take in<strong>to</strong> account thechanges that will occur as a result of migrati<strong>on</strong> from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. The followingitems should be c<strong>on</strong>sidered:● Are there any dependencies between client applicati<strong>on</strong>s and databasec<strong>on</strong>nectivity?● Do <strong>UNIX</strong> scripts support the client applicati<strong>on</strong>s?● How are communicati<strong>on</strong>s between the applicati<strong>on</strong> and database secured internallyand over the internet?● How is data distributed across multiple databases and multiple servers?


48Planning PhaseExamining the c<strong>on</strong>ceptual design of the client applicati<strong>on</strong> will provide an understanding ofhow it operates and is structured. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is used <strong>to</strong> create the physical designof the soluti<strong>on</strong>. Two additi<strong>on</strong>al design studies that may assist in creating the physicaldesign are discussed in the following secti<strong>on</strong>.High Level User Interface and Database DesignUsing the objects, services, attributes, and relati<strong>on</strong>ships identified in the logical design ofthe system, the team might decide <strong>to</strong> create a high-level user interface and databasedesign.The list of objects and services gives the team an idea about the kind of functi<strong>on</strong>alityexpected by the users. The team can use this in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>to</strong> design user interfaceelements such as butt<strong>on</strong>s, text fields, and menu items.Similarly, the object and attribute in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> of the logical design can be used <strong>to</strong> developan initial database design equivalent <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database being migrated.Build the Physical DesignPhysical design is the process of describing the comp<strong>on</strong>ents, services, and technologiesof the soluti<strong>on</strong> from the perspective of the development team. The goal of the design is <strong>to</strong>provide clarity and detail <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the development teams <strong>to</strong> develop their comp<strong>on</strong>ents,be it the user interface, business logic, database, or infrastructure.The physical design should include:● Class definiti<strong>on</strong> of applicati<strong>on</strong>s.● Database schema <str<strong>on</strong>g>for</str<strong>on</strong>g> the soluti<strong>on</strong>.● Baseline deployment model that provides:● The network <strong>to</strong>pology, showing hardware locati<strong>on</strong>s and interc<strong>on</strong>necti<strong>on</strong>s.● The data and comp<strong>on</strong>ent technology, which indicates the locati<strong>on</strong>s of thesoluti<strong>on</strong> comp<strong>on</strong>ents, services, and data s<strong>to</strong>rage in relati<strong>on</strong> <strong>to</strong> the network<strong>to</strong>pology.●●Comp<strong>on</strong>ent specificati<strong>on</strong>s that include internal structure of comp<strong>on</strong>ents andcomp<strong>on</strong>ent interfaces.Programming models that identify implementati<strong>on</strong> guidelines <str<strong>on</strong>g>for</str<strong>on</strong>g> threading, errorhandling, security, and code documentati<strong>on</strong>.A detailed discussi<strong>on</strong> of physical design is out of scope of this soluti<strong>on</strong>. For detailedguidance <strong>on</strong> designing the data layer, designing the presentati<strong>on</strong> layer, and designing thesecurity specificati<strong>on</strong>s, refer <strong>to</strong> chapters 7 through 9 of Analyzing Requirements andDefining Microsoft .NET <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> Architectures (Microsoft Press 2003).The physical design diagram allows you <strong>to</strong> see how all the comp<strong>on</strong>ents c<strong>on</strong>nect <strong>to</strong>gether.For completeness, it may include infrastructure elements outside of the scope of theproject such as firewalls or network c<strong>on</strong>necti<strong>on</strong>s that are not directly related <strong>to</strong> thesoluti<strong>on</strong>. It will help prove the security of the system, and may show potential throughputbottlenecks, or highlight single points of failure.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 49Figure 3.2 shows a sample physical design diagram. Your design c<strong>on</strong>siderati<strong>on</strong>s willrequire you <strong>to</strong> modify this example.Figure 3.2Creating a physical design <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong> and database.The following secti<strong>on</strong>s will help you plan <str<strong>on</strong>g>for</str<strong>on</strong>g> a migrati<strong>on</strong> by identifying the variouscomp<strong>on</strong>ents of the physical design and outlining the typical design c<strong>on</strong>siderati<strong>on</strong>s thatare part of a typical migrati<strong>on</strong>.


50Planning PhaseIncorporate Design C<strong>on</strong>siderati<strong>on</strong>sWhile migrating, you may want <strong>to</strong> utilize some of the advanced functi<strong>on</strong>s that areincorporated in<strong>to</strong> <strong>SQL</strong> <strong>Server</strong> and Windows <strong>Server</strong> 2003. Some references may exist<str<strong>on</strong>g>for</str<strong>on</strong>g> Windows® 2000 but the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> also applies <strong>to</strong> Windows <strong>Server</strong> 2003. For morein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer <strong>to</strong> the following resources:● Designing <str<strong>on</strong>g>for</str<strong>on</strong>g> scalabilityhttp://msdn.microsoft.com/library/default.asp?url=/library/enus/architec/8_ar_sa2_8rnd.asp● Designing <str<strong>on</strong>g>for</str<strong>on</strong>g> availabilityhttp://www.microsoft.com/technet/prodtechnol/sql/2000/plan/ssmsam.mspx● Designing <str<strong>on</strong>g>for</str<strong>on</strong>g> reliabilityhttp://www.microsoft.com/mscorp/twc/reliability/default.mspx● Designing <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancehttp://www.microsoft.com/sql/evaluati<strong>on</strong>/compare/benchmarks.asphttp://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ansvcspg.mspx● Designing <str<strong>on</strong>g>for</str<strong>on</strong>g> interoperabilityhttp://www.microsoft.com/technet/prodtechnol/sql/2000/deploy/sqlorcle.mspxHardware Design C<strong>on</strong>siderati<strong>on</strong>sIn additi<strong>on</strong> <strong>to</strong> the advanced features available in <strong>SQL</strong> <strong>Server</strong>, there are many software<strong>to</strong>ols available <strong>to</strong> assist in ensuring that the correct hardware is acquired. Some of these<strong>to</strong>ols are listed here:● Microsoft Datasizer Tool. This spreadsheet helps estimate table sizes. For morein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer <strong>to</strong>http://www.microsoft.com/downloads/details.aspx?FamilyId=564C5704-D4F5-4EE8-9F3C-CB429499D075&displaylang=en.● Dell Powermatch sizing <strong>to</strong>ols. These <strong>to</strong>ols are available <strong>to</strong> assist in selecting Dellhardware <str<strong>on</strong>g>for</str<strong>on</strong>g> use with <strong>SQL</strong> <strong>Server</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer <strong>to</strong>http://www1.us.dell.com/c<strong>on</strong>tent/<strong>to</strong>pics/global.aspx/alliances/en/sizing?c=us&cs=555&l=en&s=biz.● HP sizing <strong>to</strong>ols. These <strong>to</strong>ols are available <strong>to</strong> assist in selecting HP servers <str<strong>on</strong>g>for</str<strong>on</strong>g> usewith <strong>SQL</strong> <strong>Server</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer <strong>to</strong>http://h71019.www7.hp.com/ActiveAnswers/cache/70729-0-0-0-121.aspx.● Unisys System Sizing Tools <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>. These <strong>to</strong>ols are available <strong>to</strong> assistin c<strong>on</strong>figuring Unisys servers <str<strong>on</strong>g>for</str<strong>on</strong>g> use with <strong>SQL</strong> <strong>Server</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer<strong>to</strong>http://unisys.com/products/es7000__servers/business__soluti<strong>on</strong>s/oltp__database__server/sql__server__resources.htm.Validate the TechnologyParallel <strong>to</strong> the design process, the team will often validate the technologies being used inthe soluti<strong>on</strong>. During technology validati<strong>on</strong>, the team evaluates the products ortechnologies <strong>to</strong> ensure that they work according <strong>to</strong> specificati<strong>on</strong>s provided by their vendorand that they will meet the business needs <str<strong>on</strong>g>for</str<strong>on</strong>g> the specific soluti<strong>on</strong> scenario.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 51<strong>SQL</strong> <strong>Server</strong> Editi<strong>on</strong>s and FeaturesWhile <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> is available in Pers<strong>on</strong>al, Standard, and Enterprise Editi<strong>on</strong>s,<strong>SQL</strong> <strong>Server</strong> 2000 is available in the following editi<strong>on</strong>s:● <strong>SQL</strong> <strong>Server</strong> 2000 Enterprise Editi<strong>on</strong> (64-bit)● <strong>SQL</strong> <strong>Server</strong> 2000 Enterprise Editi<strong>on</strong>● <strong>SQL</strong> <strong>Server</strong> 2000 Standard Editi<strong>on</strong>● <strong>SQL</strong> <strong>Server</strong> 2000 Developer Editi<strong>on</strong>All editi<strong>on</strong>s of Windows® XP and Windows <strong>Server</strong> 2003 include support <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>.Support exists <str<strong>on</strong>g>for</str<strong>on</strong>g> many earlier versi<strong>on</strong>s of Windows, as well.As with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, each editi<strong>on</strong> is distinguished primarily by the availability of certainfeatures, progressing from Pers<strong>on</strong>al Editi<strong>on</strong> <strong>to</strong> Enterprise Editi<strong>on</strong>. <strong>SQL</strong> <strong>Server</strong> also offersseveral different editi<strong>on</strong>s. Each editi<strong>on</strong> provides functi<strong>on</strong>ality based <strong>on</strong> scale as shown inTable 3.3.Table 3.3: <strong>SQL</strong> <strong>Server</strong> 2000 Editi<strong>on</strong>s ComparedOSRequirementsand ScalabilityOperating SystemEnterprise (64-bit) Editi<strong>on</strong>* Windows <strong>Server</strong>2003 EnterpriseEditi<strong>on</strong>* Windows <strong>Server</strong>2003 DatacenterEditi<strong>on</strong>Scalability * Up <strong>to</strong> 64processors* Up <strong>to</strong> 512 GB ofmemory* Maximumdatabase size of1,048,516 TBEnterpriseEditi<strong>on</strong>* Windows <strong>Server</strong>2003 StandardEditi<strong>on</strong>* Windows <strong>Server</strong>2003 EnterpriseEditi<strong>on</strong>* Windows <strong>Server</strong>2003 DatacenterEditi<strong>on</strong>* Up <strong>to</strong> 32processors* Up <strong>to</strong> 64 GB ofmemory* Maximumdatabase size of1,048,516 TBStandard Editi<strong>on</strong>* Windows <strong>Server</strong>2003 StandardEditi<strong>on</strong>* Windows <strong>Server</strong>2003 EnterpriseEditi<strong>on</strong>* Windows <strong>Server</strong>2003 DatacenterEditi<strong>on</strong>* Up <strong>to</strong> 4processors* Up <strong>to</strong> 2 GB ofmemory* Maximumdatabase size of1,048,516 TBFor a detailed preview of all the <strong>SQL</strong> <strong>Server</strong> features and supporting <strong>to</strong>ols, refer <strong>to</strong>http://www.microsoft.com/sql/evaluati<strong>on</strong>/features/byfuncti<strong>on</strong>/default.asp.For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> features by editi<strong>on</strong>, refer <strong>to</strong>http://www.microsoft.com/sql/evaluati<strong>on</strong>/features/choosing.asp.While migrating <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the choice of editi<strong>on</strong> of <strong>SQL</strong> <strong>Server</strong> that is required <strong>to</strong>support the demands <strong>on</strong> the database has <strong>to</strong> be validated. Refer <strong>to</strong> the followingresource <str<strong>on</strong>g>for</str<strong>on</strong>g> a whitepaper that can aid in choosing the appropriate editi<strong>on</strong> of <strong>SQL</strong> <strong>Server</strong>:http://www.microsoft.com/sql/techinfo/planning/<strong>SQL</strong>ReskChooseEd.asp.


52Planning PhaseWindows <strong>Server</strong> 2003Windows <strong>Server</strong> 2003 is available in the following editi<strong>on</strong>s:●●●●Windows <strong>Server</strong> 2003, Standard Editi<strong>on</strong>. For departmental and standard corporateworkloads.Windows <strong>Server</strong> 2003, Enterprise Editi<strong>on</strong>. For critical or heavy server workloads.Windows <strong>Server</strong> 2003, Datacenter Editi<strong>on</strong>. For high levels of scalability andreliability.Windows <strong>Server</strong> 2003, Web Editi<strong>on</strong>. For Web serving and hosting.The goals of the Windows <strong>Server</strong> System are <strong>to</strong> promote operati<strong>on</strong>al efficiencies throughsimplified deployment, management, and security; <strong>to</strong> ensure high levels of dependability,per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, and productivity <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong> development; and <strong>to</strong> seamlessly c<strong>on</strong>nectin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, people, and systems.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the different editi<strong>on</strong>s of Windows <strong>Server</strong> 2003, refer <strong>to</strong>http://www.microsoft.com/windowsserver2003/evaluati<strong>on</strong>/features/compareediti<strong>on</strong>s.mspx.Technical Proof of C<strong>on</strong>ceptAfter validating the technologies, the team creates a pro<strong>to</strong>type project using a smalldatabase that c<strong>on</strong>tains a representative sample of the data, tables, and other objectsfound in the producti<strong>on</strong> databases. This process will validate the approach <str<strong>on</strong>g>for</str<strong>on</strong>g> themigrati<strong>on</strong> and provide useful experience when using the various <strong>to</strong>ols that have beenselected.This pro<strong>to</strong>type can also be used as a basis <str<strong>on</strong>g>for</str<strong>on</strong>g> a proof of c<strong>on</strong>cept, and ultimately thedevelopment of the soluti<strong>on</strong> itself. This initial proof-of-c<strong>on</strong>cept model often produces bothanswers and additi<strong>on</strong>al questi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> the team. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> helps in the riskmanagement process and identifies changes needed <strong>to</strong> the overall design that must beincorporated in<strong>to</strong> the specificati<strong>on</strong>s.Here are some candidates <str<strong>on</strong>g>for</str<strong>on</strong>g> the proof of c<strong>on</strong>cept that are typically part of this type ofmigrati<strong>on</strong>:● Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of binary large objects (BLOB) in s<strong>to</strong>ring, accessing, and updatingbased <strong>on</strong> differences in their s<strong>to</strong>rage architecture between <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.● Migrati<strong>on</strong> of sequences. Sequences are not supported by <strong>SQL</strong> <strong>Server</strong>, but thefuncti<strong>on</strong>ality can be duplicated.● Replacing reverse key indexes in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> with regular indexes in <strong>SQL</strong> <strong>Server</strong>.● C<strong>on</strong>verting <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> packages <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> s<strong>to</strong>red procedures.● Recreating <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s profiles (resource and password) functi<strong>on</strong>ality using Windowssecurity.● Developing Windows auditing functi<strong>on</strong>s <strong>to</strong> replace specific <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> functi<strong>on</strong>ality(sessi<strong>on</strong>, privilege, and object auditing).


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 53Develop the Project PlansThe soluti<strong>on</strong> design that was created in the Envisi<strong>on</strong>ing Phase is used as the baselinewhile creating the project plan. The project plan also needs <strong>to</strong> c<strong>on</strong>sider the key successcriteria identified in Chapter 2, "Envisi<strong>on</strong>ing Phase." The project plans include:● Development plan● Stabilizati<strong>on</strong> plan (includes test plan and pilot plan)● Deployment plan● Operati<strong>on</strong>s plan● Budget plan● Training planIn additi<strong>on</strong> <strong>to</strong> the above plans, a training checklist needs <strong>to</strong> be created that will identifythe existing and required skills. This will help you <strong>to</strong> plan the training that needs <strong>to</strong> beprovided when you do the work described in Chapter 20, "Operati<strong>on</strong>s."The development plan, test plan, and deployment plan are covered in detail under thefollowing headings.Development PlanThe development plan describes different aspects of the development endeavor, such as<strong>to</strong>ols required, methodologies and practices <strong>to</strong> be followed, schedule of events, andresources. The primary tasks of the development plan include:● Defining team roles● Identifying team, hardware, and software resources● Providing training <strong>to</strong> the team membersRefer <strong>to</strong> the development plan template provided with this soluti<strong>on</strong> <strong>to</strong> assist in creatingyour development plan.In general, it is recommended that the elements described in the following secti<strong>on</strong>s beincluded in a development plan.Development ObjectivesThese define the primary drivers that were used <strong>to</strong> create the development approach andthe key objectives of that approach. The development objectives <str<strong>on</strong>g>for</str<strong>on</strong>g> a migrati<strong>on</strong> projectdiffer from that of a new development. Most comm<strong>on</strong>ly, the key objectives are <strong>to</strong>:● Migrate the applicati<strong>on</strong> with the least amount of change.● Create a <strong>SQL</strong> <strong>Server</strong> database which is almost identical in design andimplementati<strong>on</strong> <strong>to</strong> the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.● Migrate the entire soluti<strong>on</strong> <strong>to</strong> a Windows and <strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ment with theleast amount of change.Migrati<strong>on</strong> ListThis provides a detailed listing of the applicati<strong>on</strong>s and databases that need <strong>to</strong> bemigrated as part of the current project.


54Planning PhaseOverall Delivery StrategyThis describes the overall approach <strong>to</strong> delivering the soluti<strong>on</strong>. Examples of deliverystrategy include staged delivery, depth-first, breadth-first, and features-then-per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.In migrati<strong>on</strong>s, the soluti<strong>on</strong> already exists and the delivery strategy c<strong>on</strong>sists of deployingthe replacement soluti<strong>on</strong>.Tradeoff ApproachThis defines the approach <str<strong>on</strong>g>for</str<strong>on</strong>g> making design and implementati<strong>on</strong> tradeoff decisi<strong>on</strong>s. Forexample, you might agree <strong>to</strong> trade features <str<strong>on</strong>g>for</str<strong>on</strong>g> schedule improvements, or <strong>to</strong> tradefeatures <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.Key Design GoalsThese identify the key design goals and the priority of each goal. Examples of designgoals in a migrati<strong>on</strong> include interoperability between a <strong>UNIX</strong> applicati<strong>on</strong> and the<strong>SQL</strong> <strong>Server</strong> database or rewriting the applicati<strong>on</strong> using the .NET framework.Development and Build Envir<strong>on</strong>mentThis describes the development and build envir<strong>on</strong>ment and how it will be managed.Include in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> items such as source code c<strong>on</strong>trol <strong>to</strong>ols, design <strong>to</strong>ol requirements,operating systems, or other software installed. If a development envir<strong>on</strong>ment <str<strong>on</strong>g>for</str<strong>on</strong>g> theexisting applicati<strong>on</strong> does not exist, it will need <strong>to</strong> be created. This situati<strong>on</strong> is comm<strong>on</strong>when the development of the applicati<strong>on</strong>s <strong>to</strong> be migrated was originally outsourced.Development ToolsThese <strong>to</strong>ols are used <strong>to</strong> assist in the development and test envir<strong>on</strong>ments. For a detaileddiscussi<strong>on</strong> of <strong>to</strong>ols, see the "Set Up the Development and Test Envir<strong>on</strong>ment" secti<strong>on</strong>later in this chapter.<str<strong>on</strong>g>Guide</str<strong>on</strong>g>lines and StandardsThese list and provide references <strong>to</strong> all standards and guidelines <strong>to</strong> be used <str<strong>on</strong>g>for</str<strong>on</strong>g> theproject. Standards and best practices could differ substantially from the current<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>/<strong>UNIX</strong> envir<strong>on</strong>ment. However, applying new standards will require a tremendousrewrite, which could greatly affect the migrati<strong>on</strong> timeline. It is recommended that suchstandards be applied <strong>on</strong>ly <strong>to</strong> the comp<strong>on</strong>ents that are being rewritten or modified.Versi<strong>on</strong>ing and Source C<strong>on</strong>trolThis describes how versi<strong>on</strong>ing and source c<strong>on</strong>trol will be managed. This secti<strong>on</strong> includesidentificati<strong>on</strong> of the specific <strong>to</strong>ols that will be used and how developers are expected <strong>to</strong>use them. Most source c<strong>on</strong>trol <strong>to</strong>ols work with code irrespective of plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Due <strong>to</strong> thechange in operating systems, new software may need <strong>to</strong> be acquired. For instance, ifCVS or any other source c<strong>on</strong>trol software is currently used in the <strong>UNIX</strong> envir<strong>on</strong>ment,c<strong>on</strong>siderati<strong>on</strong> should be given <strong>to</strong> migrating these functi<strong>on</strong>s <strong>to</strong> a Windows-basedalternative, such as Visual Source Safe.Build ProcessThis describes the incremental and iterative approach <str<strong>on</strong>g>for</str<strong>on</strong>g> developing code and <str<strong>on</strong>g>for</str<strong>on</strong>g> buildsof hardware and software comp<strong>on</strong>ents. It also describes how the build process will beimplemented and how often it will be implemented.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 55Comp<strong>on</strong>entsThis provides a high-level descripti<strong>on</strong> of the set of soluti<strong>on</strong> comp<strong>on</strong>ents and how they willbe migrated. In a migrati<strong>on</strong> project, most of the soluti<strong>on</strong> comp<strong>on</strong>ents should already exist.C<strong>on</strong>figurati<strong>on</strong> and Development Management ToolsThis identifies all the development <strong>to</strong>ols the team will use during the project. This includes<strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> all steps in the project: development, testing, documentati<strong>on</strong>, support,operati<strong>on</strong>s, and deployment.Design PatternsThis identifies the design patterns or templates that the team will use <str<strong>on</strong>g>for</str<strong>on</strong>g> this project andtheir sources. The team can acquire design patterns from both external and internalsources or create new design patterns. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> will <strong>on</strong>ly be necessary indevelopment plans that involve rewriting the applicati<strong>on</strong>.Development Team TrainingThis identifies the training necessary <strong>to</strong> ensure that the development team willsuccessfully develop the soluti<strong>on</strong>. This is a critical necessity in migrati<strong>on</strong>s because it isnot comm<strong>on</strong> <strong>to</strong> already have pers<strong>on</strong>nel in place that can adequately support both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>and <strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ments.Development Team SupportThis identifies the various types of support the development team will require, thesources of that support, the amount of support of each type that the team will require, andthe estimated schedule <str<strong>on</strong>g>for</str<strong>on</strong>g> support. Support may not exist <str<strong>on</strong>g>for</str<strong>on</strong>g> the target Windowsenvir<strong>on</strong>ment, and may need <strong>to</strong> be developed.Stabilizing Phase PlansDuring the Stabilizing Phase, the testing team c<strong>on</strong>ducts tests <strong>on</strong> a soluti<strong>on</strong> whosefeatures are complete. Testing during this phase emphasizes usage and operati<strong>on</strong> underrealistic envir<strong>on</strong>mental c<strong>on</strong>diti<strong>on</strong>s. The team focuses <strong>on</strong> resolving and prioritizing bugsand preparing the soluti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> release.During the Planning Phase, the team typically creates the following plans that will beused during the Stabilizing Phase:● The test plan● The pilot planTest PlanThe test plan describes the strategy and approach used <strong>to</strong> plan, organize, and managethe project’s testing activities. It identifies testing objectives, methodologies and <strong>to</strong>ols,expected results, resp<strong>on</strong>sibilities, and resource requirements. This document is theprimary plan <str<strong>on</strong>g>for</str<strong>on</strong>g> the testing team. A test plan ensures that the testing process will bec<strong>on</strong>ducted in a thorough and organized manner and will enable the team <strong>to</strong> determine thestability of the soluti<strong>on</strong>. A c<strong>on</strong>tinuous understanding of the soluti<strong>on</strong>’s status buildsc<strong>on</strong>fidence in team members and stakeholders as the soluti<strong>on</strong> is developed andstabilized.The Test Role in the MSF Team Model is resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> creating the test plan. This teamis also resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> setting the quality expectati<strong>on</strong>s and incorporating them in<strong>to</strong> the


56Planning Phasetesting plan. This template is available in the Tools and Templates folder in the zip filedownload of this guidance at http://go.microsoft.com/fwlink/?LinkId=45289.The key secti<strong>on</strong>s of a test plan include:Forms of Testing <strong>to</strong> Be Per<str<strong>on</strong>g>for</str<strong>on</strong>g>medThese include:● Code comp<strong>on</strong>ent testingIn a migrati<strong>on</strong>, the scope of changes made <strong>to</strong> the existing applicati<strong>on</strong> varies fromminor c<strong>on</strong>necti<strong>on</strong> string changes <strong>to</strong> a complete applicati<strong>on</strong> rewrite. The goal oftesting is <strong>to</strong> ensure that any comp<strong>on</strong>ent modified matches the original features andfuncti<strong>on</strong>ality. Instead of basing the test results <strong>on</strong> a series of requirements, theexisting applicati<strong>on</strong> can be used as a basis <str<strong>on</strong>g>for</str<strong>on</strong>g> comparis<strong>on</strong>.● Database testingThis includes:● Physical architecture of database. Have the data files, transacti<strong>on</strong> logs, andother comp<strong>on</strong>ents that comprise the database been created correctly?● Logical architecture of the database. Have the tables, views, s<strong>to</strong>redprocedures, triggers, and other database objects been created successfully?● Data. Have the c<strong>on</strong>tents of the tables been transferred correctly? Do tablesc<strong>on</strong>tain the correct number of rows? Is the data valid?● Functi<strong>on</strong>ality. Do the s<strong>to</strong>red procedures, triggers, views, and other itemscomprising T-<strong>SQL</strong> code operate in the same manner as the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>objects?● Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. Do the resp<strong>on</strong>se times and throughput meet requirements andmatch user expectati<strong>on</strong>s?●●●●●Infrastructure testingInfrastructure testing ncludes the development and producti<strong>on</strong> envir<strong>on</strong>ments, aswell as hardware, software, m<strong>on</strong>i<strong>to</strong>ring software, network, backup strategies, anddisaster recovery plans.Security testingThere are two levels of security testing, network level and applicati<strong>on</strong> level, thatshould be tested:● <strong>Net</strong>work level. Test access and privileges● Applicati<strong>on</strong> level. Ensure that the correct users and permissi<strong>on</strong> levels exist inthe applicati<strong>on</strong> and database.Integrati<strong>on</strong> testingIf the soluti<strong>on</strong> is deployed in phases, then test the integrati<strong>on</strong> of each phase. Eachincarnati<strong>on</strong> needs <strong>to</strong> be tested <str<strong>on</strong>g>for</str<strong>on</strong>g> acceptable integrati<strong>on</strong> with other comp<strong>on</strong>ents.User acceptance and usability testingThese tests can often be recreated from the original design soluti<strong>on</strong>. The migrati<strong>on</strong>should meet the same goals as the existing soluti<strong>on</strong>. Any new or modifiedfuncti<strong>on</strong>ality should also be tested.Stress, capacity, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testingThese tests are important because the migrated soluti<strong>on</strong> will reside in a newenvir<strong>on</strong>ment. The hardware, operating systems, and software will be very differentthan the existing soluti<strong>on</strong>. Complete testing should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong> the soluti<strong>on</strong>.Stress testing can also be used <strong>to</strong> check database coexistence issues that mayoccur when there is a heavy load <strong>on</strong> the system.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 57●Regressi<strong>on</strong> testingTo ensure that the soluti<strong>on</strong> functi<strong>on</strong>s correctly while bugs are being corrected, aset of test cases should be available that can be executed as a regressi<strong>on</strong> test.Each time the test is run, the results should be logged and compared with theexpected results. Testing per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong> the original soluti<strong>on</strong> can be reused in mostscenarios. Using the same data, test cases should per<str<strong>on</strong>g>for</str<strong>on</strong>g>m identically between theexisting soluti<strong>on</strong> and the new soluti<strong>on</strong> being tested.Test Approach and Assumpti<strong>on</strong>sDescribe at a high level the approach, activities, and techniques <strong>to</strong> be followed in testingthe soluti<strong>on</strong>. If different approaches are required <str<strong>on</strong>g>for</str<strong>on</strong>g> the soluti<strong>on</strong>’s various comp<strong>on</strong>ents,you need <strong>to</strong> specify which comp<strong>on</strong>ents will be tested by which approach. This approachis relevant <strong>to</strong> migrati<strong>on</strong>s, as not all comp<strong>on</strong>ents will have the same amount of change ortrans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. The test approach should be tempered based <strong>on</strong> the amount of change.Major Test Resp<strong>on</strong>sibilitiesIdentify the teams and individuals who will manage and implement the testing process.Features and Functi<strong>on</strong>ality <strong>to</strong> TestIdentify at a high level all features and functi<strong>on</strong>ality that will be tested. Per<str<strong>on</strong>g>for</str<strong>on</strong>g>m thefollowing tasks <strong>on</strong> the most comm<strong>on</strong> problem areas in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> migrati<strong>on</strong>project:● Ensure that the <strong>SQL</strong> <strong>Server</strong> editi<strong>on</strong> acquired meets applicati<strong>on</strong> requirements. Formore in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, see the "Validate the Technology" secti<strong>on</strong> in this chapter.● Verify that the database architecture follows best practices and will meetper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance goals.● Ensure functi<strong>on</strong>s that have moved from the database in<strong>to</strong> the applicati<strong>on</strong> (and viceversa) during the migrati<strong>on</strong> are properly documented and tested.● Check any table design changes due <strong>to</strong> restricti<strong>on</strong>s <strong>on</strong> <strong>SQL</strong> <strong>Server</strong> row size.● Test triggers that have been c<strong>on</strong>verted from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.Items <strong>to</strong> include when testing applicati<strong>on</strong> migrati<strong>on</strong> include:● Code changes● Security requirements● User c<strong>on</strong>nectivity and remote access● C<strong>on</strong>necti<strong>on</strong> string changes● Functi<strong>on</strong>ality changes. C<strong>on</strong>sider both applicati<strong>on</strong> and database <str<strong>on</strong>g>for</str<strong>on</strong>g> specific items.Some database items will affect the applicati<strong>on</strong>.Type of Required HardwareThe type of hardware <str<strong>on</strong>g>for</str<strong>on</strong>g> the test setup should closely resemble the architecture that isproposed <str<strong>on</strong>g>for</str<strong>on</strong>g> the producti<strong>on</strong> envir<strong>on</strong>ment. The availability of hardware may depend <strong>on</strong> itstype, its cost, and any other envir<strong>on</strong>mental fac<strong>to</strong>rs that need <strong>to</strong> be c<strong>on</strong>sidered at thelocati<strong>on</strong> of the test setup. In situati<strong>on</strong>s where data does not exist <strong>to</strong> make a decisi<strong>on</strong> <strong>on</strong>the producti<strong>on</strong> data, the test envir<strong>on</strong>ment has <strong>to</strong> be planned <strong>to</strong> capture such in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.In some situati<strong>on</strong>s, using virtual machine software (such as Microsoft Virtual <strong>Server</strong>2003) <strong>to</strong> recreate test envir<strong>on</strong>ments and per<str<strong>on</strong>g>for</str<strong>on</strong>g>m software testing is cost-effective.


58Planning PhaseLocati<strong>on</strong> of Test SetupDecide <strong>on</strong> the locati<strong>on</strong> of the test setup. If development, testing, and producti<strong>on</strong> are inphysically distant (possibly offshore) locati<strong>on</strong>s, then decisi<strong>on</strong>s have <strong>to</strong> be made <strong>on</strong> how <strong>to</strong>set up the envir<strong>on</strong>ments <str<strong>on</strong>g>for</str<strong>on</strong>g> optimal per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance <str<strong>on</strong>g>for</str<strong>on</strong>g> each group. For example, if the testand producti<strong>on</strong> locati<strong>on</strong>s are far apart, creating copies of a large producti<strong>on</strong> databaseacross a WAN can be an issue. Also, the test envir<strong>on</strong>ment should be isolated and shouldnot interfere with any producti<strong>on</strong> activity.Resources RequiredProvide <str<strong>on</strong>g>for</str<strong>on</strong>g> the different equipment required <str<strong>on</strong>g>for</str<strong>on</strong>g> the setup, such as power points; racks orstands; s<strong>to</strong>rage media, such as disks; and a backup system. Software, services, and<strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> the test envir<strong>on</strong>ment have <strong>to</strong> be procured and set up as per the instructi<strong>on</strong>sprovided by the test team.Expected Results of TestsDescribe the results that should be dem<strong>on</strong>strated by the tests. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> includesexpectati<strong>on</strong>s of both the soluti<strong>on</strong> team and the testers. This secti<strong>on</strong> also defines whetherthe results must be exactly as anticipated or whether a range of results is acceptable.The expected results originate from the existing soluti<strong>on</strong>. The migrated soluti<strong>on</strong> shouldper<str<strong>on</strong>g>for</str<strong>on</strong>g>m the same or better than the original system.DeliverablesDescribe the materials that must be made available or created <strong>to</strong> aid in c<strong>on</strong>ducting thetests and <str<strong>on</strong>g>for</str<strong>on</strong>g> presenting test results. In many migrati<strong>on</strong> situati<strong>on</strong>s, existing test scripts canbe reused.Testing procedures and walk-throughDescribe the steps the testing team will per<str<strong>on</strong>g>for</str<strong>on</strong>g>m <strong>to</strong> ensure quality tests.Tracking and Reporting StatusDefine the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> that test team members will communicate during the testingprocess. This secti<strong>on</strong> defines the specific test status in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> that will be created anddistributed. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> normally includes status in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> each test case andthe probability of completing the test cycle <strong>on</strong> schedule.Bug Reporting Tools and MethodsDescribe the overall bug reporting strategy and methodology. This secti<strong>on</strong> also defineswhat will qualify as a bug in the code, product features, and documentati<strong>on</strong>.SchedulesIdentify the major test cycles, tasks, milest<strong>on</strong>es, and deliverables. This secti<strong>on</strong> alsodescribes who is resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> each test cycle and its tasks. In additi<strong>on</strong>, it identifies theexpected start and completi<strong>on</strong> date <str<strong>on</strong>g>for</str<strong>on</strong>g> each test cycle and the tasks within that cycle.When planning <str<strong>on</strong>g>for</str<strong>on</strong>g> test cases, identify the secti<strong>on</strong>s of code that have changed duringmigrati<strong>on</strong> and identify the functi<strong>on</strong>ality provided.Create test cases based <strong>on</strong> these functi<strong>on</strong>ality changes. When changes are minimal,such as a Java applicati<strong>on</strong> that <strong>on</strong>ly requires the database c<strong>on</strong>necti<strong>on</strong> string <strong>to</strong> bemodified, the test case should ensure that the applicati<strong>on</strong> is c<strong>on</strong>necting properly <strong>to</strong> the


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 59<strong>SQL</strong> <strong>Server</strong> database. In most migrati<strong>on</strong>s, updates <strong>to</strong> c<strong>on</strong>nectivity and APIs represent amajority of the changes.In situati<strong>on</strong>s where the APIs have been changed, test cases should be created <strong>to</strong> test thiscomp<strong>on</strong>ent change. These cases should test database queries and updates per<str<strong>on</strong>g>for</str<strong>on</strong>g>medby the applicati<strong>on</strong> <strong>to</strong> ensure that results are as expected. Gather various scenarios ofusability and user interacti<strong>on</strong> and repeat <str<strong>on</strong>g>for</str<strong>on</strong>g> each comp<strong>on</strong>ent. Query results anddatabase updates can be checked against the same functi<strong>on</strong>ality in the existing soluti<strong>on</strong>.Refer <strong>to</strong> the test plan template <strong>to</strong> assist in creating your test plan. This template isavailable in the Tools and Templates folder in the zip file download of this guidance athttp://go.microsoft.com/fwlink/?LinkId=45289.Pilot PlanThe pilot plan describes how the team will move the candidate release versi<strong>on</strong> of thesoluti<strong>on</strong> <strong>to</strong> a staging area and test it. The goal of the pilot is <strong>to</strong> simulate the equipment,software, and comp<strong>on</strong>ents that the soluti<strong>on</strong> will use when it is active. This plan alsoidentifies how issues discovered during the pilot will be solved. The pilot plan includesdetails about how <strong>to</strong> evaluate the pilot; the results of the evaluati<strong>on</strong> will facilitate adecisi<strong>on</strong> whether <strong>to</strong> move the soluti<strong>on</strong> <strong>to</strong> producti<strong>on</strong>.Project teams often c<strong>on</strong>duct <strong>on</strong>e or more pilots <strong>to</strong> prove the feasibility of soluti<strong>on</strong>approaches, <strong>to</strong> experiment with different soluti<strong>on</strong>s, and <strong>to</strong> obtain user feedback andacceptance of proposed soluti<strong>on</strong>s. Pilot soluti<strong>on</strong>s implement <strong>on</strong>ly those subsets orsegments of requirements of the functi<strong>on</strong>al specificati<strong>on</strong> that are necessary <strong>to</strong> validatethe soluti<strong>on</strong>.Note Some projects may not require c<strong>on</strong>ducting a pilot. For example, if there are fewchanges <strong>to</strong> an applicati<strong>on</strong>, the c<strong>on</strong>sensus may be not <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m a pilot program.However, even in situati<strong>on</strong>s where an applicati<strong>on</strong> is ported, it is important <strong>to</strong> rememberthat the soluti<strong>on</strong> include the applicati<strong>on</strong> and the new <strong>SQL</strong> <strong>Server</strong> database back end.Because the back end database, envir<strong>on</strong>ment, and plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m will change in the newsoluti<strong>on</strong>, a pilot is recommended <str<strong>on</strong>g>for</str<strong>on</strong>g> highly critical applicati<strong>on</strong>s. Pilots are alsorecommended <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong>s where specific per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance criteria, such as resp<strong>on</strong>setimes or throughput, must be met. Pilot programs can also be useful in situati<strong>on</strong>s wherethere is a redesign in the migrati<strong>on</strong> and the comp<strong>on</strong>ents work differently <strong>on</strong> the newplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.In additi<strong>on</strong>, piloting can provide operati<strong>on</strong>al and deployment pers<strong>on</strong>nel practicalexperience with new technologies and can benefit the actual deployment schedule andoperati<strong>on</strong>al transiti<strong>on</strong> schedules.The pilot plan provides the means <strong>to</strong> validate the business requirements and thetechnical specificati<strong>on</strong> prior <strong>to</strong> deploying the soluti<strong>on</strong> in<strong>to</strong> producti<strong>on</strong>. Planning the detailsof the pilot ensures that the participating project teams identify their roles, resp<strong>on</strong>sibilities,and resource requirements specific <strong>to</strong> pilot development, testing, and deploymentactivities.Refer <strong>to</strong> the pilot plan template <str<strong>on</strong>g>for</str<strong>on</strong>g> assistance in creating your pilot plan. This template isavailable in the Tools and Templates folder in the zip file download of this guidance athttp://go.microsoft.com/fwlink/?LinkId=45289.


60Planning PhaseDeployment PlanDuring the Deploying Phase, the team deploys the soluti<strong>on</strong> technology and comp<strong>on</strong>ents,stabilizes the deployment, transiti<strong>on</strong>s the project <strong>to</strong> operati<strong>on</strong>s and support, and obtainsfinal cus<strong>to</strong>mer approval of the project. Planning <str<strong>on</strong>g>for</str<strong>on</strong>g> deployment starts in the PlanningPhase by developing a detailed deployment plan. This plan should be developed by theRelease Management Role with assistance from the rest of the team. See thedeployment plan template in the Tools and Templates folder in the zip file download ofthis guidance at http://go.microsoft.com/fwlink/?LinkId=45289.Key elements of the deployment plan are described in the following secti<strong>on</strong>s.Deployment ScopeThis secti<strong>on</strong> describes the soluti<strong>on</strong> architecture and scale of deployment. Thedeployment team needs <strong>to</strong> c<strong>on</strong>sider deployment of the database, server, and the clientapplicati<strong>on</strong>s. Each has its own challenges that require a different process and set of<strong>to</strong>ols.● Seats. This describes the magnitude of the deployment in terms of sites, numberof workstati<strong>on</strong>s, countries and regi<strong>on</strong>s, and other relevant size fac<strong>to</strong>rs.● Comp<strong>on</strong>ents. This lists and describes the comp<strong>on</strong>ents <strong>to</strong> be deployed and anycritical dependencies am<strong>on</strong>g them.● Architecture. This describes the soluti<strong>on</strong>’s architecture and how it might affectdeployment.Deployment ToolsThe database and server deployment will often be <strong>on</strong> <strong>on</strong>e or a few machines. They canbe deployed manually. However, the clients may have <strong>to</strong> be deployed over hundreds ofcomputers across the corporate network. This may require the need <str<strong>on</strong>g>for</str<strong>on</strong>g> softwaredistributi<strong>on</strong> and deployment <strong>to</strong>ols. These <strong>to</strong>ols are discussed in the "Deploying the ClientApplicati<strong>on</strong>" secti<strong>on</strong> in Chapter 19, "Deploying Phase."BackupsBacking up of the soluti<strong>on</strong> and the source c<strong>on</strong>trol of scripts must be carried out. Theitems that need <strong>to</strong> be backed up <str<strong>on</strong>g>for</str<strong>on</strong>g> which you need <strong>to</strong> plan include a snapshot of thesource code of the existing soluti<strong>on</strong> and the migrated soluti<strong>on</strong>. Include the versi<strong>on</strong>in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> and build in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.This ensures that the envir<strong>on</strong>ment can be recreated later, if required. It also aids duringproblems, especially when a fallback is implemented. In a phased migrati<strong>on</strong>, backups ofthe source should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med between phases, as well as any other critical junctures,as deemed necessary. If a partial rollback is needed, backups can save time.Deployment ScheduleThis identifies the critical dates and anticipated schedule <str<strong>on</strong>g>for</str<strong>on</strong>g> the Deploying Phase.Deployment ResourcesThis identifies the work<str<strong>on</strong>g>for</str<strong>on</strong>g>ce that will be needed <strong>to</strong> complete the deployment and thesources of the pers<strong>on</strong>nel.<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> SupportThis describes how the users will be supported during the deployment.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 61●●●●Help desk. This describes the support provided <strong>to</strong> users and applicati<strong>on</strong>s by thehelp desk team, including support <str<strong>on</strong>g>for</str<strong>on</strong>g> direct user questi<strong>on</strong>s and applicati<strong>on</strong> issues,and also in-depth support <str<strong>on</strong>g>for</str<strong>on</strong>g> new or difficult issues.Desk<strong>to</strong>p. This describes any changes in current workstati<strong>on</strong> applicati<strong>on</strong> supportthat might be required during deployment.<strong>Server</strong>s. This describes any changes in current server support that might berequired during deployment.Telecommunicati<strong>on</strong>s. This describes any changes in current telecommunicati<strong>on</strong>support that might be required during deployment.Coordinati<strong>on</strong> of TrainingThis describes how end-user and support staff training is coordinated with thedeployment schedule.Communicati<strong>on</strong>The necessary in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, such as the dates <str<strong>on</strong>g>for</str<strong>on</strong>g> deploying and completing the migrati<strong>on</strong>must be communicated <strong>to</strong> the cus<strong>to</strong>mers and all those who may directly or indirectly beaffected by the migrati<strong>on</strong>. The deployment plan should be made available <strong>to</strong> the entireteam so that each pers<strong>on</strong> is well in<str<strong>on</strong>g>for</str<strong>on</strong>g>med of what acti<strong>on</strong>s they are resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> andwhen it should occur. This is especially critical in large migrati<strong>on</strong>s that have <strong>to</strong> beundertaken over a grueling schedule, such as a weekend.Work SchedulesTo prevent the business operati<strong>on</strong>s from being affected by the deployment, workschedules should be set accordingly. The work schedules should c<strong>on</strong>sider training theoperati<strong>on</strong>s pers<strong>on</strong>nel and end users.Resource AvailabilityThe resources in the producti<strong>on</strong> envir<strong>on</strong>ment should be prepared <str<strong>on</strong>g>for</str<strong>on</strong>g> the soluti<strong>on</strong>deployment. The infrastructure, servers, and workstati<strong>on</strong>s should be prepared <str<strong>on</strong>g>for</str<strong>on</strong>g> thedeployment. The necessary installati<strong>on</strong> files should be ready <strong>to</strong> c<strong>on</strong>duct a smooth andtimely deployment. Spare disk drives, cables, network cards, power points, stands, andbackup power supply should be made available in case of failure in hardware during thedeployment. In many instances, such precauti<strong>on</strong>s are not taken until a soluti<strong>on</strong> is alreadydeployed. Hence it is important <strong>to</strong> produce a plan <strong>to</strong> capture all these tasks.● Assembling the team. The rollout team should be assembled and the training <strong>to</strong>per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the deployment should be provided. The rollout team members could befrom the project team, but the team should also include members from theoperati<strong>on</strong>s staff because they need <strong>to</strong> develop a thorough knowledge of thefuncti<strong>on</strong>ing of the soluti<strong>on</strong>. Alternate team members should also be selected <strong>to</strong>prepare <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>tingencies.● Training the team. The deployment team should be given the necessary trainingand privileges <strong>to</strong> overcome the difficulties that could arise during the rollout. Thedifferent installati<strong>on</strong> manuals and documentati<strong>on</strong> should be provided <strong>to</strong> the rolloutteam. A special help desk should be set up <str<strong>on</strong>g>for</str<strong>on</strong>g> the users and the rollout team <strong>to</strong>revert <strong>to</strong> while deploying the soluti<strong>on</strong>.● Documenting unplanned procedures. During the rollout, some procedures mayhave been implemented which were a part of the rollout plan. The deploymentteam may need these procedures <strong>to</strong> stabilize the deployment or correctun<str<strong>on</strong>g>for</str<strong>on</strong>g>eseen situati<strong>on</strong>s created due <strong>to</strong> the executi<strong>on</strong> of unplanned procedures.


62Planning PhaseThese emergency procedures should be documented and include the cause andeffect of the procedure adopted.Because there are risks involved, the risk management plan has <strong>to</strong> be reviewedand updated. The risk management template is available in the Tools andTemplates folder in the zip file download of this guidance athttp://go.microsoft.com/fwlink/?LinkId=45289.Deployment StrategiesThe main strategies that need <strong>to</strong> be c<strong>on</strong>sidered <str<strong>on</strong>g>for</str<strong>on</strong>g> deployment include:● Cu<strong>to</strong>ver strategy. The critical area in a migrati<strong>on</strong> project where the existingsystem is shut down and the new system is ready <strong>to</strong> be implemented in theproducti<strong>on</strong> envir<strong>on</strong>ment. The cu<strong>to</strong>ver strategy focuses <strong>on</strong> the tasks, activities, andtime required during the final days of the project. The cu<strong>to</strong>ver strategies availableare:● Straight cu<strong>to</strong>ver. This strategy enables migrati<strong>on</strong> of the database from <strong>on</strong>eenvir<strong>on</strong>ment <strong>to</strong> another without taking any intermediary steps. This opti<strong>on</strong> isused when downtime does not limit the migrati<strong>on</strong>, and the migrated databasedoes not c<strong>on</strong>tain critical in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.● Parallel cu<strong>to</strong>ver. Replicati<strong>on</strong> is a strategy that is used by organizati<strong>on</strong>s that d<strong>on</strong>ot have the adequate downtime required <strong>to</strong> build and migrate a database. Adatabase is created in the new envir<strong>on</strong>ment and data is migrated <strong>on</strong> ac<strong>on</strong>tinual basis. A process is put in place <strong>to</strong> replicate the current databasechanges in<strong>to</strong> the new database synchr<strong>on</strong>ously or asynchr<strong>on</strong>ously.● Serial cu<strong>to</strong>ver. This opti<strong>on</strong> enables the database <strong>to</strong> be migrated in phases.This approach is usually implemented when multiple databases need <strong>to</strong> bemigrated or data within the database is porti<strong>on</strong>ed based <strong>on</strong> business functi<strong>on</strong>s.The serial cu<strong>to</strong>ver strategy is difficult <strong>to</strong> implement when the database iscomplex and interdependent with other infrastructure elements.●●Phase-out strategies. In large, complex migrati<strong>on</strong>s, the soluti<strong>on</strong> is rolled out inphases. This enables the team <strong>to</strong> assess and reduce the business risks. Phasingout enables the deployment <strong>to</strong> take place in small and manageable parts. Thereare two types of phase-outs:● Vertical phase-out. In vertical phase-out, modules are rolled out <strong>on</strong>e at atime. This implies that both the source soluti<strong>on</strong> and the target soluti<strong>on</strong>interoperate. The advantage is that the soluti<strong>on</strong> is rolled out in manageableparts. The disadvantage is that data bridge programs between the twosoluti<strong>on</strong>s have <strong>to</strong> be deployed at each phase-out.● Horiz<strong>on</strong>tal phase-out. The horiz<strong>on</strong>tal phase-out covers the rolling out of thesoluti<strong>on</strong> in phases over the different geographical areas. While implementing ahoriz<strong>on</strong>tal phase-out, the differences in the envir<strong>on</strong>ment c<strong>on</strong>diti<strong>on</strong>s of thebusiness and applicati<strong>on</strong>s should be taken care of.Fallback strategies. A fallback is necessary if the migrati<strong>on</strong> encounters difficultiesor delays that impacts business. This could result due <strong>to</strong> the following reas<strong>on</strong>s:● Unfeasible migrati<strong>on</strong> strategy● Undocumented requirements or procedures● Insufficient testing● Disasters● Un<str<strong>on</strong>g>for</str<strong>on</strong>g>eseen situati<strong>on</strong>s


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 63Each phase and each acti<strong>on</strong> in the rollout has <strong>to</strong> be associated with an impact <strong>to</strong>determine if a fallback is required whenever that acti<strong>on</strong> cannot be successfullycompleted. Dependencies <str<strong>on</strong>g>for</str<strong>on</strong>g> every acti<strong>on</strong> should also be mapped <strong>to</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>esee theimpact <strong>on</strong> tasks further down the chain. Every precauti<strong>on</strong> <strong>to</strong> ensure that thefallback is successfully completed has <strong>to</strong> be undertaken. For example, in case of afallback, the licenses of the existing soluti<strong>on</strong> need <strong>to</strong> be still valid, and theencrypti<strong>on</strong> certificates need <strong>to</strong> be valid.A fallback plan should enable the soluti<strong>on</strong> <strong>to</strong> be rolled back <strong>to</strong> a c<strong>on</strong>sistent andstable state. Workaround strategies or c<strong>on</strong>tingency plans should be tried be<str<strong>on</strong>g>for</str<strong>on</strong>g>edeciding <strong>to</strong> fallback <strong>on</strong> the original database. The fallback strategies <strong>to</strong> beimplemented depend <strong>on</strong> the cu<strong>to</strong>ver strategies that are selected. The fallbackstrategy should accommodate <str<strong>on</strong>g>for</str<strong>on</strong>g> any transacti<strong>on</strong>s that were executed since thestart of deployment. To select the optimal fallback strategy, a list of the possiblefailures needs <strong>to</strong> be documented. The different fallback strategies available are:● Fallback after straight cu<strong>to</strong>ver. In case of a fallback in straight cu<strong>to</strong>ver, the<strong>UNIX</strong> envir<strong>on</strong>ment needs <strong>to</strong> be frozen at the time the cu<strong>to</strong>ver started. Thus, incase of a fallback, it is possible <strong>to</strong> restart the <strong>UNIX</strong> envir<strong>on</strong>ment with minimalef<str<strong>on</strong>g>for</str<strong>on</strong>g>t. A fallback may require re-establishment of broken sessi<strong>on</strong>s between thecus<strong>to</strong>mer computers and the database. To reduce downtime and rework,during the fallback, checkpoints have <strong>to</strong> be established be<str<strong>on</strong>g>for</str<strong>on</strong>g>e clients aremigrated. Also, a subset of clients should be cut over and tested be<str<strong>on</strong>g>for</str<strong>on</strong>g>e therest of the clients. In additi<strong>on</strong>, adequate time should be provided <str<strong>on</strong>g>for</str<strong>on</strong>g> a fallbackwith minimal user disturbance.● Fallback after parallel cu<strong>to</strong>ver. The fallback process involves reversing thedirecti<strong>on</strong> of replicati<strong>on</strong> that was used in the cu<strong>to</strong>ver, that is, <strong>SQL</strong> <strong>Server</strong> <strong>to</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database. C<strong>on</strong>sequently, the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database is updated <str<strong>on</strong>g>for</str<strong>on</strong>g> the periodof the cu<strong>to</strong>ver. The client side is the main technical area <strong>to</strong> be addressedduring the fallback. <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the clients in smaller batches can ease the painof reverting <strong>to</strong> the original envir<strong>on</strong>ment.● Fallback after serial cu<strong>to</strong>ver. The fallback is similar <strong>to</strong> that in a straightcu<strong>to</strong>ver, with the entire migrati<strong>on</strong> viewed as a collecti<strong>on</strong> of smaller cu<strong>to</strong>vers.The serial or phased cu<strong>to</strong>ver enables you <strong>to</strong> fallback <strong>to</strong> a previous c<strong>on</strong>sistentstate without having <strong>to</strong> undo all changes. You are also able <strong>to</strong> solve problemsin small increments.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> and assistance in developing your deployment plan, refer <strong>to</strong> thedeployment plan template.Create the Project SchedulesBased <strong>on</strong> the functi<strong>on</strong>al specificati<strong>on</strong> and the project plan, the team creates a projectschedule that defines the release date of the soluti<strong>on</strong>. The team may choose <strong>to</strong> divide theschedule functi<strong>on</strong>ally. For example, different sub test teams will work <strong>on</strong> testing differentfeatures of the soluti<strong>on</strong>. Each subteam will create its own schedule.A release date is decided after integrating the master project schedule with the schedulesfrom each team lead. A release date enables the team members <strong>to</strong> prioritize functi<strong>on</strong>s,assess risk, and plan effectively.Estimating the Ef<str<strong>on</strong>g>for</str<strong>on</strong>g>tAccording <strong>to</strong> the various functi<strong>on</strong>al comp<strong>on</strong>ents, each task is allotted <strong>to</strong> a team that isdeveloping the comp<strong>on</strong>ent. Each team prepares plans based <strong>on</strong> their role and


64Planning Phasedeliverables. Finally, all the plans are reviewed and dependencies between the plans areoutlined. These various plans are then merged in<strong>to</strong> a master project plan.Estimating the teams' ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t can be accomplished as follows:● Each team leader prioritizes the functi<strong>on</strong>s, roles, and resp<strong>on</strong>sibilities <str<strong>on</strong>g>for</str<strong>on</strong>g> the entireteam.● The team members are required <strong>to</strong> estimate their per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance <str<strong>on</strong>g>for</str<strong>on</strong>g> each taskassigned. The time given <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m an individual task should vary from <strong>on</strong>e halfday <strong>to</strong> <strong>on</strong>e week. If the time durati<strong>on</strong> estimated is short, then the overhead inmanaging the task may be <strong>to</strong>o high. If the time estimated is <strong>to</strong>o l<strong>on</strong>g, thenmanaging the scope of work becomes <strong>to</strong>o difficult.● Per<str<strong>on</strong>g>for</str<strong>on</strong>g>m bot<strong>to</strong>m-up estimating <strong>to</strong> create accurate schedules. This method enablesthe individual per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the task <strong>to</strong> estimate the time taken <strong>to</strong> complete it. Theestimate is usually based <strong>on</strong> the individual's experience of per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming a similartask. In additi<strong>on</strong>, individuals that estimate time plans <str<strong>on</strong>g>for</str<strong>on</strong>g> their work feel moreaccountable <str<strong>on</strong>g>for</str<strong>on</strong>g> their work schedules.● Implement risk-driven estimating, which enables the team members <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m thedifficult and highest risk tasks first. It permits individuals <strong>to</strong> minimize risk andprovides excess time <strong>to</strong> mitigate risk.When scheduling a migrati<strong>on</strong>, there are many time-related elements <strong>to</strong> c<strong>on</strong>sider. Forinstance, the development and test envir<strong>on</strong>ment need <strong>to</strong> be set up be<str<strong>on</strong>g>for</str<strong>on</strong>g>e starting theDeveloping Phase <strong>to</strong> maximize team productivity, mitigate risks, and avoid delays. It isalso recommended <strong>to</strong> migrate the database be<str<strong>on</strong>g>for</str<strong>on</strong>g>e migrating the applicati<strong>on</strong>. This is due<strong>to</strong> object-level differences between the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> databases that may need<strong>to</strong> be modified.Migrati<strong>on</strong> envir<strong>on</strong>ments also impact the schedule. For instance, projects that involveporting the applicati<strong>on</strong>, such as Java, can be accomplished relatively quickly. By c<strong>on</strong>trast,migrati<strong>on</strong> envir<strong>on</strong>ments that require rewriting the applicati<strong>on</strong>, such as <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms andPro*C, will need a l<strong>on</strong>ger development schedule. Also, it is more challenging <strong>to</strong> migratedata in OLTP envir<strong>on</strong>ments than in batch processing envir<strong>on</strong>ments.Skills can also affect the scheduling. In an optimal migrati<strong>on</strong>, a database administra<strong>to</strong>r <strong>on</strong>the team is skilled in both <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> envir<strong>on</strong>ments. If current databaseadministra<strong>to</strong>rs are <strong>on</strong>ly familiar with the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> envir<strong>on</strong>ment, extra time should be allowed<str<strong>on</strong>g>for</str<strong>on</strong>g> job training and skill acquisiti<strong>on</strong>. The same applies <strong>to</strong> applicati<strong>on</strong> developers. Inadditi<strong>on</strong>, pilot testing and migrating smaller applicati<strong>on</strong>s be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the main applicati<strong>on</strong> maybe beneficial <strong>to</strong> the project by providing the entire project team with experience that mayprove helpful while migrating the main applicati<strong>on</strong>.After you have defined a schedule, you can allocate resources <strong>to</strong> it. You should:● Update the project plan with detailed allocati<strong>on</strong> of resources.● Check and c<strong>on</strong>figure availability of resources, identifying any possible overuse ofresources.● Establish a baseline and track progress <strong>on</strong> tasks and budget.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 65Set Up the Development and Test Envir<strong>on</strong>mentsThe final tasks <str<strong>on</strong>g>for</str<strong>on</strong>g> the Planning Phase are setting up the development and testenvir<strong>on</strong>ments. Completing these tasks allow <str<strong>on</strong>g>for</str<strong>on</strong>g> a smooth transiti<strong>on</strong> in<strong>to</strong> the DevelopmentPhase.In many ways, the development and test envir<strong>on</strong>ments are similar. Both are modeled <strong>on</strong>the soluti<strong>on</strong> envir<strong>on</strong>ment, and both are used <strong>to</strong> refine the soluti<strong>on</strong>. There are alsodifferences between the functi<strong>on</strong>s of these two envir<strong>on</strong>ments.The development envir<strong>on</strong>ment is used <strong>to</strong> develop the migrati<strong>on</strong> soluti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the database,client applicati<strong>on</strong>, and server applicati<strong>on</strong>s. In additi<strong>on</strong>, the envir<strong>on</strong>ment may go throughchanges as the soluti<strong>on</strong> is developed.By c<strong>on</strong>trast, the test envir<strong>on</strong>ment is more strictly c<strong>on</strong>trolled <strong>to</strong> ensure that it emulates theproducti<strong>on</strong> envir<strong>on</strong>ment. The test envir<strong>on</strong>ment is used <strong>to</strong> complete all necessary testing<str<strong>on</strong>g>for</str<strong>on</strong>g> the database and applicati<strong>on</strong>. The test envir<strong>on</strong>ment must be as similar as possible <strong>to</strong>the producti<strong>on</strong> envir<strong>on</strong>ment so that stress and scalability tests will have a measure ofaccuracy.Often in migrati<strong>on</strong> projects, the development envir<strong>on</strong>ment is used <str<strong>on</strong>g>for</str<strong>on</strong>g> testing <strong>on</strong>ce theDeveloping Phase has ended. In most situati<strong>on</strong>s, the test envir<strong>on</strong>ment requires a higherlevel of per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance than the development envir<strong>on</strong>ment, and additi<strong>on</strong>al hardware willneed <strong>to</strong> be added.If you are reusing equipment, it is best <strong>to</strong> reload all operating systems, applicati<strong>on</strong>s, anddata. This ensures that testing results will not be skewed by a system setting or error leftfrom the development envir<strong>on</strong>ment.The test envir<strong>on</strong>ment also has different requirements than the development envir<strong>on</strong>ment.For instance, testing <strong>to</strong>ols should be installed <str<strong>on</strong>g>for</str<strong>on</strong>g> tasks such as recording per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancefac<strong>to</strong>rs, or <strong>to</strong> increase the load during stress testing.The <strong>to</strong>ols required <str<strong>on</strong>g>for</str<strong>on</strong>g> development and testing are:● Database modeling <strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> reverse engineering existing databases andgenerating data definiti<strong>on</strong> statements <str<strong>on</strong>g>for</str<strong>on</strong>g> the new envir<strong>on</strong>ment. The more popularmodeling <strong>to</strong>ols are AllFusi<strong>on</strong> ERwin from Computer Associates and ER/Studiofrom Embarcadero.● Software development <strong>to</strong>ols such Visual Studio .NET or Visual Basic .NET, Perl,Pyth<strong>on</strong>, PHP, and Java● Software management <strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> source c<strong>on</strong>trol and bug tracking — Visual SourceSafe and C<strong>on</strong>current Versi<strong>on</strong> Systems (CVS) are the popular <strong>on</strong>es <str<strong>on</strong>g>for</str<strong>on</strong>g> sourcec<strong>on</strong>trol. PVCS from Merant and ClearQuest from Rati<strong>on</strong>al can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> bugtracking.● An applicati<strong>on</strong> debugger (if <strong>on</strong>e is not bundled with the applicati<strong>on</strong> development<strong>to</strong>ol). Most applicati<strong>on</strong>s come with their own built-in debuggers.● Software <str<strong>on</strong>g>for</str<strong>on</strong>g> administering <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>offer Enterprise Manager, which c<strong>on</strong>tains a comprehensive set of <strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> alladministrative tasks. There are several third-party <strong>to</strong>ols available, such as Toadand <strong>SQL</strong> Naviga<strong>to</strong>r from Quest, PL/<strong>SQL</strong> Developer from Allround Au<strong>to</strong>mati<strong>on</strong>s,Unicenter <strong>SQL</strong>-Stati<strong>on</strong> from Computer Associates, and Rapid <strong>SQL</strong> fromEmbarcedero.● Database and data migrati<strong>on</strong> <strong>to</strong>ols. Tools that are aimed specifically at <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong><strong>SQL</strong> Sever migrati<strong>on</strong> are available from Microsoft.● <strong>UNIX</strong> interoperability <strong>to</strong>ols such as SFU, FreeTDS, and so <strong>on</strong>.


66Planning Phase●●●Scripting <strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> writing scripts <str<strong>on</strong>g>for</str<strong>on</strong>g> testing. Perl is a popular scripting languagethat is portable across <strong>UNIX</strong> and Windows. Windows Script is available fromMicrosoft.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance m<strong>on</strong>i<strong>to</strong>ring and analysis <strong>to</strong>ols <str<strong>on</strong>g>for</str<strong>on</strong>g> the various comp<strong>on</strong>ents of thesoluti<strong>on</strong>. Perfm<strong>on</strong> is a versatile <strong>to</strong>ol <str<strong>on</strong>g>for</str<strong>on</strong>g> m<strong>on</strong>i<strong>to</strong>ring the Windows system and it cancapture statistics <str<strong>on</strong>g>for</str<strong>on</strong>g> any applicati<strong>on</strong> that runs <strong>on</strong> a Windows computer. Filem<strong>on</strong>and <strong>Net</strong>m<strong>on</strong> can be used specifically <str<strong>on</strong>g>for</str<strong>on</strong>g> the file system and internet traffic.Scheduling <strong>to</strong>ol <str<strong>on</strong>g>for</str<strong>on</strong>g> au<strong>to</strong>mating tests and <str<strong>on</strong>g>for</str<strong>on</strong>g> capturing statistics. Windowsscheduler can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> this purpose. Au<strong>to</strong>sys from Computer Associates andC<strong>on</strong>trol-M from BMC are also popular.For additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> testing, refer <strong>to</strong> Chapter 18, "Stabilizing Phase."


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 674Developing: Databases —Introducti<strong>on</strong>Introducti<strong>on</strong> and GoalsFor a migrati<strong>on</strong> project, the Developing Phase is the time when the team builds thesoluti<strong>on</strong> comp<strong>on</strong>ents — code and infrastructure as well as documentati<strong>on</strong>. Typically, thiswork c<strong>on</strong>sists of modifying existing code in a way that enables it <strong>to</strong> work within the newenvir<strong>on</strong>ment. When new code is written, some aspect of the original comp<strong>on</strong>ent usuallyremains unchanged — <str<strong>on</strong>g>for</str<strong>on</strong>g> example, exposed APIs, or specific comp<strong>on</strong>ent behaviors.Both the modificati<strong>on</strong> of existing code and development of new code in this c<strong>on</strong>text arec<strong>on</strong>sidered <strong>to</strong> be migrating activities.Although the development and migrati<strong>on</strong> work is the focus of this phase and thisguidance, the entire team is active. For example, some team members are creatingdeliverables such as training materials, rollout and site preparati<strong>on</strong> checklists, andupdated pilot and rollout plans while others are doing functi<strong>on</strong>al testing. Somedevelopment work may c<strong>on</strong>tinue in<strong>to</strong> the Stabilizing Phase in resp<strong>on</strong>se <strong>to</strong> test results.This chapter serves as an introducti<strong>on</strong> <strong>to</strong> the database development-oriented chapters.Chapters 5 through 8 describe and dem<strong>on</strong>strate how <strong>to</strong> implement a Microsoft®<strong>SQL</strong> <strong>Server</strong> database that resembles the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database as closely aspossible. These chapters also describe how <strong>to</strong> produce a soluti<strong>on</strong> that meets yourorganizati<strong>on</strong>'s requirements <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, functi<strong>on</strong>ality, availability, scalability, andrecoverability. The following list provides an overview of the c<strong>on</strong>tent in each of thedatabase development-oriented chapters:● Chapter 4: Developing: Database — Introducti<strong>on</strong>. This chapter prefaces thedifferent tasks in migrating the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> 2000.● Chapter 5: Developing: Database — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Architecture.This chapter describes the steps in creating an instance of <strong>SQL</strong> <strong>Server</strong> which isequivalent in architecture <strong>to</strong> the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.● Chapter 6: Developing: Database — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas. This chapter showshow <strong>to</strong> migrate a schema owner and its objects <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database.● Chapter 7: Developing: Database — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Users. Thischapter c<strong>on</strong>tains detailed steps in creating users in the <strong>SQL</strong> <strong>Server</strong> databases andgranting them the same kind of privileges they had in the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.


68Developing: Databases — Introducti<strong>on</strong>●●Chapter 8: Developing: Database — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data. This chapter exploresthe different opti<strong>on</strong>s in migrating the applicati<strong>on</strong> data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. Itprovides details in the usage of each of the opti<strong>on</strong>s.Chapter 9: Developing: Database — Unit Testing the Migrati<strong>on</strong>. This chapterc<strong>on</strong>tains the processes <str<strong>on</strong>g>for</str<strong>on</strong>g> testing the migrated database, its objects and data.The Developing Phase <str<strong>on</strong>g>for</str<strong>on</strong>g>mally ends with the Scope Complete Milest<strong>on</strong>e. At this majormilest<strong>on</strong>e, the team gains <str<strong>on</strong>g>for</str<strong>on</strong>g>mal approval from the sp<strong>on</strong>sor or key stakeholders. Allsoluti<strong>on</strong> elements are built and the soluti<strong>on</strong> features and functi<strong>on</strong>ality are completeaccording <strong>to</strong> the functi<strong>on</strong>al specificati<strong>on</strong>s agreed up<strong>on</strong> during planning. Table 4.1describes the major tasks that need <strong>to</strong> take place while migrating the database.Table 4.1: Major Tasks and DeliverablesTasksMigrate the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database architectureMigrate the schemasMigrate the usersMigrate the dataDeliverables<strong>SQL</strong> <strong>Server</strong> instance that is equivalent instructure <strong>to</strong> the source<strong>SQL</strong> <strong>Server</strong> databases housing applicati<strong>on</strong>schemas<strong>SQL</strong> <strong>Server</strong> users with similar privileges asthe sourceComplete database ready <str<strong>on</strong>g>for</str<strong>on</strong>g> use<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the DatabaseBecause they are both relati<strong>on</strong>al databases, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> have moresimilarities than differences in their features and functi<strong>on</strong>s. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>provide all the core functi<strong>on</strong>ality expected of a RDBMS, including c<strong>on</strong>currency, security,backup, recovery, scalability, availability, sessi<strong>on</strong> management, transacti<strong>on</strong> management,s<strong>to</strong>rage management, resource management, and so <strong>on</strong>. Both exhibit a moderate degreeof compliance <strong>to</strong> ANSI standards. Hence migrating from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong><strong>on</strong> Windows® poses less of a challenge than would normally be expected whenmigrating from <strong>on</strong>e proprietary computing system <strong>to</strong> another. Because <strong>SQL</strong> <strong>Server</strong> and<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are relati<strong>on</strong>al databases, it is not necessary <strong>to</strong> redesign the database. It is notnecessary <strong>to</strong> rearchitect the applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance or security because the twoDBMSs are very similar in their architecture. The majority of the work involved is inaccommodating the differences in the implementati<strong>on</strong> of items such as indexes, datatypes, and <strong>SQL</strong> and DBMS features, such as partiti<strong>on</strong>ing.To simplify the migrati<strong>on</strong> of the database, the entire process can be organized in<strong>to</strong> fourmajor tasks:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 69Figure 4.1Tasks in the migrati<strong>on</strong> of a databaseEach of the four major tasks includes a set of subtasks as follows:1. Migrate the database architecturea. Build the <strong>SQL</strong> <strong>Server</strong> instanceb. C<strong>on</strong>figure the serverc. Migrate the s<strong>to</strong>rage architecture2. Migrate the schemasa. Migrate the schemab. Migrate the schema objects3. Migrate the usersa. Create user accountsb. Create roles and grant privileges4. Migrate the dataa. Plan the data migrati<strong>on</strong>b. Execute the data migrati<strong>on</strong>In Chapters 5 through 8, examples are provided <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the major tasks and subtasksat the end of the chapter. The discussi<strong>on</strong> of testing the migrated database is in Chapter9, "Developing: Databases — Unit Testing the Migrati<strong>on</strong>." <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBAs who are new <strong>to</strong><strong>SQL</strong> <strong>Server</strong> should also read Appendix A, "<strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Professi<strong>on</strong>als," whichprovides a c<strong>on</strong>densed guide <str<strong>on</strong>g>for</str<strong>on</strong>g> educating <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBAs about the internal architecture of<strong>SQL</strong> <strong>Server</strong> by leveraging existing knowledge of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The appendix also providesin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about how <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m some of the comm<strong>on</strong> administrative functi<strong>on</strong>s in<strong>SQL</strong> <strong>Server</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 715Developing: Databases —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the DatabaseArchitectureIntroducti<strong>on</strong> and GoalsThe first task in the migrati<strong>on</strong> of the database is <strong>to</strong> create an instance of <strong>SQL</strong> <strong>Server</strong> thatwill provide the c<strong>on</strong>tainer (the RDBMS) <str<strong>on</strong>g>for</str<strong>on</strong>g> creating schemas and schema objects <strong>to</strong> cater<strong>to</strong> the needs of applicati<strong>on</strong>s. Your main focus when creating the database should be <strong>on</strong>its architecture: the instance architecture involving server resources, such as processorpower and memory; and s<strong>to</strong>rage architecture, including file systems. Your objective <str<strong>on</strong>g>for</str<strong>on</strong>g>both of these areas is <strong>to</strong> derive per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance that is equivalent <strong>to</strong> or better than theoriginal soluti<strong>on</strong>.The two most comm<strong>on</strong> implementati<strong>on</strong>s of databases are Online Transacti<strong>on</strong> Processing(OLTP) systems and Decisi<strong>on</strong> Support Systems (DSS). OLTP systems are characterizedby large numbers of short transacti<strong>on</strong>s that frequently add or modify data. DSS systems,<strong>on</strong> the other hand, c<strong>on</strong>tain large volumes of mostly static data imported in<strong>to</strong> them fromOLTP databases, file systems, and other such systems <str<strong>on</strong>g>for</str<strong>on</strong>g> the purposes of analysis andreporting. There are fewer transacti<strong>on</strong>s in DSS systems, but they run much l<strong>on</strong>ger. OLTPsystem per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is influenced by locking. DSS per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is typified by large reads,sorts, computati<strong>on</strong>, and so <strong>on</strong>.The guidance provided in this soluti<strong>on</strong> is focused <strong>on</strong> OLTP systems. The types ofoperati<strong>on</strong>s per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in OLTP and DSS systems impose different demands <strong>on</strong> thedatabase resources. While the architecture <str<strong>on</strong>g>for</str<strong>on</strong>g> OLTP and DSS systems differs, resourcec<strong>on</strong>siderati<strong>on</strong>s are similar. Though there are some objects that are specialized <str<strong>on</strong>g>for</str<strong>on</strong>g> DSSsystems, most objects are comm<strong>on</strong> <strong>to</strong> both systems. As a result, the guidance providedapplies <strong>to</strong> DSS systems, as well.Build the <strong>SQL</strong> <strong>Server</strong> InstanceThis secti<strong>on</strong> discusses the planning and preparati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> installing the <strong>SQL</strong> <strong>Server</strong>RDBMS software. A more detailed discussi<strong>on</strong> can be found in <strong>SQL</strong> <strong>Server</strong> Books Onlineunder the “Installing <strong>SQL</strong> <strong>Server</strong>” <strong>to</strong>pic.


72Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database ArchitecturePre-Installati<strong>on</strong> PlanningYou should follow these design guidelines <str<strong>on</strong>g>for</str<strong>on</strong>g> the layout of a <strong>SQL</strong> <strong>Server</strong> softwareinstallati<strong>on</strong> and database files:● Independent subdirec<strong>to</strong>ries. Files should be separated by categories andinstance <strong>to</strong> minimize effects and ease navigati<strong>on</strong>. When named instances of <strong>SQL</strong><strong>Server</strong> are created, the associated direc<strong>to</strong>ries are created with instance names <str<strong>on</strong>g>for</str<strong>on</strong>g>identificati<strong>on</strong> purposes.● C<strong>on</strong>sistent naming c<strong>on</strong>venti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> files. Use the following file name extensi<strong>on</strong>s:.mdf <str<strong>on</strong>g>for</str<strong>on</strong>g> primary datafiles, .ndf <str<strong>on</strong>g>for</str<strong>on</strong>g> sec<strong>on</strong>dary datafiles, and .ldf <str<strong>on</strong>g>for</str<strong>on</strong>g> log files. Thedefault file naming c<strong>on</strong>venti<strong>on</strong> is dbname_data.mdf <str<strong>on</strong>g>for</str<strong>on</strong>g> the datafile anddbname_log.ldf <str<strong>on</strong>g>for</str<strong>on</strong>g> the log file.● Integrity of home direc<strong>to</strong>ries. Keep the <strong>SQL</strong> <strong>Server</strong> software separate from thedatafiles. This allows the software <strong>to</strong> be moved or deleted without affecting theapplicati<strong>on</strong>.● Separati<strong>on</strong> of administrative in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> each database. S<strong>to</strong>re system datain the master database separate from other data.● Separati<strong>on</strong> of tablespace c<strong>on</strong>tent. Every instance of <strong>SQL</strong> <strong>Server</strong> comes with thesystem databases master, model, msdb, and tempdb.● Tune I/O load across all disks. <strong>SQL</strong> <strong>Server</strong> has filegroups, each with multiplefiles that give the same advantages as tablespaces. In additi<strong>on</strong>, s<strong>to</strong>rage allocated<strong>to</strong> an object is distributed evenly across all datafiles bel<strong>on</strong>ging <strong>to</strong> the filegroup.Installati<strong>on</strong>The following important installati<strong>on</strong> opti<strong>on</strong>s have <strong>to</strong> be determined prior <strong>to</strong> installing <strong>SQL</strong><strong>Server</strong>:● Instance name. <strong>SQL</strong> <strong>Server</strong> has a provisi<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> a default instance where theinstance takes the network name of the server. Multiple instances with assignednames can also be created. <strong>SQL</strong> <strong>Server</strong> naming c<strong>on</strong>venti<strong>on</strong>s do not precludereuse of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> instance names.● <strong>Net</strong>work libraries. <strong>SQL</strong> <strong>Server</strong> can communicate using several network pro<strong>to</strong>cols.TCP/IP and named pipes are the most comm<strong>on</strong>. To minimize resource utilizati<strong>on</strong>,<strong>on</strong>ly c<strong>on</strong>figure those pro<strong>to</strong>cols that are required.● Service accounts. Like any other service, both <strong>SQL</strong> <strong>Server</strong> and <strong>SQL</strong> <strong>Server</strong>Agent (the <strong>SQL</strong> <strong>Server</strong> scheduling service) require a Microsoft Windows® account.You should run <strong>SQL</strong> <strong>Server</strong> under a domain account. It does not have <strong>to</strong> be a localadministra<strong>to</strong>r or a domain account that has local administrative privileges.● Authenticati<strong>on</strong> mode. Opti<strong>on</strong>s available in <strong>SQL</strong> <strong>Server</strong> are WindowsAuthenticati<strong>on</strong> or Mixed mode. Mixed mode allows login access <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>either by a valid Windows account or a valid <strong>SQL</strong> <strong>Server</strong> login. The authenticati<strong>on</strong>mode can be changed any time in the future. Changing the authenticati<strong>on</strong> moderequires that the database be restarted <strong>to</strong> take effect.● Licensing mode. Indicate whether this <strong>SQL</strong> <strong>Server</strong> is licensed by processor or perseat (Client Access License) and the number <str<strong>on</strong>g>for</str<strong>on</strong>g> the given mode.● Locati<strong>on</strong> of files. With <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, even though the installer provides the opti<strong>on</strong> ofcreating a starter database, installing the software and creati<strong>on</strong> of databases aretwo independent events. Installing the <strong>SQL</strong> <strong>Server</strong> software also creates a"database system" with databases such as master, model, msdb, northwind,pubs, and tempdb created by default. The destinati<strong>on</strong> locati<strong>on</strong> of <strong>SQL</strong> <strong>Server</strong>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 73applicati<strong>on</strong> files and the datafiles <str<strong>on</strong>g>for</str<strong>on</strong>g> the default databases can be specified atinstallati<strong>on</strong>.C<strong>on</strong>figure the <strong>Server</strong>A <strong>SQL</strong> <strong>Server</strong> instance can be c<strong>on</strong>figured similar <strong>to</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> instance. The areas thatare covered here include memory, CPU, and listener.Architecturally, both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> can be divided in<strong>to</strong> instance and database.The instance is made up of memory areas and database processes. In <strong>SQL</strong> <strong>Server</strong>, thedivisi<strong>on</strong> of memory pool in<strong>to</strong> sub-caches (buffer cache, procedure cache, log cache,c<strong>on</strong>necti<strong>on</strong> c<strong>on</strong>text, and system data structures) based <strong>on</strong> functi<strong>on</strong> closely resembles the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> SGA and its comp<strong>on</strong>ents. <strong>SQL</strong> <strong>Server</strong> has threads that per<str<strong>on</strong>g>for</str<strong>on</strong>g>m similar work <strong>to</strong> the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g>eground and background processes.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the characteristics and behavior of the database and the instance aredetermined by a large set of parameters s<strong>to</strong>red in the initializati<strong>on</strong> file (init.ora) or serverparameter file (spfile). These parameters cover a diverse set of resources, such asmemory, processes, network, disk, I/O, c<strong>on</strong>necti<strong>on</strong>s, files, character set, and so <strong>on</strong>.The n<strong>on</strong>-default values of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> initializati<strong>on</strong> parameters can be obtained from theparameter file if <strong>on</strong>e is in use. If a server parameter file is in use, the parameter valuescan be obtained using <strong>on</strong>e of the following opti<strong>on</strong>s:● C<strong>on</strong>vert the server parameter file (spfile) <strong>to</strong> an initializati<strong>on</strong> parameter file byexecuting the following statement:CREATE pfile FROM spfile● Query the database by executing the following statement:SELECT name, valueFROM sys.v$spparameterWHERE isspecified = 'TRUE'<strong>SQL</strong> <strong>Server</strong> does not have an equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g> every initializati<strong>on</strong> parameter. Thec<strong>on</strong>figurati<strong>on</strong> opti<strong>on</strong>s in <strong>SQL</strong> <strong>Server</strong> can be specified using <strong>SQL</strong> <strong>Server</strong> EnterpriseManager or using the sp_c<strong>on</strong>figure system s<strong>to</strong>red procedure. Syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> use is shown inthe following statement.sp_c<strong>on</strong>figure [opti<strong>on</strong>, [value]]A discussi<strong>on</strong> of every <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> initializati<strong>on</strong> parameter is bey<strong>on</strong>d the scope of this guide.The c<strong>on</strong>figurati<strong>on</strong> opti<strong>on</strong>s available in <strong>SQL</strong> <strong>Server</strong> can be categorized in<strong>to</strong> userc<strong>on</strong>figurableand advanced. The advanced opti<strong>on</strong>s, which are similar <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>’s “hidden”parameters, are either self-c<strong>on</strong>figuring or should be manipulated <strong>on</strong>ly with the advice of acertified <strong>SQL</strong> <strong>Server</strong> technician.Examples of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> parameters that have an equivalent c<strong>on</strong>figurable parameter in<strong>SQL</strong> <strong>Server</strong> are provided in Table 5.1:Table 5.1: Examples of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Initializati<strong>on</strong> Parameters with Equivalent in<strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Processesfast_start_mttr_targetSessi<strong>on</strong>sdml_locks<strong>SQL</strong> <strong>Server</strong>max worker thread opti<strong>on</strong>srecovery intervalUser c<strong>on</strong>necti<strong>on</strong>sLocks


74Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database ArchitectureSometimes a c<strong>on</strong>figurati<strong>on</strong> opti<strong>on</strong> can be set at <strong>on</strong>e of several different places. Forexample, the <strong>SQL</strong> <strong>Server</strong> max degree of parallelism parameter can be set using the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DEGREE clause at the object or query level.Certain opti<strong>on</strong>s which are c<strong>on</strong>figurable in <strong>on</strong>e database may have a fixed implementati<strong>on</strong>in the other. For example, the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> LOG_CHECKPOINT_INTERVAL andLOG_CHECKPOINT_TIMEOUT parameters used <strong>to</strong> tune checkpoints do not haveequivalents in <strong>SQL</strong> <strong>Server</strong>. In <strong>SQL</strong> <strong>Server</strong>, checkpoints occur au<strong>to</strong>matically based <strong>on</strong> thenumber of redo records in the log. Similarly, UNDO_MANAGEMENT,UNDO_TABLESPACE, and ROLLBACK_SEGMENTS that define the s<strong>to</strong>rage <str<strong>on</strong>g>for</str<strong>on</strong>g>transacti<strong>on</strong> rollback or undo data are implemented in <strong>SQL</strong> <strong>Server</strong> as part of thetransacti<strong>on</strong> logs of each database.C<strong>on</strong>figure Memory<strong>SQL</strong> <strong>Server</strong> has far fewer c<strong>on</strong>figurati<strong>on</strong> parameters than <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, there areseveral parameters that are used <strong>to</strong> c<strong>on</strong>trol memory allocati<strong>on</strong> <strong>to</strong> the instance and itssub-comp<strong>on</strong>ents. Some of these parameters are● SGA_MAX_SIZE● DB_CACHE_SIZE● SHARED_POOL_SIZE● LARGE_POOL_SIZE● JAVA_POOL_SIZE● LOG_BUFFER● SORT_AREA_SIZE<strong>SQL</strong> <strong>Server</strong> offers the parameters min server memory and max server memory, whichcan be used <strong>to</strong> limit the amount of server memory that can be utilized by the databasesystem. <strong>SQL</strong> <strong>Server</strong> cooperates with the operating system <strong>to</strong> dynamically adjust theamount of memory used based <strong>on</strong> the demands <strong>on</strong> the server from other applicati<strong>on</strong>s.However, this behavior puts the burden <strong>on</strong> the dimensi<strong>on</strong>ing of the system so it iscapable of running the database with known loads and peaks and avoiding competingworkloads which might jeopardize the system resources available <strong>to</strong> the database. Allmemory areas within the memory pool are dynamically adjusted by the <strong>SQL</strong> <strong>Server</strong> code<strong>to</strong> optimize per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and do not need any administra<strong>to</strong>r input. Hence you will findvery few memory-related c<strong>on</strong>figurati<strong>on</strong> parameters in <strong>SQL</strong> <strong>Server</strong>.The amount of memory that can be utilized by <strong>SQL</strong> <strong>Server</strong> can be c<strong>on</strong>figured either usingEnterprise Manager or through T-<strong>SQL</strong>. The two opti<strong>on</strong>s are provided in the followingprocedures:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 75 To c<strong>on</strong>figure the amount of memory available <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> in EnterpriseManager, follow these steps:1. Expand the server group.2. Right-click <strong>Server</strong> (<strong>Server</strong> Name\Instance Name), and then click Properties.3. Select the Memory tab.4. Select Dynamically c<strong>on</strong>figure <strong>SQL</strong> <strong>Server</strong> memory <strong>to</strong> set the memory rangeunder which <strong>SQL</strong> <strong>Server</strong> should operate. Select Use a fixed memory size (MB) <strong>to</strong>allocate a fixed amount of memory. The actual values can be selected using thememory slider graphic.The code <str<strong>on</strong>g>for</str<strong>on</strong>g> setting a range of memory and a fixed amount of memory <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> isprovided in the following procedure. To c<strong>on</strong>figure a range of memory <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> using T-<strong>SQL</strong>, enter thefollowing commands:USE masterEXEC sp_c<strong>on</strong>figure 'show advanced opti<strong>on</strong>', 1RECONFIGUREGOsp_c<strong>on</strong>figure 'min server memory', 100 -- 100MBRECONFIGUREGOsp_c<strong>on</strong>figure 'max server memory', 4000 -- 4000 MBRECONFIGUREGO To c<strong>on</strong>figure a fixed amount of memory <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> using T-<strong>SQL</strong>, enter thefollowing commands:USE mastersp_c<strong>on</strong>figure 'show advanced opti<strong>on</strong>', 1RECONFIGUREGOsp_c<strong>on</strong>figure 'min server memory', 400RECONFIGUREGOsp_c<strong>on</strong>figure 'max server memory', 400RECONFIGUREGONote A database restart is required <strong>to</strong> activate the new settings of all advanced opti<strong>on</strong>s.If the amount of physical memory exceeds 3 GB, then the Address WindowingExtensi<strong>on</strong>s (AWE) Windows feature has <strong>to</strong> be enabled <strong>to</strong> handle allocati<strong>on</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>using the c<strong>on</strong>figurati<strong>on</strong> parameter awe enabled. When this feature is enabled,<strong>SQL</strong> <strong>Server</strong> s<strong>to</strong>ps dynamic memory management at the server level and the max servermemory parameter has <strong>to</strong> be set. If the max server memory parameter is set, cache


76Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Architecturemanagement is similar <strong>to</strong> SGA sizing in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> but without the complicati<strong>on</strong>s of tuning theindividual cache comp<strong>on</strong>ents. To c<strong>on</strong>figure <strong>SQL</strong> <strong>Server</strong> <strong>to</strong> use more than 3 GB of memory using T-<strong>SQL</strong>,enter the following commands:USE mastersp_c<strong>on</strong>figure 'show advanced opti<strong>on</strong>', 1RECONFIGUREGOsp_c<strong>on</strong>figure 'awe enabled', 1RECONFIGUREGOsp_c<strong>on</strong>figure 'max server memory', 6000RECONFIGUREGOBecause the memory requirements of a <strong>SQL</strong> <strong>Server</strong> instance are not the same as anequivalent <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> instance, the <strong>SQL</strong> <strong>Server</strong> memory size has <strong>to</strong> be tuned during amigrati<strong>on</strong>. The following Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r counters can be used <strong>to</strong> check the amoun<strong>to</strong>f memory <strong>SQL</strong> <strong>Server</strong> is using:● <strong>SQL</strong> <strong>Server</strong>: Buffer Manager: Total Pages● <strong>SQL</strong> <strong>Server</strong>: Memory Manager: Total <strong>Server</strong> Memory (KB)● Process: Working SetThe dbcc memorystatus command can be used <strong>to</strong> view in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about memoryallocati<strong>on</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about memory usage and this command, refer <strong>to</strong>http://support.microsoft.com/?id=271624.The LOCK_SGA initializati<strong>on</strong> parameter can be implemented in <strong>SQL</strong> <strong>Server</strong> using setworking set size. The allocated memory stays in physical memory and improvesper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance because swapping is avoided. However, care should be taken thatallocating a fixed amount of memory <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> does not impact the needs of otherapplicati<strong>on</strong>s running <strong>on</strong> the same server.Set the CPU Affinity<strong>SQL</strong> <strong>Server</strong> has the capability of defining CPU affinity where CPUs can be dedicated <strong>to</strong>an instance. This can be c<strong>on</strong>trolled using the affinity mask c<strong>on</strong>figurati<strong>on</strong> setting orEnterprise Manager. The priority boost c<strong>on</strong>figurati<strong>on</strong> setting can be used <strong>to</strong> prioritizethreads. <strong>SQL</strong> <strong>Server</strong> SP1 has added an IO_affinity_mask switch, which can used atinstance startup <strong>to</strong> reserve CPUs <strong>to</strong> handle disk I/O associated with the instance. Use ofthe IO_affinity_mask c<strong>on</strong>figurati<strong>on</strong> setting is <strong>on</strong>ly recommended <str<strong>on</strong>g>for</str<strong>on</strong>g> machines with morethan 16 CPUs.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> setting up the I/O affinity mask, refer <strong>to</strong>http://support.microsoft.com/?kbid=298402.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 77C<strong>on</strong>figure the ListenerThe <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> listener can operate <strong>on</strong> any available port. The well-known default selecti<strong>on</strong> is1521. A default installati<strong>on</strong> of <strong>SQL</strong> <strong>Server</strong> uses port 1433. If not c<strong>on</strong>figured manually, anamed instance picks up an unused TCP port during startup. Unlike <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, where asingle listener is shared by all instances, each <strong>SQL</strong> <strong>Server</strong> instance listens <strong>on</strong> its ownport. The <strong>SQL</strong> <strong>Server</strong> server name, database name, and port in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> are required byclient applicati<strong>on</strong>s <strong>to</strong> c<strong>on</strong>figure the data source or the c<strong>on</strong>necti<strong>on</strong> string (in n<strong>on</strong>-DNSc<strong>on</strong>necti<strong>on</strong>s).Migrate the S<strong>to</strong>rage ArchitectureThis secti<strong>on</strong> discusses the physical and logical s<strong>to</strong>rage structures found in <strong>SQL</strong> <strong>Server</strong>.This discussi<strong>on</strong> is useful in understanding how <strong>to</strong> c<strong>on</strong>figure s<strong>to</strong>rage in <strong>SQL</strong> <strong>Server</strong> in amanner similar <strong>to</strong> the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.Database data is physically s<strong>to</strong>red in files. However, allocati<strong>on</strong> of this space <strong>to</strong> thedatabase objects is d<strong>on</strong>e in logical units such as blocks, extents, and segments. Figure5.1 provides a comparis<strong>on</strong> of the s<strong>to</strong>rage architecture in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Figure 5.1Mapping <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> s<strong>to</strong>rage structures <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>The organizati<strong>on</strong> of s<strong>to</strong>rage and its allocati<strong>on</strong> has great significance <strong>on</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance andmaintenance of a database. Due <strong>to</strong> the similarities in the s<strong>to</strong>rage architecture, theprinciples <strong>on</strong> which the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database was organized can be carried over in<strong>to</strong>the <strong>SQL</strong> <strong>Server</strong> database with relative ease. The following secti<strong>on</strong>s discuss each level ofthe s<strong>to</strong>rage hierarchy shown in Figure 5.1.BlocksIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the smallest unit of s<strong>to</strong>rage is the data block. All data in the database isretrieved and manipulated in terms of blocks. The <strong>SQL</strong> <strong>Server</strong> equivalent of the datablock is called the page. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the DBA chooses the default page size at databasecreati<strong>on</strong> <strong>to</strong> be any of 2K, 4K, 8K, 16K or 32K. In <strong>SQL</strong> <strong>Server</strong>, the page size is fixed at 8K.With <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i, in additi<strong>on</strong> <strong>to</strong> the default page size, up <strong>to</strong> five n<strong>on</strong>-standard (n<strong>on</strong>-default)


78Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Architecturepage sizes can also be used <str<strong>on</strong>g>for</str<strong>on</strong>g> the tablespaces (and, c<strong>on</strong>sequently, the logical s<strong>to</strong>ragestructures).The <strong>SQL</strong> <strong>Server</strong> page has similar compositi<strong>on</strong> as the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> data block. The data pagec<strong>on</strong>sists of page header, data rows, and row offset array (row direc<strong>to</strong>ry). The headerleaves 8060 bytes of usable space <str<strong>on</strong>g>for</str<strong>on</strong>g> data rows and row offset. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, a data rowthat is larger than the usable space is broken in<strong>to</strong> several row pieces (row chaining) ands<strong>to</strong>red in multiple blocks. <strong>SQL</strong> <strong>Server</strong> does not allow rows larger than 8060 bytes. Thisrestricti<strong>on</strong> in <strong>SQL</strong> <strong>Server</strong>, however, does not apply <strong>to</strong> rows c<strong>on</strong>taining large data types,such as text, image, and so <strong>on</strong>, which are s<strong>to</strong>red differently.Within a <strong>SQL</strong> <strong>Server</strong> block, space is managed in a manner similar <strong>to</strong> that by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>’sAu<strong>to</strong>matic Segment Space Management (ASSM) opti<strong>on</strong>, where used and free space istracked using bitmaps. This has implicati<strong>on</strong>s with respect <strong>to</strong> migrating <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. In<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the choice of block size is driven by the type of database — OLTP or DSS/DataWarehouse. The advantage of large block size is mainly in terms of I/O per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancebecause there is less overall cost <str<strong>on</strong>g>for</str<strong>on</strong>g> setting up fewer I/Os. Better I/O per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance canbe achieved with smaller block sizes by using other techniques, such as multi-block read(DB_FILE_MULTIBLOCK_READ_COUNT), parallel reads and read ahead, or prefetch.The maximum I/O size, however, is dependent <strong>on</strong> the operating system. <strong>SQL</strong> <strong>Server</strong> alsouses a technique called scatter I/O that enables multiple unrelated blocks <strong>to</strong> be read in asingle I/O request.An advantage of larger block size is reduced amount of row chaining. This is a fac<strong>to</strong>rwhen tables c<strong>on</strong>tain rows with lengths larger than can be accommodated in a block.Reading of multiple blocks may be necessitated in a <strong>SQL</strong> <strong>Server</strong> database as compared<strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases with larger block size, but the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance can be compensated <str<strong>on</strong>g>for</str<strong>on</strong>g>by better hardware and I/O techniques.Based <strong>on</strong> the envir<strong>on</strong>ment, large block sizes can impact cache per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. With largeblock sizes, <str<strong>on</strong>g>for</str<strong>on</strong>g> a fixed amount of RAM, the number of blocks in physical memoryreduces. For example, if 1 MB of memory can hold 500 blocks of size 2 KB, it can hold<strong>on</strong>ly 125 blocks of size 8 KB. So the cache per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is dependent <strong>on</strong> the density ofthe block (number of rows per block) and the access pattern (random or sequential).Smaller blocks reduce c<strong>on</strong>tenti<strong>on</strong> while the overhead becomes a larger porti<strong>on</strong> of theblock.In the migrati<strong>on</strong>, the move from differing block sizes in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> 8 KB blocks in<strong>SQL</strong> <strong>Server</strong> does not pose any challenge. When migrating from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> (where multipleblock sizes are in use), the rows will be rearranged in<strong>to</strong> 8 KB blocks. However, soluti<strong>on</strong>shave <strong>to</strong> be created <strong>to</strong> accommodate rows with length greater than 8060 bytes. Suchsoluti<strong>on</strong>s are examined later in this chapter.Extents and SegmentsData allocati<strong>on</strong> <strong>to</strong> schema objects (such as tables and indexes) and system datastructures (temporary segment, rollback segment) in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> is in termsof logical extents. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> provides parameters <str<strong>on</strong>g>for</str<strong>on</strong>g> appropriate sizing of the extents.<strong>SQL</strong> <strong>Server</strong>, <strong>on</strong> the other hand, uses fixed size extents of 8 pages (64 KB). <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>extents — irrespective of whether they bel<strong>on</strong>g <strong>to</strong> dicti<strong>on</strong>ary or locally-managedtablespaces — are migrated <strong>to</strong> fixed 64 KB extents.Extents allocated <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> objects are dedicated <strong>to</strong> the object and do not c<strong>on</strong>tain blocksfrom other objects. This is not the case in <strong>SQL</strong> <strong>Server</strong>. <strong>SQL</strong> <strong>Server</strong> has two types ofextents: uni<str<strong>on</strong>g>for</str<strong>on</strong>g>m and mixed. In a uni<str<strong>on</strong>g>for</str<strong>on</strong>g>m extent, all pages are allocated <strong>to</strong> a single object,while mixed extents can have pages bel<strong>on</strong>ging <strong>to</strong> multiple objects. When a table or indexis created in <strong>SQL</strong> <strong>Server</strong>, initially it is allocated two pages out of mixed extent. When the


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 79table or index grows <strong>to</strong> eight pages, all future allocati<strong>on</strong>s use uni<str<strong>on</strong>g>for</str<strong>on</strong>g>m extents. As a resul<strong>to</strong>f fixed size extents, fragmentati<strong>on</strong> within the tablespace (filegroup in <strong>SQL</strong> <strong>Server</strong>) iseliminated.Because an extent is a c<strong>on</strong>tiguous allocati<strong>on</strong> of blocks, large extents aid in better I/O ratewhile reading huge amounts of data. After moving <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, physical I/O will have<strong>to</strong> be c<strong>on</strong>figured and tuned, as was the case with the change in block sizes.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, all extents of an object are collectively called a segment. While the c<strong>on</strong>cept ofsegment existed in versi<strong>on</strong> 6.5, <strong>SQL</strong> <strong>Server</strong> does not have an equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g> the segmentfrom versi<strong>on</strong> 7.0 and later. The segment has no bearing <strong>on</strong> migrati<strong>on</strong> or per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.Tablespaces and DatafilesDatafiles are used <strong>to</strong> s<strong>to</strong>re persistent data in the database. For ease of management, <strong>on</strong>eor more datafiles can be grouped in<strong>to</strong> logical tablespaces. The <strong>SQL</strong> <strong>Server</strong> equivalent ofthe tablespace is the filegroup. While filegroups are similar in functi<strong>on</strong>, their organizati<strong>on</strong>differs from that of tablespaces. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespaces are at the instance level. <strong>SQL</strong> <strong>Server</strong>filegroups come under and are associated with the individual databases. Figure 5.2illustrates the tablespace <strong>to</strong> datafiles hierarchy:


80Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database ArchitectureFigure 5.2Schematic mapping of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> files and tablespaces <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 81Table 5.2 captures some of the relati<strong>on</strong>s between tablespaces in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and databasesin <strong>SQL</strong> <strong>Server</strong> that are not obvious in Figure 5.2.Table 5.2: <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Tablespaces and <strong>SQL</strong> <strong>Server</strong> Functi<strong>on</strong>al Equivalents<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>System tablespaceTemporary tablespaceUndo (Rollback) tablespaceOnline Redo log"App Data" tablespace"App Index" tablespaceN/AN/A<strong>SQL</strong> <strong>Server</strong>master databasetempdb databaseTransacti<strong>on</strong> logTransacti<strong>on</strong> log"App" database —"Data" filegroup"App" database —"Index" filegroupmodel databasemsdb databaseThe following list describes how <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> functi<strong>on</strong>ality is implemented in <strong>SQL</strong> <strong>Server</strong>:●●●●●Each of the <strong>SQL</strong> <strong>Server</strong> databases has its own security structures, such as users,privileges (permissi<strong>on</strong>s), and roles.Each of the <strong>SQL</strong> <strong>Server</strong> databases has its own administrative roles that bes<strong>to</strong>wprivileges <strong>on</strong> the database.In <strong>SQL</strong> <strong>Server</strong>, the system catalog — which is analogous <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> datadicti<strong>on</strong>ary — is broken up between the individual databases and the masterdatabase.In <strong>SQL</strong> <strong>Server</strong>, each of the databases has its own transacti<strong>on</strong> log files, whichcombine the functi<strong>on</strong>s of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong>line redo logs and rollback segments.The tempdb database provides temporary s<strong>to</strong>rage <str<strong>on</strong>g>for</str<strong>on</strong>g> the entire <strong>SQL</strong> <strong>Server</strong>instance, and the temporary tablespace in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> is comm<strong>on</strong> <strong>to</strong> the entire <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>instance.Tablespaces and filegroups provide the ability <strong>to</strong> better distribute data across multiplefiles <str<strong>on</strong>g>for</str<strong>on</strong>g> the purposes of per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. The grouping also helps ease administrati<strong>on</strong> ofbackup and recovery, maintenance, availability, and so <strong>on</strong>.Each <strong>SQL</strong> <strong>Server</strong> database is created with a primary file bel<strong>on</strong>ging <strong>to</strong> the default primaryfilegroup. Opti<strong>on</strong>ally, sec<strong>on</strong>dary datafiles can be added <strong>to</strong> the primary filegroup, oradditi<strong>on</strong>al filegroups can be created. The locati<strong>on</strong> of the files bel<strong>on</strong>ging <strong>to</strong> a database isrecorded in the master database and the primary file <str<strong>on</strong>g>for</str<strong>on</strong>g> the database. Data added <strong>to</strong>objects of a filegroup are proporti<strong>on</strong>ally filled across all files bel<strong>on</strong>ging <strong>to</strong> the filegroup.A comm<strong>on</strong> c<strong>on</strong>cern am<strong>on</strong>g users when creating <strong>SQL</strong> <strong>Server</strong> databases is the lack of themultiplexing feature available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>trol files and redo logs. This is not ac<strong>on</strong>cern because <strong>SQL</strong> <strong>Server</strong> recommends the use of striped and mirrored devices(RAID 0+1) <str<strong>on</strong>g>for</str<strong>on</strong>g> transacti<strong>on</strong> logs <strong>to</strong> preserve the level of protecti<strong>on</strong> against hardwarefailure obtained by log multiplexing. <strong>SQL</strong> <strong>Server</strong> recommends using RAID 0+1 <str<strong>on</strong>g>for</str<strong>on</strong>g> alldatabase datafiles. If RAID 0+1 cannot be implemented, at a minimum RAID 5 should beused <strong>to</strong> provide <strong>to</strong>lerance <str<strong>on</strong>g>for</str<strong>on</strong>g> hard disk failure. Apart from file systems, <strong>SQL</strong> <strong>Server</strong> alsosupports the use of raw partiti<strong>on</strong>s.S<strong>to</strong>rage Definiti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> Tables and IndexesIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the s<strong>to</strong>rage definiti<strong>on</strong> is used <strong>to</strong> specify the characteristics of tables andindexes. The following list provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> how these characteristics migrate <strong>to</strong><strong>SQL</strong> <strong>Server</strong>.


82Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Architecture●●●Physical attributes. These include PCTUSED, PCTFREE, INITRANS, andMAXTRANS. Of these parameters, <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>ly offers an equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g>PCTFREE through the FILLFACTOR clause. FILLFACTOR is available <str<strong>on</strong>g>for</str<strong>on</strong>g> indexes<strong>on</strong>ly. A PCTFREE of 10 would corresp<strong>on</strong>d <strong>to</strong> a FILLFACTOR of 90.Tablespace. This is used in a manner similar <strong>to</strong> tables. The <strong>SQL</strong> <strong>Server</strong> equivalentis the ON filegroup_name opti<strong>on</strong>. A default filegroup can be specified <str<strong>on</strong>g>for</str<strong>on</strong>g> eachdatabase, and the default filegroup functi<strong>on</strong>s similar <strong>to</strong> the default tablespace of an<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> user. If a filegroup is not specified during index creati<strong>on</strong>, the index iscreated in the default filegroup <str<strong>on</strong>g>for</str<strong>on</strong>g> the database.S<strong>to</strong>rage attributes. These override the defaults specified at the tablespace level,such as INITIAL, NEXT, MINEXTENTS, MAXEXTENTS, PCTINCREASE, and so<strong>on</strong>. Due <strong>to</strong> the fixed (64 KB) extents, these attributes have no relevance in<strong>SQL</strong> <strong>Server</strong>.Migrate System S<strong>to</strong>rage StructuresAs has already been presented in this chapter, an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database has the followingsystem structures that have a similar role in a <strong>SQL</strong> <strong>Server</strong> database. The c<strong>on</strong>figurati<strong>on</strong> ofthese structures in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database can be used <strong>to</strong> provide a starting point <str<strong>on</strong>g>for</str<strong>on</strong>g>c<strong>on</strong>figurati<strong>on</strong> in <strong>SQL</strong> <strong>Server</strong>.● System tablespace. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the system tablespace houses the data dicti<strong>on</strong>aryand the system rollback segments. The master database in <strong>SQL</strong> <strong>Server</strong> has asimilar role. The transacti<strong>on</strong> log — which also holds the rollback in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> — is ina separate file. Also, the data dicti<strong>on</strong>ary in the master database does not growbecause user object in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is s<strong>to</strong>red in the primary file of the c<strong>on</strong>taineddatabase under the decentralized data dicti<strong>on</strong>ary model of <strong>SQL</strong> <strong>Server</strong>. Themaster database also has some of the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> that is s<strong>to</strong>red in the c<strong>on</strong>trol fileof an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database. Based <strong>on</strong> these facts, it is appropriate <strong>to</strong> use the defaultmaster database settings.● Rollback or undo. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, a separate tablespace exists <str<strong>on</strong>g>for</str<strong>on</strong>g> holding rollbacksegments (manual and au<strong>to</strong> modes) whose size and number is dependent up<strong>on</strong>the number of user c<strong>on</strong>necti<strong>on</strong>s and the amount of changes being made <strong>to</strong> thedatabase. These fac<strong>to</strong>rs should be c<strong>on</strong>sidered in sizing the transacti<strong>on</strong> log in<strong>SQL</strong> <strong>Server</strong>.● Redo. There are several fac<strong>to</strong>rs <strong>to</strong> c<strong>on</strong>sider while choosing the size of atransacti<strong>on</strong> log. The source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database has more than <strong>on</strong>e schema that willbe migrated in<strong>to</strong> separate <strong>SQL</strong> <strong>Server</strong> databases. For the same transacti<strong>on</strong>, theamount of redo and rollback in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> generated in <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> isdifferent. The frequency of backup or truncati<strong>on</strong> of the transacti<strong>on</strong> log alsoinfluences the size. Hence pro<strong>to</strong>typing is the best way <strong>to</strong> size the <strong>SQL</strong> <strong>Server</strong>transacti<strong>on</strong> log.● Temporary. The size of tempdb can be initially set <strong>to</strong> a c<strong>on</strong>servative size ascompared <strong>to</strong> its <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> counterpart, the temporary tablespace. The au<strong>to</strong>-incrementfeature should be set <strong>to</strong> ensure that transacti<strong>on</strong>s do not fail due <strong>to</strong> lack of space.Setting very small increments will also affect per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance due <strong>to</strong> c<strong>on</strong>stant spaceoperati<strong>on</strong>s. The temporary space needs are based <strong>on</strong> the applicati<strong>on</strong> needs, whichmay change a little as applicati<strong>on</strong>s are migrated <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ment.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 836Developing: Databases —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasIntroducti<strong>on</strong> and GoalsThe next task is <strong>to</strong> create additi<strong>on</strong>al databases <strong>to</strong> house the applicati<strong>on</strong> schema objectsand the objects that are migrated.Apart from the architectural differences menti<strong>on</strong>ed in Chapter 5, there are alsodifferences in data models between OLTP and DSS systems. OLTP systems have morecomplex relati<strong>on</strong>s, with c<strong>on</strong>straints used <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce business rules. DSS systems havesimpler and far fewer relati<strong>on</strong>ships between tables. Despite the differences betweensystems and schema modeling techniques (such as normalized, star, and snowflake), theimplementati<strong>on</strong> of the physical schema uses the same set of objects, such as tables,indexes, and views. As a result, migrati<strong>on</strong> of the schemas and data is the same <str<strong>on</strong>g>for</str<strong>on</strong>g> allthese types. As in Chapter 5, the examples used in this chapter focus <strong>on</strong> OLTP systems,but the guidance is applicable <strong>to</strong> DSS systems, as well.A Microsoft® <strong>SQL</strong> <strong>Server</strong> database has the characteristics of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schemabecause objects can be created inside the database. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the schema and thes<strong>to</strong>rage (tablespaces) have independent identities — objects of a schema can be createdin different tablespaces, and a single tablespace can accommodate objects from multipleschemas. In this c<strong>on</strong>text, <strong>SQL</strong> <strong>Server</strong> databases are similar <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespaces — anowner can create objects in different databases, and a database can c<strong>on</strong>tain objects fromdifferent owners.In spite of this fact, the database provides a higher degree of separati<strong>on</strong> of theapplicati<strong>on</strong> data and security than is provided by schemas. <strong>SQL</strong> <strong>Server</strong> has beendesigned <str<strong>on</strong>g>for</str<strong>on</strong>g> the isolati<strong>on</strong> of administrative duties at the database level. The system(catalog and roles) has been divided, with centralized functi<strong>on</strong>s that have instance-wideauthority under the master database and database-specific functi<strong>on</strong>s under the individualdatabases.Creating a <strong>SQL</strong> <strong>Server</strong> database <str<strong>on</strong>g>for</str<strong>on</strong>g> each <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema is the ideal choice <str<strong>on</strong>g>for</str<strong>on</strong>g> thelogical separati<strong>on</strong> of objects based <strong>on</strong> the business functi<strong>on</strong> (applicati<strong>on</strong>) that is providedby the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schemas. Subsequently, the schema's objects can be created under thedatabase.Tools are available from Microsoft that can assist in this step of the database migrati<strong>on</strong>.The Microsoft <strong>SQL</strong> <strong>Server</strong> Migrati<strong>on</strong> Assistant (SSMA) provides the Schema and Data


84Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasMigra<strong>to</strong>r, which specializes in the migrati<strong>on</strong> of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. TheSSMA also provides the <strong>SQL</strong> C<strong>on</strong>verter <strong>to</strong>ol, which c<strong>on</strong>verts <strong>SQL</strong> code found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>objects (such as s<strong>to</strong>red procedures) <strong>to</strong> their T-<strong>SQL</strong> equivalents. The SSMA <strong>to</strong>ol suite canbe downloaded from http://www.microsoft.com/sql/migrati<strong>on</strong>. The beta versi<strong>on</strong> of SSMAis available as of the date of publishing this soluti<strong>on</strong>. Versi<strong>on</strong> 1.0 of SSMA is slated <strong>to</strong> beavailable in June 2005.Most <strong>to</strong>ols that are employed in the administrati<strong>on</strong> of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases are capable ofextracting object definiti<strong>on</strong>s. Toad and <strong>SQL</strong> Naviga<strong>to</strong>r from Quest, PL/<strong>SQL</strong> Developerfrom Allround Au<strong>to</strong>mati<strong>on</strong>s, Unicenter <strong>SQL</strong>-Stati<strong>on</strong> from Computer Associates, Rapid<strong>SQL</strong> from Embarcedero, and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Enterprise Manager from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are examples ofsuch <strong>to</strong>ols.Modeling <strong>to</strong>ols such as AllFusi<strong>on</strong> (Erwin) from Computer Associates and ER/Studio fromEmbarcadero can also be employed <strong>to</strong> reverse engineer the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.The goal of this chapter is <strong>to</strong> show how an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema and its objects should bemigrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. Scripts should be used <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming most of the tasks in thisstep, because scripts make the migrati<strong>on</strong> easier <strong>to</strong> execute compared <strong>to</strong> the use of GUI<strong>to</strong>ols.Scripting Migrated Schema ObjectsThe development process is built <strong>on</strong> the requirement that when the development iscomplete, the code will be in place <str<strong>on</strong>g>for</str<strong>on</strong>g> unit testing and implementati<strong>on</strong>. These scripts willallow recreati<strong>on</strong> of the objects in a reliable manner when creating the database in theStabilizing Phase and the Deploying Phase. There are some basic rules that should befollowed when scripting the database <str<strong>on</strong>g>for</str<strong>on</strong>g> promoti<strong>on</strong> <strong>to</strong> a staging envir<strong>on</strong>ment <str<strong>on</strong>g>for</str<strong>on</strong>g> unittesting:● Script everything● Provide support documentati<strong>on</strong>● Protect the scriptsEach of these basic rules is discussed under the following headings.Script EverythingScript everything associated with the database implementati<strong>on</strong>. The Generate <strong>SQL</strong> Scriptfeature of <strong>SQL</strong> <strong>Server</strong> Enterprise Manager can be used <strong>to</strong> script each database object inthe migrated database. After the scripts are created, c<strong>on</strong>duct a validati<strong>on</strong> process <strong>to</strong>verify that the number of objects scripted is the same as the number of objects that existin the development database. This process is very important because it helps <strong>to</strong> ensurethat the database being promoted <strong>to</strong> the staging envir<strong>on</strong>ment is identical <strong>to</strong> the databasein the development envir<strong>on</strong>ment.Provide Support Documentati<strong>on</strong>Provide support documentati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> each script. Comment the code <strong>to</strong> describe what ishappening in the script and include any observati<strong>on</strong>s gathered when it was last executed,such as how l<strong>on</strong>g executi<strong>on</strong> <strong>to</strong>ok and how many rows were affected.Protect the ScriptsProtecting the scripts is very important <str<strong>on</strong>g>for</str<strong>on</strong>g> the database implementati<strong>on</strong>. Treat the scriptslike producti<strong>on</strong> objects at this point. To ensure that the appropriate scripts are used whenthe database is promoted between development, staging, and producti<strong>on</strong> envir<strong>on</strong>ments,


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 85keep the scripts in a secured direc<strong>to</strong>ry or under versi<strong>on</strong> c<strong>on</strong>trol. Versi<strong>on</strong>ing is veryimportant because an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> is not a mere mapping of objectsfrom <strong>on</strong>e database <strong>to</strong> another. The differences between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> willrequire that some of the <strong>SQL</strong> statements be rewritten <str<strong>on</strong>g>for</str<strong>on</strong>g> the new envir<strong>on</strong>ment. Thesechanges in <strong>SQL</strong> will also prompt changes <strong>to</strong> the database objects and their design.These changes will be driven by the applicati<strong>on</strong> development (migrati<strong>on</strong>) process and notfrom within the database migrati<strong>on</strong> process described here. Only the development anddeployment teams should have access <strong>to</strong> the scripts.Migrate the SchemaThis secti<strong>on</strong> discusses the necessary steps in migrating the schema owner and settingup the s<strong>to</strong>rage in preparati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating the schema objects and its data.The high-level steps <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating the s<strong>to</strong>rage architecture of a schema are:1. Map the s<strong>to</strong>rage architecture.2. Create a database <str<strong>on</strong>g>for</str<strong>on</strong>g> the schema.3. Create filegroups <str<strong>on</strong>g>for</str<strong>on</strong>g> the tablespaces.4. Add datafiles <strong>to</strong> filegroups.Each of these four high-level steps is discussed in detail under the followingsubheadings.Map the S<strong>to</strong>rage ArchitectureThe first step in migrating an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema is <strong>to</strong> understand the s<strong>to</strong>rage architectureand how these architectural comp<strong>on</strong>ents will map <strong>to</strong> their equivalents in <strong>SQL</strong> <strong>Server</strong>.In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the various characteristics of the tablespaces and datafiles in which the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema is s<strong>to</strong>red has <strong>to</strong> be gathered.There are several <strong>to</strong>ols, both from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> as well as third parties, which are used inadministering <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases. Any of these <strong>to</strong>ols can be employed <strong>to</strong> gatherin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the tablespaces and datafiles. In the example migrati<strong>on</strong> that is provided atthe end of this secti<strong>on</strong>, methods <str<strong>on</strong>g>for</str<strong>on</strong>g> capturing the requisite data purely using <strong>SQL</strong> areprovided.


86Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasFigures 6.1 and 6.2 provide a view of how the s<strong>to</strong>rage objects will align in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>.Figure 6.1<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema illustratedFigure 6.2<strong>SQL</strong> <strong>Server</strong> schema equivalent


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 87Start by compiling a list of tablespaces that c<strong>on</strong>tain objects bel<strong>on</strong>ging <strong>to</strong> the schema andgather the following related in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>:● Tablespace name.● Status. The status of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespace may be either ONLINE, OFFLINE, orREAD ONLY. If a tablespace is OFFLINE, then a decisi<strong>on</strong> has <strong>to</strong> be made if it isrequired <strong>to</strong> be migrated. Data in an offline tablespace cannot be accessed and ithas <strong>to</strong> be brought <strong>on</strong>line <str<strong>on</strong>g>for</str<strong>on</strong>g> migrati<strong>on</strong>.● Tablespace c<strong>on</strong>tents. Only tablespaces whose tablespace c<strong>on</strong>tent attribute is set<strong>to</strong> PERMANENT have <strong>to</strong> be migrated.● Logging attribute. Tablespaces may be set <strong>to</strong> LOGGING or NOLOGGING, whichspecifies the default characteristic <str<strong>on</strong>g>for</str<strong>on</strong>g> bulk operati<strong>on</strong>s against the objects in thetablespace.Note In <strong>SQL</strong> <strong>Server</strong>, the attributes of status, tablespace c<strong>on</strong>tents, and logging are setat the database level and not the filegroup level. If an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema has tablespaceswith more than <strong>on</strong>e value <str<strong>on</strong>g>for</str<strong>on</strong>g> these attributes, more than <strong>on</strong>e database will have <strong>to</strong> becreated in <strong>SQL</strong> <strong>Server</strong>. For example, if a schema uses two tablespaces (<strong>on</strong>e isONLINE and the other READ ONLY), then the two tablespaces have <strong>to</strong> be mapped <strong>to</strong>two separate databases in <strong>SQL</strong> <strong>Server</strong>. The two databases can then be set <strong>to</strong> ONLINEand READ_ONLY, respectively, using the state opti<strong>on</strong>s available in <strong>SQL</strong> <strong>Server</strong>.Gather the following in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the datafiles in the tablespaces:● File name● File size● File au<strong>to</strong>extensibility● Maximum file size● File au<strong>to</strong> extensi<strong>on</strong> incrementFrom the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> gathered about tablespaces and their datafiles, produce a map <str<strong>on</strong>g>for</str<strong>on</strong>g>the databases, filegroups. and datafiles <strong>to</strong> be created in <strong>SQL</strong> <strong>Server</strong> as shown in Figure6.2.Create Databases <str<strong>on</strong>g>for</str<strong>on</strong>g> the SchemaTo migrate the schemas from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, databases are created in <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> theschemas. The databases will hold the schema objects and their data. This secti<strong>on</strong>provides details <strong>on</strong> how <strong>to</strong> create databases in <strong>SQL</strong> <strong>Server</strong>.To an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBA, creating a database means creating an entire database system thatc<strong>on</strong>tains c<strong>on</strong>trol files, redo logs, data dicti<strong>on</strong>ary and temporary tablespace. In<strong>SQL</strong> <strong>Server</strong>, these tasks are accomplished as part of the installati<strong>on</strong> process. Hencecreating a database in <strong>SQL</strong> <strong>Server</strong> implies adding a user database <strong>to</strong> the already existingsystem databases. Members of the fixed server roles sysadmin and dbcrea<strong>to</strong>r, or anyuser with such privileges, can create a database. By default, the crea<strong>to</strong>r of the databasebecomes the owner of the database.Databases can be created either through Enterprise Manager or by using the CREATEDATABASE T-<strong>SQL</strong> command. Only members of the sysadmin and dbcrea<strong>to</strong>r fixedserver roles or users who have been granted the CREATE DATABASE permissi<strong>on</strong> cancreate a new database.The following basic characteristics of the database have <strong>to</strong> be decided be<str<strong>on</strong>g>for</str<strong>on</strong>g>e creating adatabase:


88Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas●●●●●●Database name. Naming is c<strong>on</strong>strained by the same rules as identifiers. Ameaningful name can be used and need not be the same as the name of the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema being migrated.Database owner. By default, the user who created the database becomes thedatabase owner (dbo). The owner can be changed using sp_changedbowner. Tomimic the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema, a login with the same name as the schema can bemade the database owner. A more detailed account of the implicati<strong>on</strong>s of databaseowner and database object owner is provided in the "Qualifiers and NameResoluti<strong>on</strong>" secti<strong>on</strong> later in this chapter.Filegroups. These are the equivalents of tablespaces. A default primary filegroupis created during the database creati<strong>on</strong>.Primary file. Every database is created with a default primary file bel<strong>on</strong>ging <strong>to</strong> thedefault primary filegroup identifiable by the .mdf file name extensi<strong>on</strong>. The primaryfile c<strong>on</strong>tains startup in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the database and is used <strong>to</strong> s<strong>to</strong>re user data justas any other datafile. Only the size and growth characteristics can be changed.Sec<strong>on</strong>dary files. Additi<strong>on</strong>al files can be created in a database and associated withthe primary file group or any additi<strong>on</strong>al filegroup. The recommended file nameextensi<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> sec<strong>on</strong>dary files is .ndf.Transacti<strong>on</strong> log. Hold rollback and redo in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> required <strong>to</strong> recover thedatabase. Notice that, unlike <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, where rollback segments and redo logs arecentral <strong>to</strong> the instance, every database has at least <strong>on</strong>e transacti<strong>on</strong> log.Transacti<strong>on</strong> logs are not part of any filegroup.There are two ways <strong>to</strong> create a new database using Enterprise Manager: using theDatabase Properties dialog and by using the Create Database Wizard. An example ofeach of these procedures is provided here. To create a database using the Database Properties dialog, follow thesesteps:1. Right-click Databases, and then left-click New Database, or right-click <strong>Server</strong>(<strong>Server</strong> Name\Instance Name), then right-click New, and then left-click Database.2. In the Database Properties window, enter the database name in the Generalpane, the datafile and filegroup c<strong>on</strong>figurati<strong>on</strong> in the Data Files pane, and thetransacti<strong>on</strong> log c<strong>on</strong>figurati<strong>on</strong> in the Transacti<strong>on</strong> Log pane. To create a new database using the Create Database Wizard, follow thesesteps:1. Expand a server group, and then expand the server in which <strong>to</strong> create a database.2. On the Tools menu, click Wizards.3. Expand Database.4. Double-click Create Database Wizard.5. Complete the steps in the wizard.<strong>SQL</strong> <strong>Server</strong> also offers the CREATE DATABASE statement <str<strong>on</strong>g>for</str<strong>on</strong>g> creating databases.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 89 To create a database using the T-<strong>SQL</strong> CREATE DATABASE statement, use thefollowing syntax:CREATE DATABASE database_name[ ON][ < filespec > [ ,...n ] ][ , < filegroup > [ ,...n ] ][ LOG ON { < filespec > [ ,...n ] } ][ COLLATE collati<strong>on</strong>_name ][ FOR LOAD | FOR ATTACH ]< filespec > ::=[ PRIMARY ]( [ NAME = logical_file_name , ]FILENAME = 'os_file_name'[ , SIZE = size ][ , MAXSIZE = { max_size | UNLIMITED } ][ , FILEGROWTH = growth_increment ] ) [ ,...n ]< filegroup > ::=FILEGROUP filegroup_name < filespec > [ ,...n ]C<strong>on</strong>figure the Databases<strong>SQL</strong> <strong>Server</strong> is very similar <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> in its architecture and can be similarly c<strong>on</strong>figured. Inthe discussi<strong>on</strong> of system c<strong>on</strong>figurati<strong>on</strong> opti<strong>on</strong>s, several opti<strong>on</strong>s that apply <strong>to</strong> the individualdatabases but are set at the instance level are discussed. These opti<strong>on</strong>s apply uni<str<strong>on</strong>g>for</str<strong>on</strong>g>mly<strong>to</strong> all databases in the instance. In c<strong>on</strong>trast, the following five different sets of opti<strong>on</strong>s areset at the database level and apply <strong>on</strong>ly <strong>to</strong> the targeted database.● Au<strong>to</strong> opti<strong>on</strong>s● Cursor opti<strong>on</strong>s● Recovery opti<strong>on</strong>s● <strong>SQL</strong> opti<strong>on</strong>s● State opti<strong>on</strong>sThese opti<strong>on</strong>s are set using the ALTER DATABASE statement. A subset of the availableopti<strong>on</strong>s can be set using Enterprise Manager. For a descripti<strong>on</strong> of each of these opti<strong>on</strong>s,refer <strong>to</strong> http://msdn.microsoft.com/library/default.asp?url=/library/enus/createdb/cm_8_des_03_6ohf.asp.If the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database is in NOARCHIVELOG mode, then the Simple Recoverymodel is chosen <str<strong>on</strong>g>for</str<strong>on</strong>g> the database and the Full Recovery model is used if the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database is in ARCHIVELOG mode. If the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespace is in read-<strong>on</strong>ly mode, thenthe corresp<strong>on</strong>ding database created in <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> that database has <strong>to</strong> be set <strong>to</strong>read-<strong>on</strong>ly mode. Similarly, if the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespace is offline, the corresp<strong>on</strong>ding databasecan be taken offline after the migrati<strong>on</strong> is complete. If logging has been turned off <str<strong>on</strong>g>for</str<strong>on</strong>g> the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespace, then set the recovery model <str<strong>on</strong>g>for</str<strong>on</strong>g> the database <strong>to</strong> BULK_LOGGED.An overview of the <strong>SQL</strong> <strong>Server</strong> recovery models is available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/dnsqlmag2k/html/dbRecovery.asp.


90Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasCreate Filegroups <str<strong>on</strong>g>for</str<strong>on</strong>g> the TablespacesFilegroups in <strong>SQL</strong> <strong>Server</strong> are similar <strong>to</strong> tablespaces in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. They are used <strong>to</strong> logicallygroup s<strong>to</strong>rage. When a database is created in <strong>SQL</strong> <strong>Server</strong>, it has <strong>on</strong>e filegroup bydefault. Based <strong>on</strong> the number of tablespaces that the schema uses, additi<strong>on</strong>al filegroupshave <strong>to</strong> be created in the newly created database.Every database is created with a default primary filegroup that cannot be renamed ordropped. As a result, <strong>on</strong>e of the tablespaces will have <strong>to</strong> map <strong>to</strong> the primary filegroupduring migrati<strong>on</strong>. Additi<strong>on</strong>al sec<strong>on</strong>dary or user filegroups can be created with userspecifiednames.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, tablespaces are created as locally managed or dicti<strong>on</strong>ary managed. The typeof tablespace determines what s<strong>to</strong>rage parameters can be used. Creating filegroups issimilar <strong>to</strong> creating tablespaces under <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> except that a filegroup is added <strong>to</strong> a specific<strong>SQL</strong> <strong>Server</strong> database. Filegroups added <strong>to</strong> a database are called sec<strong>on</strong>dary filegroups,and they can be added <strong>to</strong> any database. Datafiles are added separately from thedefiniti<strong>on</strong> of a filegroup.The following two opti<strong>on</strong>s are available <str<strong>on</strong>g>for</str<strong>on</strong>g> creating a filegroup. To create a filegroup using Enterprise Manager, follow these steps:1. Expand Databases and right-click Properties of the database <strong>to</strong> which thefilegroup has <strong>to</strong> be added.2. In the Database Properties window, left-click the Filegroups pane.3. Type the filegroup name in the next available empty line that follows the filegrouplisting. To add a filegroup <strong>to</strong> a database using T-<strong>SQL</strong>, execute the followingstatement:ALTER DATABASE database_nameADD FILEGROUP filegroup_nameAdd Datafiles <strong>to</strong> FilegroupsS<strong>to</strong>rage has <strong>to</strong> be allocated in the <strong>SQL</strong> <strong>Server</strong> database <strong>to</strong> meet the requirements of theschema being migrated. Datafiles are added <strong>to</strong> filegroups much as datafiles are added <strong>to</strong>tablespaces in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.Adding a datafile in <strong>SQL</strong> <strong>Server</strong> is similar <strong>to</strong> the process used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Thecharacteristics that can be set are related <strong>to</strong> au<strong>to</strong>-growth and are similar in functi<strong>on</strong> <strong>to</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s AUTOEXTEND feature. An additi<strong>on</strong>al characteristic that does not exist in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>is the logical file name.Datafiles can be added <strong>to</strong> the primary filegroup as well as any sec<strong>on</strong>dary filegroups eitherthrough Enterprise Manager or using T-<strong>SQL</strong>. To add a datafile by using Enterprise Manager, follow these steps:1. Expand Databases and right-click Properties of the database <strong>to</strong> which thefilegroup has <strong>to</strong> be added.2. In the Database Properties window, left-click the Data Files pane.3. Add file in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in the next available empty line in the file listing. In the filegroupcolumn, select the filegroup name from the drop-down list. Also set the growthcharacteristics <str<strong>on</strong>g>for</str<strong>on</strong>g> the file.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 91 To add a datafile <strong>to</strong> the primary filegroup or sec<strong>on</strong>dary filegroups using T-<strong>SQL</strong>, use the following syntax:ALTER DATABASE database{ ADD FILE < filespec > [ ,...n ] [ TO FILEGROUP filegroup_name ]where ::=( NAME = logical_file_name[ , FILENAME = 'os_file_name' ][ , SIZE = size ][ , MAXSIZE = { max_size | UNLIMITED } ][ , FILEGROWTH = growth_increment ] )The TO FILEGROUP clause is not required <strong>to</strong> add datafiles <strong>to</strong> the primary filegroup.Add Transacti<strong>on</strong> LogsIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> transacti<strong>on</strong>s and the changes they make is recorded in redologs. The redo logs are comm<strong>on</strong> <strong>to</strong> the entire instance. In <strong>SQL</strong> <strong>Server</strong>, transacti<strong>on</strong>alchanges are logged in the transacti<strong>on</strong> log <str<strong>on</strong>g>for</str<strong>on</strong>g> the database whose objects are involved inthe transacti<strong>on</strong>. A database is created with a single default transacti<strong>on</strong> log. The defaulttransacti<strong>on</strong> log has <strong>to</strong> be sized or new <strong>on</strong>es added based <strong>on</strong> the update activity againstthe database.Transacti<strong>on</strong> logs can be added using a process similar <strong>to</strong> that used <str<strong>on</strong>g>for</str<strong>on</strong>g> adding datafiles,as shown in the following procedure. To add a datafile by using Enterprise Manager, follow these steps:1. Expand Databases and right-click Properties of the database <strong>to</strong> which thetransacti<strong>on</strong> log has <strong>to</strong> be added.2. In the Database Properties window, left-click the Transacti<strong>on</strong> Log pane.3. Add the transacti<strong>on</strong> log file in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in the next available empty line in the filelisting. Also set the growth characteristics. To add a transacti<strong>on</strong> log <strong>to</strong> a database using T-<strong>SQL</strong>, use the following syntax:ALTER DATABASE database{ ADD LOG FILE < filespec > [ ,...n ]where ::=( NAME = logical_file_name[ , FILENAME = 'os_file_name' ][ , SIZE = size ][ , MAXSIZE = { max_size | UNLIMITED } ][ , FILEGROWTH = growth_increment ] )Sample Schema Migrati<strong>on</strong>This secti<strong>on</strong> describes an example schema migrati<strong>on</strong> using the four steps that have beendescribed earlier. The HR schema that is bundled with the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> installati<strong>on</strong> software isused <strong>to</strong> illustrate the steps in migrating a schema. The s<strong>to</strong>rage characteristics of thetablespaces used by the HR schema have been modified <strong>to</strong> dem<strong>on</strong>strate some of the


92Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemassteps that would be comm<strong>on</strong> in migrati<strong>on</strong>s. This example is c<strong>on</strong>ducted using the featuresand <strong>to</strong>ols offered by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> and no third-party <strong>to</strong>ol is employed.1. Extract the schema s<strong>to</strong>rage requirements by following these substeps:a. Produce a listing of tablespaces in which the schema has objects by using thefollowing statement:SELECT DISTINCT tablespace_name "TABLESPACE NAME"FROM dba_segmentsWHERE owner = 'HR'The owner in the statement is the name of the schema <strong>to</strong> be migrated. Theoutput is as follows:TABLESPACE NAME____________________________________________________________EXAMPLEINDXb. Obtain the characteristics of each of the tablespaces using the followingstatement:SELECT tablespace_name, status, c<strong>on</strong>tents, loggingFROM dba_tablespacesWHERE tablespace_name IN (SELECT DISTINCT tablespace_nameFROM dba_segmentsWHERE owner = 'HR')The owner in the statement is the name of the schema <strong>to</strong> be migrated. Theoutput is as follows:TABLESPACE_NAME STATUS CONTENTS LOGGING_______________________________________________________EXAMPLE ONLINE PERMANENT LOGGINGINDX ONLINE PERMANENT LOGGINGc. Find the datafiles associated with the tablespaces using the followingstatement:SELECT tablespace_name "TS NAME",file_name "FILE NAME", bytes/1024/1024 "SIZE MB",au<strong>to</strong>extensible, maxbytes/1024/1024 "MAX SIZE MB",increment_by*8192/1024/1024 "INCR SIZE MB"FROM dba_data_filesWHERE tablespace_name IN (SELECT DISTINCT tablespace_nameFROM dba_segmentsWHERE owner = 'HR')The owner in the statement is the name of the schema <strong>to</strong> be migrated. Theoutput is as follows:TS NAME FILE NAME SIZE AUTO MAX SZ INCR________________________________________________________________________EXAMPLE /u02/oradata/oracle92/example01.dbf 1000 YES 1000 100EXAMPLE /u02/oradata/oracle92/example02.dbf 100 YES 1000 100INDX /u03/oradata/oracle92/indx01.dbf 1000 YES 1000 50INDX /u03/oradata/oracle92/indx02.dbf 50 YES 1000 50Note The output has been re<str<strong>on</strong>g>for</str<strong>on</strong>g>matted <strong>to</strong> fit the page.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 93Figures 6.1 and 6.2 provide schematics <str<strong>on</strong>g>for</str<strong>on</strong>g> the hierarchical organizati<strong>on</strong> ofs<strong>to</strong>rage in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. Terminologies such as schema, database,tablespace, filegroup, datafile and transacti<strong>on</strong> log are used here. These figuresare modified in Figure 6.3 and Figure 6.4 <strong>to</strong> show instances <str<strong>on</strong>g>for</str<strong>on</strong>g> theterminologies based <strong>on</strong> the HR schema:Figure 6.3<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> s<strong>to</strong>rage map <str<strong>on</strong>g>for</str<strong>on</strong>g> sample HR schemaFigure 6.4Equivalent <strong>SQL</strong> <strong>Server</strong> s<strong>to</strong>rage map <str<strong>on</strong>g>for</str<strong>on</strong>g> sample HR schemaNote Instead of putting the HR_DATA files under the required PRIMARYfilegroup, a separate HR_DATA filegroup can be created. This helps make thefilegroup and datafiles correlati<strong>on</strong> easier.2. Create and c<strong>on</strong>figure a new database in the <strong>SQL</strong> <strong>Server</strong> instance <strong>to</strong> hold theschema objects.a. Create the database.


94Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasCreate the database with s<strong>to</strong>rage attributes selected using the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>gathered in step 1. The locati<strong>on</strong> of the files is dependent <strong>on</strong> the file system ofthe target Windows® server <strong>on</strong> which <strong>SQL</strong> <strong>Server</strong> is installed.Create the database using the following commands:USE masterGOCREATE DATABASE HRDATAON PRIMARY( NAME='HRDATA_01',FILENAME='E:\mssql\Mssql$corp1\data\hr_data_01.mdf',SIZE=1000MB,FILEGROWTH=0)LOG ON( NAME='HRDATA_LOG_01',FILENAME='G: \mssql\Mssql$corp1\log\hr_log_01.ldf',SIZE=10MB,MAXSIZE=100MB,FILEGROWTH=10)GOAll filegroups and files (data and transacti<strong>on</strong> log) can be added at the time ofcreati<strong>on</strong> of the database. The following is the syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> doing this:USE masterGOCREATE DATABASE HRDATAON PRIMARY( NAME='HRDATA_01',FILENAME='E:\ mssql\Mssql$corp1\data\hr_data_01.mdf',SIZE=1000MB,FILEGROWTH=0),( NAME='HRDATA_ 02',FILENAME='E:\mssql\Mssql$corp1\data\hr_data_02.ndf',SIZE=100MB,MAXSIZE=1000MB,FILEGROWTH=100MB),FILEGROUP HR_INDX( NAME='HRINDX_01',FILENAME='F:\mssql\ Mssql$corp1\data\hr_indx_01.ndf',SIZE=1000MB,FILEGROWTH=0) ,( NAME='HRINDX_02',LOG ONFILENAME='F:\mssql\Mssql$corp1\data\hr_indx_02.ndf',SIZE=100MB,MAXSIZE=1000MB,FILEGROWTH=50MB)( NAME='HRDATA_LOG_01',FILENAME='G:\mssql\Mssql$corp1\log\hr_log_01.ldf',SIZE=10MB,MAXSIZE=100MB,


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 95b.GOFILEGROWTH=10)If the database is in ARCHIVELOG mode, then set the database <strong>to</strong> SimpleRecovery model; if it is in NOARCHIVELOG mode, then set <strong>to</strong> Full Recoverymodel. If the tablespace corresp<strong>on</strong>ding <strong>to</strong> the database is in NOLOGGINGmode, set the database <strong>to</strong> Bulk-Logged Recovery model. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong><strong>on</strong> the recovery models available in <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_bkprst_4l83.aspIf the tablespace is in read <strong>on</strong>ly or offline mode, set the database <strong>to</strong> therespective mode after migrati<strong>on</strong> of the schema and data is complete.In this example, <strong>on</strong>ly the required primary filegroup with a primary file and thetransacti<strong>on</strong> log are created as part of the database creati<strong>on</strong>, and additi<strong>on</strong>alfilegroups and files are added in subsequent steps <strong>to</strong> enable dem<strong>on</strong>strati<strong>on</strong> offuncti<strong>on</strong>s such as adding filegroups and data files.C<strong>on</strong>figure the database.The mode <str<strong>on</strong>g>for</str<strong>on</strong>g> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database can be found using the following query:SELECT log_modeFROM v$database3. Add sec<strong>on</strong>dary filegroups.The HR_INDX filegroup can be added using the following commands:Use masterGOALTER DATABASE HRDATAADD FILEGROUP HR_INDXGO4. Add sec<strong>on</strong>dary datafiles.The Filename, Current Size, Au<strong>to</strong>extensibility, Max Size, and Increment Sizevalues retrieved from the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database are used in creating similar datafiles <str<strong>on</strong>g>for</str<strong>on</strong>g>the HRDATA database. The primary file has already been created <strong>to</strong> match thefirst file in the HR_DATA tablespace.Create additi<strong>on</strong>al datafiles <str<strong>on</strong>g>for</str<strong>on</strong>g> the filegroups using the following commands:ALTER DATABASE HRDATAADD FILE( NAME='HRDATA_02',FILENAME='E:\mssql\Mssql$corp1\data\hr_data_02.ndf',SIZE=100MB,MAXSIZE=1000MB,FILEGROWTH=100MB)GOALTER DATABASE HRDATAADD FILE( NAME='HRINDX_01',FILENAME='F:\mssql\Mssql$corp1\data\hr_indx_01.ndf',SIZE=1000MB,FILEGROWTH=0),( NAME='HRINDX_02',FILENAME='F:\mssql\Mssql$corp1\data\hr_indx_02.ndf',SIZE=100MB,


96Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasMAXSIZE=1000MB,FILEGROWTH=50MB)TO FILEGROUP HR_INDXGOIn this example, the focus was restricted <strong>to</strong> migrating a single schema. When migratingan entire database c<strong>on</strong>sisting of multiple schemas, the s<strong>to</strong>rage decisi<strong>on</strong>s will have <strong>to</strong> bemade using the best practices in s<strong>to</strong>rage allocati<strong>on</strong> that were followed in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Placetemporary files <strong>on</strong> separate devices, separate data and log files, separate data and indexfiles, distribute I/O load across all available decisi<strong>on</strong>s, and separate tables with highactivity <strong>on</strong><strong>to</strong> separate devices.For descripti<strong>on</strong>s of best practices <str<strong>on</strong>g>for</str<strong>on</strong>g> the s<strong>to</strong>rage comp<strong>on</strong>ent of <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong> thesecti<strong>on</strong> titled "Optimizing the S<strong>to</strong>rage Comp<strong>on</strong>ent" athttp://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/enus/part10/c3361.mspx.Multiple schemas comm<strong>on</strong>ly share tablespaces in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases. C<strong>on</strong>ceptually,<strong>SQL</strong> <strong>Server</strong> databases can be viewed more like <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespaces, and objects frommultiple schemas can be created in the same database. From this perspective,<strong>SQL</strong> <strong>Server</strong> databases functi<strong>on</strong> similarly <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tablespaces. Figure 6.5 shows therelati<strong>on</strong> between schemas and tablespaces, where a schema's objects can be in multipletablespaces and a tablespace can have objects from multiple schemas.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 97Figure 6.5Sharing of tablespaces/databases by multiple schemas/owners


98Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasMigrate the Schema ObjectsIn the "Migrate the Schema" secti<strong>on</strong> earlier in this chapter, the focus was limited <strong>to</strong> theschema and its s<strong>to</strong>rage structures. This focus culminated in creati<strong>on</strong> of databases withappropriate filegroups and datafiles. The database merely <str<strong>on</strong>g>for</str<strong>on</strong>g>ms the shell in which theschema objects will be enclosed. In this secti<strong>on</strong>, the following high-level steps inmigrating the schema objects are taken. These steps cover tasks related <strong>to</strong> schemaobjects and security.1. Create the schema owner.2. Create the schema objects.These steps are discussed in detail under the following subheadings.Create the Schema OwnerA schema owner in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> is a user with privileges <strong>to</strong> create objects. This is true in<strong>SQL</strong> <strong>Server</strong> as well. A user will have <strong>to</strong> be created in <strong>SQL</strong> <strong>Server</strong> in the database inwhich the schemas objects will be created. The user is then given privileges in thedatabase <strong>to</strong> create objects and populate the data.Users of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> databases can be classified as administrative users,applicati<strong>on</strong> users, and schema owners.● Administrative users are users with special roles, such as database administra<strong>to</strong>rand security administra<strong>to</strong>r.● Applicati<strong>on</strong> users are users who manipulate data in the owning user's tables.● Schema owners are users who create and maintain objects related <strong>to</strong> anapplicati<strong>on</strong>.The basics <str<strong>on</strong>g>for</str<strong>on</strong>g> the creati<strong>on</strong> of all the three types of users are the same and are discussedin detail here. This knowledge is useful in creating applicati<strong>on</strong> users and administrativeusers in Chapter 7, "Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Users."A discussi<strong>on</strong> of user accounts <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the categories of users is presented in the res<strong>to</strong>f this secti<strong>on</strong>. This discussi<strong>on</strong> covers the differences in the logins between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong> and the associated authenticati<strong>on</strong> and password functi<strong>on</strong>ality.AccountsIn terms of logins, all three types of users are created equal and are differentiated <strong>on</strong>ly bythe privileges they are bes<strong>to</strong>wed. However, keeping with the practice of isolati<strong>on</strong> andaut<strong>on</strong>omy of user databases, logins are implemented a little differently in <strong>SQL</strong> <strong>Server</strong>. Itis important <strong>to</strong> understand this difference be<str<strong>on</strong>g>for</str<strong>on</strong>g>e starting the migrati<strong>on</strong> of schemas andusers. <strong>SQL</strong> <strong>Server</strong> has two levels (not types) of logins. In additi<strong>on</strong> <strong>to</strong> the instance login,<strong>SQL</strong> <strong>Server</strong> requires separate logins be created <str<strong>on</strong>g>for</str<strong>on</strong>g> each database that the user orschema needs <strong>to</strong> c<strong>on</strong>nect <strong>to</strong>.To avoid c<strong>on</strong>fusi<strong>on</strong> while referring <strong>to</strong> these various logins and accounts, this guide usesthe following terminologies comm<strong>on</strong>ly employed <str<strong>on</strong>g>for</str<strong>on</strong>g> the various logins in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> — Instance Level — user or username● <strong>SQL</strong> <strong>Server</strong> — Instance Level — login (login ID)● <strong>SQL</strong> <strong>Server</strong> — Database Level — user


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 99Logins provide access <strong>to</strong> the instance of <strong>SQL</strong> <strong>Server</strong>, whereas the user account c<strong>on</strong>trolsprivileges <strong>to</strong> objects inside the database. Figure 6.6 illustrates these relati<strong>on</strong>ships.Figure 6.6Migrati<strong>on</strong> of schema owner security from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>The migrati<strong>on</strong> of a schema owner from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> requires a login be createdat the instance level and a user be created at the database level. The impact of thisarchitectural change is observed in how objects are qualified. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, a schema objectis identified in <strong>SQL</strong> statements using schema.object_name. While migrating <strong>to</strong><strong>SQL</strong> <strong>Server</strong> the schema object has <strong>to</strong> be fully qualified as database.owner.object_name.Even though there is no difference between the login aspects of the different types ofusers, <strong>on</strong>ly the schema owners and their migrati<strong>on</strong> are discussed here. A discussi<strong>on</strong> ofapplicati<strong>on</strong> users and administrative users is postp<strong>on</strong>ed <strong>to</strong> the next task of the databasemigrati<strong>on</strong>, migrating the user, which is discussed in Chapter 7, "Developing: Databases —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Users."Authenticati<strong>on</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> offers several opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> the authenticati<strong>on</strong> of users. The two popular methods inuse are authenticati<strong>on</strong> by the database and authenticati<strong>on</strong> by the operating system. In<strong>SQL</strong> <strong>Server</strong>, the database mode is called <strong>SQL</strong> <strong>Server</strong> Authenticati<strong>on</strong> Mode and theoperating system mode is called Windows Authenticati<strong>on</strong> Mode. The databaseauthenticati<strong>on</strong> modes in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> are closely compatible and use a username and password pair. The operating system authenticati<strong>on</strong> is quite different between<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s operating system mode can <strong>on</strong>ly authenticate userswith local accounts <strong>on</strong> <strong>UNIX</strong> servers. Windows authenticati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> is actuallyper<str<strong>on</strong>g>for</str<strong>on</strong>g>med by the domain and not the local account <strong>on</strong> the Windows server.Password ManagementThe <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> RDBMS also provides password management functi<strong>on</strong>s, such as accountlocking, password lifetime and expirati<strong>on</strong>, password his<strong>to</strong>ry, and password complexityverificati<strong>on</strong>. The <strong>SQL</strong> <strong>Server</strong> RDBMS does not provide these services, and Windowssecurity is used <strong>to</strong> provide these features.Hence the migrati<strong>on</strong> of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> user names <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> logins and users is dependent<strong>on</strong> the type of authenticati<strong>on</strong> in use as well as the requirements of password


100 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemasmanagement. Table 6.1 shows the migrati<strong>on</strong> opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> logins based <strong>on</strong>authenticati<strong>on</strong> mode and the requirements <strong>on</strong> password management functi<strong>on</strong>ality.Table 6.1: Login Migrati<strong>on</strong> Based <strong>on</strong> Authenticati<strong>on</strong> Requirements<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Authenticati<strong>on</strong>Mode<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> PasswordManagementDatabase N<strong>on</strong>e DatabaseDatabase Required WindowsOperating system N/A Windows<strong>SQL</strong> <strong>Server</strong>Authenticati<strong>on</strong> ModeAs a practice, the schema owner login should not be used <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>necti<strong>on</strong> by theapplicati<strong>on</strong> instance (three-tier) or the applicati<strong>on</strong> users (two-tier and three-tier). Hence a<strong>SQL</strong> <strong>Server</strong> authenticated login would be appropriate. However, <str<strong>on</strong>g>for</str<strong>on</strong>g> clients who restrictauthenticati<strong>on</strong> <strong>to</strong> Windows mode <strong>on</strong>ly because of security c<strong>on</strong>cerns, a domain loginshould be created <str<strong>on</strong>g>for</str<strong>on</strong>g> the schema owner.Based <strong>on</strong> the security model — either Windows users or groups — review the guidelinesin th e "<strong>SQL</strong> <strong>Server</strong> 2000 SP3 Security Features and Best Practices" white paperavailable athttp://www.microsoft.com/sql/techinfo/administrati<strong>on</strong>/2 000/security/securityWP.asp <strong>to</strong>assist with implementati<strong>on</strong>.The following <strong>SQL</strong> statement can be used <strong>to</strong> extract the characteristics of the schemaowner account in the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database:SELECT du.username,DECODE(du.password,'EXTERNAL','EXTERNAL','DB')"AUTHENTICATION MODE",du.default_tablespace, du.temporary_tablespace,dp.resource_name, dp.limitFROM dba_users du, dba_profiles dpWHERE du.profile = dp.profileAND dp.resource_type = 'PASSWORD'<strong>SQL</strong> <strong>Server</strong> does not have a CREATE USER statement. There are two system s<strong>to</strong>redprocedures <strong>to</strong> add logins <str<strong>on</strong>g>for</str<strong>on</strong>g> the two modes of authenticati<strong>on</strong>, and a separate s<strong>to</strong>redprocedure <strong>to</strong> add users at the database level.It is possible <strong>to</strong> add a new login <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> using Enterprise Manager and systems<strong>to</strong>red procedures. T o add a new login <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> instance using Enterprise Manager:1. Expand the <strong>SQL</strong> <strong>Server</strong> Group and expand the <strong>Server</strong> (<strong>Server</strong> Name\InstanceName).2. Expand Security, right-click Logins, and then click New Login.3. Provide the login name and authenticati<strong>on</strong> method in the General pane. Systemand database level privileges can be granted through fixed roles under the <strong>Server</strong>Roles pane. Object-level privileges can be granted either directly or through userroles in the Database Access pane.If the user is <strong>to</strong> be authenticatedby the domain, the correct domain should bepicked using the drop-down menu under Windows Authenticati<strong>on</strong> in the Generalpane. If domain authenticati<strong>on</strong> is used, the name of the login is in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m Domainname\Domain login name. The default database that the user will c<strong>on</strong>nect <strong>to</strong> whenc<strong>on</strong>necting <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> can be set under the Defaults heading in the Generalpane. This is different from the default tablespace setting <str<strong>on</strong>g>for</str<strong>on</strong>g> a user in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 101By checking the appropriate database, the new user can be granted privileges <strong>on</strong> specificdatabases in the <strong>SQL</strong> <strong>Server</strong> instance by checking the appropriate database in theDatabase Access pane. This acti<strong>on</strong> also creates user accounts of the same name in therespective databases. For a schema owner, the db_owner role has <strong>to</strong> be granted <str<strong>on</strong>g>for</str<strong>on</strong>g> theprivilege of creating objects in the target database. The db_owner role has completeadministrative authority over the database and can be c<strong>on</strong>sidered <strong>to</strong> be similar <strong>to</strong> the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> dba role but restricted <strong>to</strong> a single <strong>SQL</strong> <strong>Server</strong> database. To give the <strong>SQL</strong> <strong>Server</strong>database object owner equivalent of the resource role in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, which grants DDLprivileges, the database role db_ddladmin can be used. <strong>SQL</strong> <strong>Server</strong> also has theCREATE TABLE, CREATE TRIGGER, CREATE VIEW and CREATE PROCEDUREroles that can be used <strong>to</strong> further curtail the capabilities of the schema owner. To add a new Windows authenticated login <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> instance using T-<strong>SQL</strong>, use the following syntax:sp_grantlogin[ @loginame = ] 'login_name'where login_name is of the <str<strong>on</strong>g>for</str<strong>on</strong>g>m domain_name\domain_login_name To add a new database authenticated login <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> instance using T-<strong>SQL</strong>, use the following syntax:sp_addlogin [ @loginame = ] 'login_name'[ , [ @passwd = ] 'password' ][ , [ @defdb = ] 'database_name' ][ , [ @encryp<strong>to</strong>pt = ] 'encrypti<strong>on</strong>_opti<strong>on</strong>' ]where database_name specifies the database the login c<strong>on</strong>nects <strong>to</strong> after logging in(default database). While passwords are encrypted in <strong>SQL</strong> <strong>Server</strong> by default, the opti<strong>on</strong>exists <strong>to</strong> skip encrypti<strong>on</strong> <strong>to</strong> allow cus<strong>to</strong>m password encrypti<strong>on</strong> by the applicati<strong>on</strong> using adifferent algorithm.A user account should be created separately <str<strong>on</strong>g>for</str<strong>on</strong>g> the login in the default database. To create a user account <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database using T-<strong>SQL</strong>, use thefollowing syntax:sp_grantdbaccess [ @loginame = ] 'login_name'[, [ @name_in_db = ] 'user_name'The name chosen <str<strong>on</strong>g>for</str<strong>on</strong>g> the user account can be different from that <str<strong>on</strong>g>for</str<strong>on</strong>g> the login account.Some of the other characteristics associated with a user or schema owner in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> thatneed <strong>to</strong> be addressed are:● De fault tablespace. In <strong>SQL</strong> <strong>Server</strong>, a default filegroup can be set <str<strong>on</strong>g>for</str<strong>on</strong>g> eachda tabase which has the same functi<strong>on</strong> and effect as the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> default tablespaceusing the following syntax.ALTER DATABASE database_nameMODIFY FILEGROUP filegroup_name DEFAULT● Temporary tablespace. By default, all users of <strong>SQL</strong> <strong>Server</strong> use the tempdbdatabase.● Tablespa ce quota. Quotas cannot be set in <strong>SQL</strong> <strong>Server</strong> at the instance,database, or filegrouplevel.


102 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasCreate the Schema ObjectsThis secti<strong>on</strong> discusses the migrati<strong>on</strong> of the schema objects from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.The following is a complete list of objects that are classified by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> as schema objects:●●●●●●●●●●●●●●●●TablesClustersObject TablesIndex-organized TablesC<strong>on</strong>straintsTriggersIndexesViewsObject ViewsFuncti<strong>on</strong>sS<strong>to</strong>red ProceduresPackagesSyn<strong>on</strong>ymsSequencesDatabase LinksObject TypesTable 6.2 provides a high-level view of how the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema objects map <strong>to</strong><strong>SQL</strong> <strong>Server</strong>.Table 6.2: <strong>SQL</strong> <strong>Server</strong> Objects that Replace <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Schema Objects<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>TableClusterObject TableIndex-organized TableC<strong>on</strong>straintsTriggersIndexViewObject ViewSyn<strong>on</strong>ymSequenceDatabase LinkObject TypesProcedureFuncti<strong>on</strong>Package<strong>SQL</strong> <strong>Server</strong>TableTableClusterTable (with clustered index)C<strong>on</strong>straintsTriggersIndexViewN/AViewIdentityLinked <strong>Server</strong>N/AS<strong>to</strong>red ProcedureFuncti<strong>on</strong>S<strong>to</strong>red Procedure


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 103Some of these objects fall under broader classificati<strong>on</strong>s, such as tables and views. Whilethe discussi<strong>on</strong> of some of the objects is bey<strong>on</strong>d the scope of this guide, the following arecovered in this chapter:● Tables● Comments● C<strong>on</strong>straints● Triggers● Views● Indexes● S<strong>to</strong>red Programs, including functi<strong>on</strong>s, s<strong>to</strong>red procedures, and packages● Objects not found in <strong>SQL</strong> <strong>Server</strong>, including sequences, syn<strong>on</strong>yms, and databaselinksThe data definiti<strong>on</strong> language (DDL) <str<strong>on</strong>g>for</str<strong>on</strong>g> defining objects is in accord with ANSI <strong>SQL</strong>standards. Because both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> maintain compliance with <strong>SQL</strong>-92 and<strong>SQL</strong>-99 standards, the syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> defining objects is very similar.Identifiers and Naming<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> object and column names are generally not case-sensitive. However, noassumpti<strong>on</strong>s should be made because they can be <str<strong>on</strong>g>for</str<strong>on</strong>g>ced <strong>to</strong> be case sensitive bydelimiting them (enclosing them) in double quotati<strong>on</strong> marks (“). For example, the nameTRANSACTION_DATE can be made case sensitive by using “Transacti<strong>on</strong>_Date”. Also,quotes can be used <strong>to</strong> create irregular identifiers such as “Transacti<strong>on</strong> Date” (with a blankspace). Similarly, object and column names in <strong>SQL</strong> <strong>Server</strong> are not case-sensitive bydefault, but this default behavior can be changed by modifying c<strong>on</strong>figurati<strong>on</strong> settings.N<strong>on</strong>standard or delimited identifiers can be created just as in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> using eitherquotati<strong>on</strong> marks (“) or brackets ([ ]). Read the "Using Identifiers" secti<strong>on</strong> in <strong>SQL</strong> <strong>Server</strong>Books Online <str<strong>on</strong>g>for</str<strong>on</strong>g> rules about the c<strong>on</strong>structi<strong>on</strong> and use of regular and delimited identifiers.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> table and column names are s<strong>to</strong>red in data dicti<strong>on</strong>ary tables as uppercase stringsunless <str<strong>on</strong>g>for</str<strong>on</strong>g>ced <strong>to</strong> be case sensitive using delimiters. In c<strong>on</strong>trast, the default <strong>SQL</strong> <strong>Server</strong>behavior is <strong>to</strong> s<strong>to</strong>re them in the case used when they were created. Because scripts <str<strong>on</strong>g>for</str<strong>on</strong>g>use with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are written with such expectati<strong>on</strong>s, it is recommended you useuppercase identifiers while creating the objects in <strong>SQL</strong> <strong>Server</strong> (without <str<strong>on</strong>g>for</str<strong>on</strong>g>cing case byusing delimiters).Qualifiers and Name Resoluti<strong>on</strong>The names of objects are influenced by uniqueness requirements. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> object nameshave <strong>to</strong> be unique <str<strong>on</strong>g>for</str<strong>on</strong>g> a schema. In <strong>SQL</strong> <strong>Server</strong>, the same owner can own objects of thesame name in two different databases, that is, the combinati<strong>on</strong> of owner.table_nameneeds <strong>to</strong> be unique <strong>on</strong>ly within a database. Hence objects are qualified in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> as[schema.]object_namewhereas in <strong>SQL</strong> <strong>Server</strong> the complete qualifier is[database.]owner.]object_nameRules have been established in both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> resolving anobject_name that is not qualified.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the resoluti<strong>on</strong> is governed by syn<strong>on</strong>yms and the c<strong>on</strong>cept of namespaces.Tables, views, snapshots, sequences, syn<strong>on</strong>yms, procedures, functi<strong>on</strong>s, and packagesare in a single namespace. Triggers, indexes, and clusters each have their own individual


104 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemasnamespace. The following order is used <strong>to</strong> resolve an object that falls in the tablenamespace:1. Table namespace of current user's schema2. Private syn<strong>on</strong>ym in the current user's schema3. Public syn<strong>on</strong>ymThe order is different in <strong>SQL</strong> <strong>Server</strong>, and resoluti<strong>on</strong> occurs as:1. Current user's schema in the current d atabase (set with USE statement)2. Database owner dbo of the current databaseThese relati<strong>on</strong>ships h ave <strong>to</strong> be taken care of during the migrati<strong>on</strong> of the users andapplicati<strong>on</strong> s. Because a user can own obj ects of the same name in multiple databasesand different users can hav e objects of the same name in the same database, it isrecommended that both database name and owner name be used <strong>to</strong> qualify objects in<strong>SQL</strong> <strong>Server</strong>.C hanging object identifiers <strong>to</strong> meet <strong>SQL</strong> <strong>Server</strong> standards can affect the applicati<strong>on</strong>susing them. However, changing the names of certain objects, such as indexes andc<strong>on</strong>straints, could be transparent <strong>to</strong> the business applicati<strong>on</strong>s. Given the rules <str<strong>on</strong>g>for</str<strong>on</strong>g> namingin <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, there is no need <strong>to</strong> change the names of any of the identifiers.Note It is recommended that all objects in the migrated <strong>SQL</strong> <strong>Server</strong> database bequalified by database and owner because the rules <str<strong>on</strong>g>for</str<strong>on</strong>g> resolving names couldotherwise lead <strong>to</strong> the wr<strong>on</strong>g object.Working with Data Types<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer two types of data types: native data types and user defineddata types. The data types that are provided by the DBMS are called native data types orsystem data types. There are four basic cl asses of data: character, numeric, datetime,and binary. In additi<strong>on</strong>, both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> have a few data types that areunique <strong>to</strong> each syste m. Tables 6.3 through 6.5 provide a complete mapping of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>data types <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> data types that you should use when migrating.Care has been taken <strong>to</strong> suggest the closest possible data type both in terms of type ofdata being c<strong>on</strong>sidered as well as the scale or size of the data that has <strong>to</strong> beaccommodated. A bad ch oice in data type can lead <strong>to</strong> a lot of problems during datam igrati<strong>on</strong>. The choice has <strong>to</strong> be driven by the definiti<strong>on</strong> in the source table and not by thedata in the table. Even when data migrati<strong>on</strong> is successful, the applicati<strong>on</strong> may fail sometime in the future because the table canno t handle data that it was originally designed <str<strong>on</strong>g>for</str<strong>on</strong>g>.<strong>SQL</strong> <strong>Server</strong> data types can com<str<strong>on</strong>g>for</str<strong>on</strong>g>tably provide a close equivalent of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> datatypes, and over sizing is not recommende d because it drives up the row size and thes<strong>to</strong>rage requirements and will affect per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.Character or Alphanumeric DataNote that <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> differ in the parameter used <strong>to</strong> define Char (Nchar),and Varchar (NVarchar) columns. For example, when CHAR(n) is used <strong>to</strong> specify acolumn data type in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, n represents the number of characters, while in <strong>SQL</strong> <strong>Server</strong> itrepresents number of bytes.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 105Table 6.3 provides the <strong>SQL</strong> <strong>Server</strong> data types <strong>to</strong> use when migrating <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> characterdata.Table 6.3: <strong>SQL</strong> <strong>Server</strong> Equiv alent <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Character-based Data Types<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DataTypeMax Size (Bytes)<strong>SQL</strong> <strong>Server</strong> DataTypeChar 2000 Char 8000NChar 2000 NChar 4000Varchar 4000 Varchar 8000NVarchar 4000 NVarchar4000Varchar2 4000 Varchar2 8000NVarchar2 4000 NVarchar 4000LONG 2 31 Text 2 31 –1CLOB 2 32 Text 2 31 –1NCLOB 2 32 NText 2 30 –1Numeric DataMax Size (Bytes)<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has <strong>on</strong>ly <strong>on</strong>e numeric data type, NUMBER, that can s<strong>to</strong>re zero, positive, negative,fixed, and floating point numbers, with a precisi<strong>on</strong> (p) of 38 digits and a scale (s) rangingfrom -84 <strong>to</strong> 127. Syn<strong>on</strong>yms, such as NUMERIC, DECIMAL, FLOAT, INTEGER, can beused. <strong>SQL</strong> <strong>Server</strong>, <strong>on</strong> the other hand, has eight distinct named numeric data types thatc<strong>on</strong>strain the range of values they can hold. <strong>SQL</strong> <strong>Server</strong> also has three other data typesthat are of the number category: BIT, MONEY, and SMALLMONEY. Table 6.4 comparesnumeric data types in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Table 6.4: Finding Closest <strong>SQL</strong> <strong>Server</strong> Equivalent <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Numeric Data Types<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Number(19,0)Int or Number(10,0)SmallInt or Number(6,0)Number(3,0)Number(p,0)Float or DoublePrecisi<strong>on</strong> or Number(38)Real or Number(19) or Float(63)Number(19,4)Number(10,4)<strong>SQL</strong> <strong>Server</strong>BigIntIntSmallIntTinyIntDecimal or Numeric(p,s)FloatReal or Float(24)M<strong>on</strong>eySmallM<strong>on</strong>eyBinary Data<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s BLOB replaces the older RAW and LONG RAW data types. The IMAGE datatype in <strong>SQL</strong> <strong>Server</strong> is the closest equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>’s BLOB data type, and it cansupport data up <strong>to</strong> 2 GB in size. The BINARY data type is a fixed size column whileVARBINARY is its variable size counterpart. Table 6.5 provides <strong>SQL</strong> <strong>Server</strong> equivalents<str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> binary data types.


106 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasTable 6.5: <strong>SQL</strong> <strong>Server</strong> Equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Binary Data Types<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DataTypeMax Size<strong>SQL</strong> <strong>Server</strong> DataTypeBLOB 4 GB Image 2 GBRaw 2000 bytes Image 2 GBL<strong>on</strong>g Raw 2 GB Image 2 GBBFile 4 GB (file pointer) N/ARaw(n) 2000 bytes Binary(n) orVarBinary(n)Max Size8000 bytesFor more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about designing <str<strong>on</strong>g>for</str<strong>on</strong>g> and implementing BLOBs in <strong>SQL</strong> <strong>Server</strong>, refer<strong>to</strong> http://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/enus/part3/c1161.mspx.Date and TimeHis<strong>to</strong>rically, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has had <strong>on</strong>e data type, Date, which s<strong>to</strong>res both date and timein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i, three new date and time data types have been added <strong>to</strong>address these shortcomings. The Timestamp data type can s<strong>to</strong>re fracti<strong>on</strong>al sec<strong>on</strong>ds up<strong>to</strong> 9 digits of precisi<strong>on</strong>. Time z<strong>on</strong>e aware data types, Timestamp With Time Z<strong>on</strong>e andTimestamp with Local Time Z<strong>on</strong>e, are also available and they can handle daylightsaving time.<strong>SQL</strong> <strong>Server</strong> has two data types: DateTime and SmallDateTime. DateTime canrepresent the date and time in the range January 1, 1753 <strong>to</strong> December 31, 9999 with aprecisi<strong>on</strong> of <strong>on</strong>e-three hundredth of a sec<strong>on</strong>d. SmallDateTime can represent dates in therange January 1, 1900, through June 6, 2079 with a precisi<strong>on</strong> limited <strong>to</strong> the minute. The<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Date and Timestamp data types should be migrated <strong>to</strong> the DateTime data type.T he other two time z<strong>on</strong>e aware data types do not have an equivalent in <strong>SQL</strong> <strong>Server</strong>.User Defined TypesA simple implementati<strong>on</strong> of user-defined data types is the capability <strong>to</strong> define data typesas simple variati<strong>on</strong>s of the primitive data types. For example, defining a data type ZIP asa native type Char, with a length of 5, prov ides a uni<str<strong>on</strong>g>for</str<strong>on</strong>g>m definiti<strong>on</strong> that avoids anyambiguity between designers and developers.For example, the user-defined data type ZIP can be created as follows:CREATE TYPE zip_type AS OBJECT (zip char(5))/In <strong>SQL</strong> <strong>Server</strong>, the user-defined ZIP data type is:EXEC sp_addtype zip_type, 'char(5)'User-defined data types can be recursively used <strong>to</strong> define other user-defined data types.However, <strong>SQL</strong> <strong>Server</strong> does not support object types and their collecti<strong>on</strong>s.TablesThe definiti<strong>on</strong> of the table data structure is the same, both in c<strong>on</strong>cept and <str<strong>on</strong>g>for</str<strong>on</strong>g>m, in both<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. This can be attributed <strong>to</strong> compliance with ANSI <strong>SQL</strong> standards.When designing the table data structure, data integrity is as important as data access. Toserve these purposes, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> provides several opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> how data can be organizedwithin the table. Table 6.6 summarizes them:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 107Table 6.6: <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> Table Types Compared<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Heap-Organized TableClustered Table -Partiti<strong>on</strong>ed Table -Nested Table -Temporary TableExternal Table -Object Table -Index-Organized Table<strong>SQL</strong> <strong>Server</strong>HeapTemporary TableClustered IndexThe most comm<strong>on</strong> implementati<strong>on</strong> of the table object is, in its basic <str<strong>on</strong>g>for</str<strong>on</strong>g>m, the heap-is the focus of the remainder of this organized table, and this table object secti<strong>on</strong>.The CREATE TABLE syntax, which creates a simple heap organized table, has threemajor parts:● Table name● Body (enclosed in parenthesis) — column name, column properties (data type,defaults, inline column c<strong>on</strong>straints), out-of-line column c<strong>on</strong>straints, tablec<strong>on</strong>straints● S<strong>to</strong>rage specificati<strong>on</strong>Table 6.7 compares the structural compositi<strong>on</strong> of the CREATE TABLE syntax in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>and <strong>SQL</strong> <strong>Server</strong>.Table 6.7: High-level Comparis<strong>on</strong> of Table Definiti<strong>on</strong> Syntax<str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong>CREATE TABLECREATE TABLE[schema.]table_name[[database.]owner.]table_name(column namecolumn data type(column namecolumn data typedefault expressi<strong>on</strong>column c<strong>on</strong>straint, …defaults expressi<strong>on</strong>column c<strong>on</strong>straint, …out of line or table c<strong>on</strong>strain<strong>to</strong>ut of line or table c<strong>on</strong>straint) )[s<strong>to</strong>rage_specificati<strong>on</strong>][s<strong>to</strong>rage_specificati<strong>on</strong>]The steps <str<strong>on</strong>g>for</str<strong>on</strong>g> creating a table in <strong>SQL</strong> <strong>Server</strong> using both Enterprise Manager and T-<strong>SQL</strong>are provided in the following procedures. To create a new table using Enterprise Manager, follow these steps:1. Expand <strong>Server</strong>, then Databases, and then the target database.2. Right-click Tables and select New Table. A new window appears <str<strong>on</strong>g>for</str<strong>on</strong>g> addingcolumns and other objects, such as indexes and c<strong>on</strong>straints related <strong>to</strong> the table.This window is called the Table Designer <strong>to</strong>ol.3. Add new columns in the <strong>to</strong>p grid (column definiti<strong>on</strong> grid) al<strong>on</strong>g with the column datatype and nullability c<strong>on</strong>straint. Some of the column's properties, such as Default


108 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasValue, can be provided in the Columns pane at the bot<strong>to</strong>m. The Identity propertyis discussed in greater detail under the "Sequences" heading.4. Click the Table and Index Properties butt<strong>on</strong> found <strong>on</strong> the Columns window, orright-click anywhere in the column definiti<strong>on</strong> grid and select Properties <strong>to</strong> bring upthe table Properties window, which can be used <strong>to</strong> specify table level properties,c<strong>on</strong>straints, and indexes. To create a new table using T-<strong>SQL</strong>, use the following syntax:CREATE TABLE[ database_name.[ owner ] . | owner. ] table_name( { < column_definiti<strong>on</strong> >| column_name AS computed_column_expressi<strong>on</strong>| < table_c<strong>on</strong>straint > } [ ,...n ])[ ON { filegroup | DEFAULT } ][ TEXTIMAGE_ON { filegroup | DEFAULT } ]where < column_definiti<strong>on</strong> > ::= column_name data_type[ COLLATE < collati<strong>on</strong>_name > ][ [ DEFAULT c<strong>on</strong>stant_expressi<strong>on</strong> ]The following list covers each of the comp<strong>on</strong>ents of the CREATE TABLE syntax:● Table and column name. As is the case in the "Identifiers and Naming" secti<strong>on</strong>earlier in this chapter, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> table and column names do not need any changeswhen migrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.● Column data type. The column data type <str<strong>on</strong>g>for</str<strong>on</strong>g>ms part of the table definiti<strong>on</strong> and isan integral part of creating a table. For the sake of reducing the complexity in thediscussi<strong>on</strong> of tables (because there are several comp<strong>on</strong>ents <strong>to</strong> be dealt with here),the discussi<strong>on</strong> of data types has been covered in the secti<strong>on</strong> "Working with DataTypes" earlier in this chapter.● Default value. The rules <str<strong>on</strong>g>for</str<strong>on</strong>g> specifying default value are very similar in bothdatabases, and default values can be specified in most cases. One of thedifficulties that may be encountered while migrating <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> is the lack of anequivalent <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> system functi<strong>on</strong> used <str<strong>on</strong>g>for</str<strong>on</strong>g> defining the default values. In<strong>SQL</strong> <strong>Server</strong>, a default value cannot be specified <str<strong>on</strong>g>for</str<strong>on</strong>g> a column of type timestamp.While <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> treats defaults as a property of the column, <strong>SQL</strong> <strong>Server</strong> definesdefaults as a c<strong>on</strong>straint.● C<strong>on</strong>straints. A detailed discussi<strong>on</strong> of c<strong>on</strong>straints appears in the "C<strong>on</strong>straints"secti<strong>on</strong> later in this chapter.● S<strong>to</strong>rage properties. A detailed discussi<strong>on</strong> of the s<strong>to</strong>rage architecture appears inthe "Migrate the S<strong>to</strong>rage Architecture" secti<strong>on</strong> in Chapter 5, Developing:Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Architecture." The <strong>on</strong>ly s<strong>to</strong>rage property thatcan be specified during table creati<strong>on</strong> is the filegroup name. If a filegroup is notspecified, then the table is created in the database's default filegroup.In the Tab le and Index Properties window, the Table Filegroup drop-down listcan be used pick a filegroup from which the table will be allocated s<strong>to</strong>rage. TheT ext Filegroup drop-down list can be used <strong>to</strong> specify the fi legroup <strong>to</strong> be used <str<strong>on</strong>g>for</str<strong>on</strong>g>large objects, such as text and imagecolumns.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 109Not e In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, tables can be created based <strong>on</strong> the definiti<strong>on</strong> of othertables.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, this is accomplished using the following statementCREATE TABLE table_name AS SELECT …The same can be achieved in <strong>SQL</strong> <strong>Server</strong> using the following syntax:SELECT … INTO table_nameThe various table types found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> can be migrated as described in the following list.Detailed knowledge of each table type is not necessary <strong>to</strong> accomplish the migrati<strong>on</strong>.● Clustered table. Sometimes simply called clusters, these do not have anequivalent in <strong>SQL</strong> <strong>Server</strong>. The tables in the cluster have <strong>to</strong> be created as regularheaps. If rows are frequently accessed using a range search, a clustered indexmay be created <strong>on</strong> such column(s). Only <strong>on</strong>e clustered index can be created <strong>on</strong> atable.This migrati<strong>on</strong> of clustered tables in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> heaps in <strong>SQL</strong> <strong>Server</strong> will betransparent <strong>to</strong> the applicati<strong>on</strong> and users.● Partiti<strong>on</strong>ed table. <strong>SQL</strong> <strong>Server</strong> does not have the partiti<strong>on</strong>ed table opti<strong>on</strong>.However, <strong>SQL</strong> <strong>Server</strong> offers partiti<strong>on</strong>ed views that are built using the samestrategy that was used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> (be<str<strong>on</strong>g>for</str<strong>on</strong>g>e <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 8i) when true horiz<strong>on</strong>talpartiti<strong>on</strong>ing was not available. This involves creating separate tables <str<strong>on</strong>g>for</str<strong>on</strong>g> each ofthe partiti<strong>on</strong>s, with a check c<strong>on</strong>straint <strong>on</strong> the partiti<strong>on</strong> key column(s) <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce arange of values. A partiti<strong>on</strong>ed view is then created as a uni<strong>on</strong> of all the c<strong>on</strong>stituenttables. Details <strong>on</strong> the implementati<strong>on</strong> of partiti<strong>on</strong>ed views can be found under the<strong>to</strong>pic "Creating a Partiti<strong>on</strong>ed View" in <strong>SQL</strong> <strong>Server</strong> Books Online.This migrati<strong>on</strong> of partiti<strong>on</strong>ed tables in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> heaps in <strong>SQL</strong> <strong>Server</strong> will betransparent <strong>to</strong> the applicati<strong>on</strong> and users.● Nested table. <strong>SQL</strong> <strong>Server</strong> does not support nested tables. The implementati<strong>on</strong>strategy used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> can be imitated in <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating them. Thenested table column can be separated out in<strong>to</strong> its own table (denormalized withsimilar definiti<strong>on</strong>) with a unique identifier used <strong>to</strong> c<strong>on</strong>nect the rows from the parenttable <strong>to</strong> the child table.● Minor modificati<strong>on</strong> <strong>to</strong> retrieve the data from the child table will be required inthe code <strong>to</strong> accommodate this change.● Temporary table. <strong>SQL</strong> <strong>Server</strong> supports both local and global temporary tables.<strong>SQL</strong> <strong>Server</strong>'s local temporary table is equivalent <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s global temporary table( with the ON COMMIT PRESERVE ROWS ) because it provides the same level ofisolati<strong>on</strong> from other sessi<strong>on</strong>s.Table 6.8 shows the syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> creating temporary tables in <strong>SQL</strong> <strong>Server</strong>.Table 6.8: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Creating Temporary Tables in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE GLOBAL TEMPORARY TABLEtable_name …ON COMMIT DELETE|PRESERVE ROWS<strong>SQL</strong> <strong>Server</strong>CREATE TABLE# table_nameLocal temporary tables in <strong>SQL</strong> <strong>Server</strong> work identically <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> temporary tablesand do not warrant any changes in the code. But the code pieces that assume thatrows are deleted au<strong>to</strong>matically when working with tables with ON COMMIT


110 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas●●●●DELETE ROWS has <strong>to</strong> be modified <strong>to</strong> include a DELETE statement incompensati<strong>on</strong>.External table. <strong>SQL</strong> <strong>Server</strong> does not have the opti<strong>on</strong> <strong>to</strong> create tables whose dataresides in flat files. Hence such data will have <strong>to</strong> be imported in<strong>to</strong> the database.Object table. <strong>SQL</strong> <strong>Server</strong> does not support objects. The strategy <str<strong>on</strong>g>for</str<strong>on</strong>g> migratingobject tables <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> is <strong>to</strong> flatten (absorb) the object column in<strong>to</strong> the tableitself. This will induce <strong>on</strong>ly a small change in the <strong>SQL</strong> code that accesses the data.Index-organized table. The <strong>SQL</strong> <strong>Server</strong> clustered indexes are very similar <strong>to</strong> theindex-organized table (IOT), where the index is merged in<strong>to</strong> the table instead oftwo separate structures. Clustered indexes are implemented in a fashi<strong>on</strong> similar <strong>to</strong>index-organized tables and have very similar features.Index-organized tables are sorted <strong>on</strong> the primary key. To migrate an indexorganizedtable <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the CLUSTERED keyword can be used inc<strong>on</strong>juncti<strong>on</strong> with the PRIMARY KEY c<strong>on</strong>straint, as described in the syntax given inTable 6.9.In <strong>SQL</strong> <strong>Server</strong>, a clustered index can be created <strong>on</strong> any column(s) of a table, but ithas <strong>to</strong> be created using the CREATE INDEX clause. If a clustered index is createdwith n<strong>on</strong>-unique columns, <strong>SQL</strong> <strong>Server</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ces uniqueness by adding anuniqueifier <strong>to</strong> the rows with duplicates.In most cases, the primary key would be the ideal column <str<strong>on</strong>g>for</str<strong>on</strong>g> a clustered index. Anidentity column can also be used <str<strong>on</strong>g>for</str<strong>on</strong>g> a clustered key. In <strong>SQL</strong> <strong>Server</strong>, it isrecommended that every table should have a clustered index.Note Clustered indexes should be created be<str<strong>on</strong>g>for</str<strong>on</strong>g>e creating any n<strong>on</strong>clusteredindexes. If clustered indexes are planned <str<strong>on</strong>g>for</str<strong>on</strong>g> a table, defer creati<strong>on</strong> of n<strong>on</strong>clusteredindexes (as part of PRIMARY KEY or UNIQUE c<strong>on</strong>straint definiti<strong>on</strong>) during thetable creati<strong>on</strong> in this step.Table 6.9 shows the <strong>SQL</strong> <strong>Server</strong> opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> creating the equivalent of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>index-organized table.Table 6.9: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Creating Index-organized Tables in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE TABLE table_name(column_name datatype,…)ORGANIZATION INDEX[ s<strong>to</strong>rage_definiti<strong>on</strong> ]<strong>SQL</strong> <strong>Server</strong>CREATE TABLE table_name(column_name datatype,[ CONSTRAINT c<strong>on</strong>straint_name ]PRIMARY KEY CLUSTERED[ ON filegroup | DEFAULT ])orCREATE [UNIQUE] CLUSTERED INDEXindex_nameON table_name( column_name [, …] )[ ON filegroup | DEFAULT ]Migrati<strong>on</strong> of tables is complicated by the referential integrity (<str<strong>on</strong>g>for</str<strong>on</strong>g>eign key) c<strong>on</strong>straintsbetween tables. There are two opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> how <strong>to</strong> migrate tables. Opti<strong>on</strong> <strong>on</strong>e is <strong>to</strong> create


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 111tables in a specific order based <strong>on</strong> the <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints (parent tables first). Opti<strong>on</strong>two is <strong>to</strong> create tables in any order, leaving out the <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints, and addingthem after all the tables have been created.CommentsThis is a property of the table that is often not documented and, hence, easily overlookedduring a migrati<strong>on</strong>. <strong>SQL</strong> <strong>Server</strong> does not have a comment property associated with tablesand columns. However, <strong>SQL</strong> <strong>Server</strong> provides the capability <strong>to</strong> associate cus<strong>to</strong>mproperties, called extended properties, with objects.Comments can be added <strong>to</strong> tables and columns using Enterprise Manager and systems<strong>to</strong>red procedures. To add a comment <strong>on</strong> tables and columns using Enterprise Manager, followthese steps:1. Expand <strong>Server</strong>, then Databases, and then the target database.2. Left-click Tables <strong>to</strong> display the list of tables.3. Right-click the target table and left-click Design Table. This brings up the TableDesigner.4. Comments <str<strong>on</strong>g>for</str<strong>on</strong>g> the individual columns can be added in the Descripti<strong>on</strong> field of theColumns pane at the bot<strong>to</strong>m of the Table Designer window.5. In the Table Designer window, click the Table and Index Properties butt<strong>on</strong> foundabove the grid.6. Left-click the Tables pane of the Properties window. Table comments can beadded in the Descripti<strong>on</strong> field in the Tables pane.The sp_addextendedproperty system s<strong>to</strong>red procedure can be used <strong>to</strong> add any userdefinedmetadata <strong>to</strong> any column in <strong>SQL</strong> <strong>Server</strong>. This (and any other properties that area dded <strong>to</strong> the column) can be retrieved with the fn_listextendedproperty functi<strong>on</strong>.Table 6.10 shows the syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> adding comments at the table and column levels.Table 6.10: Comparis<strong>on</strong> of Functi<strong>on</strong>ality<str<strong>on</strong>g>for</str<strong>on</strong>g> Adding Comments in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>COMMENT ON TABLE table_name IScommentCOMMENT ON COLUMNtable_name.column_name IS comment<strong>SQL</strong> <strong>Server</strong>sp_ addextendedproperty 'comment',comment,'user', schema_name, 'table',table_namesp_addextendedproperty 'comment',comment,'user', schema_name, 'table',table_name, 'column', column_nameC<strong>on</strong>straintsC<strong>on</strong>straints are data integrity rules that are defined <strong>on</strong> the columns of a table <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>cecertain business rules. As an example, the specificati<strong>on</strong> of data types in the definiti<strong>on</strong> ofthe column c<strong>on</strong>stitutes a c<strong>on</strong>straint.


112 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasTable 6.11 compares the availability of various types of c<strong>on</strong>straints in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>:Table 6.11: C<strong>on</strong>straints Available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>NOT NULLUNIQUEPRIMARY KEYFOREIGN KEYCHECK<strong>SQL</strong> <strong>Server</strong>NOT NULLUNIQUEPRIMARY KEYFOREIGN KEYCHECKThe functi<strong>on</strong>ality provided by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> <strong>to</strong> define c<strong>on</strong>straints <strong>on</strong> columns,including the syntactic use of inline (or column) c<strong>on</strong>straints and out-of-line (or table)c<strong>on</strong>straints, is almost identical. The syntax in Table 6.12 illustrates the similarity. Out-of-have <strong>to</strong> be used when more than <strong>on</strong>e column is involved in the definiti<strong>on</strong>line c<strong>on</strong>straintsof a c<strong>on</strong>straint. If a c<strong>on</strong>straint name is not specified using the CONSTRAINT clause, adefault name is generated by the database. The default names given by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are of the<str<strong>on</strong>g>for</str<strong>on</strong>g>m SYS_Cn where n is a unique number generated by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The names provided by<strong>SQL</strong> <strong>Server</strong> are more suggestive with respect <strong>to</strong> the type of c<strong>on</strong>straint (<str<strong>on</strong>g>for</str<strong>on</strong>g> example, CK,PK, and FK) and the table and column(s) involved. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> the two opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g>defining c<strong>on</strong>straints in <strong>SQL</strong> <strong>Server</strong> is provided in Table 6.12.Table 6.12: T-<strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Defining Inline and Out-of-line C<strong>on</strong>straints in<strong>SQL</strong> <strong>Server</strong>Inline (Column) C<strong>on</strong>straintCREATE TABLE table_name(column_name datatype[ CONSTRAINT c<strong>on</strong>straint_name ] [ [NOT ] NULL | UNIQUE | PRIMARY KEY |CHECK (c<strong>on</strong>diti<strong>on</strong>) | REFERENCESref_table (ref_column) ])Out-of-line (Table) C<strong>on</strong>straintCREATE TABLE table_name(column_name datatype,[ CONSTRAINT c<strong>on</strong>straint_name ] [UNIQUE (column_name [, ...]) |PRIMARY KEY (column_name [, ...]) |CHECK (c<strong>on</strong>diti<strong>on</strong>) | FOREIGN KEY(column_name [, ...]) REFERENCESref_table (ref_column) ])NOT NULL C<strong>on</strong>straintIn both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, the NOT NULL c<strong>on</strong>straint can be specified <strong>on</strong>ly as acolumn c<strong>on</strong>straint. More often than not, a c<strong>on</strong>straint name is not provided while creatingNOT NULL c<strong>on</strong>straints.When a column has not been specifically defined as NOT NULL in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, it defaults <strong>to</strong>being nullable. When NULL or NOT NULL is not specified explicitly <str<strong>on</strong>g>for</str<strong>on</strong>g> a columndefiniti<strong>on</strong>, <strong>SQL</strong> <strong>Server</strong> uses the default of NOT NULL. For ANSI compatibility, setting thedatabase opti<strong>on</strong> ANSI_NULL_DEFAULT <strong>to</strong> ON changes the database default <strong>to</strong> NULL. In<strong>SQL</strong> <strong>Server</strong>, database and sessi<strong>on</strong> settings can override the nullability specified by thecolumn definiti<strong>on</strong>.Some DBAs like <strong>to</strong> use meaningful names <str<strong>on</strong>g>for</str<strong>on</strong>g> all c<strong>on</strong>straints so that errors referring <strong>to</strong>c<strong>on</strong>s traint violati<strong>on</strong>s can be easily recognized in error messages. When migrating from<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, NOT NULL c<strong>on</strong>straints with user-definednames can be queried using thefollowing syntax:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 113CREATE TABLE NOT NULL CONSTRAINTS(c<strong>on</strong>straint_name varchar2(30),owner varchar2(30)table_name varchar2(30),column_name varchar2(30),search_c<strong>on</strong>diti<strong>on</strong> clob);INSERT INTO NOT NULL CONSTRAINTSSELECT dc.c<strong>on</strong>straint_name, dc.owner, dc.table_name, dcc.column_name,<strong>to</strong>_lob(dc.search c<strong>on</strong>diti<strong>on</strong>)FROM dba_c<strong>on</strong>straints dc, dba_c<strong>on</strong>s_columns dccWHERE dc.owner = dcc.ownerAND dc.c<strong>on</strong>straint_name = dc c.c<strong>on</strong>straint_nameAND dc.c<strong>on</strong>straint_type = 'C'AND dc.owner = 'user_name';COMMIT;SELECT *FROM NOT_NULL_CONSTRAINTSWHERE dbms_lob.instr(search_c<strong>on</strong>diti<strong>on</strong>, 'IS NOT NULL',1,1) > 0;NOT NULL c<strong>on</strong>straints can be created <strong>on</strong> tables using Enterprise Manager and theCREATE TABLE T-<strong>SQL</strong> statement. To create a NOT NULL c<strong>on</strong>straint using Enterprise Manager, follow thesesteps:1. In the Table Designer, the Allow Nulls column should be unchecked <str<strong>on</strong>g>for</str<strong>on</strong>g> en<str<strong>on</strong>g>for</str<strong>on</strong>g>cingthe NOT NULL c<strong>on</strong>straint and checked <strong>to</strong> indicate a NULL c<strong>on</strong>straint. To create a NOT NULL c<strong>on</strong>straint Using T-<strong>SQL</strong>, use the following syntax:CREATE TABLE table_name(column_name datatype [ CONSTRAINT c<strong>on</strong>straint_name ]{ NULL | NOT NULL },…)Check C<strong>on</strong>straintBoth <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use the same syntax <strong>to</strong> define check c<strong>on</strong>straints; both alsohave similar restricti<strong>on</strong>s in its usage. CHECK c<strong>on</strong>straints can be defined <strong>on</strong> a singlecolumn or multiple columns at the table level. The c<strong>on</strong>diti<strong>on</strong>s specified in the CHECKclause should evaluate <strong>to</strong> a Boolean value of TRUE or FALSE. The c<strong>on</strong>diti<strong>on</strong>s can refer<strong>to</strong> other columns but are restricted <strong>to</strong> the row being modified.Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> allow multiple CHECK c<strong>on</strong>straints <strong>on</strong> a column. A columnc<strong>on</strong>straint can <strong>on</strong>ly reference the column it is being created <strong>on</strong>. Each c<strong>on</strong>straint can havemultiple c<strong>on</strong>catenated c<strong>on</strong>diti<strong>on</strong>s. The process <strong>to</strong> create check c<strong>on</strong>straints <strong>on</strong> tablesusing Enterprise Manager and T-<strong>SQL</strong> is provided in the following procedures. To create a check c<strong>on</strong>straint using the Table Designer in Enterprise Manager,follow these steps:1. In the Table Designer, click the Manage C<strong>on</strong>straints butt<strong>on</strong> <strong>to</strong> bring up the tableProperties window with the Check C<strong>on</strong>straints pane active.2. Click the New butt<strong>on</strong> <strong>to</strong> add a c<strong>on</strong>straint.


114 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas3. A name of the type CK_table_name is inserted by the system in the C<strong>on</strong>straintname box. The c<strong>on</strong>straint name can be changed <strong>to</strong> match the name given in<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong>ly after entering a valid c<strong>on</strong>diti<strong>on</strong> in the C<strong>on</strong>straint expressi<strong>on</strong> box. To create a check c<strong>on</strong>straint using T-<strong>SQL</strong>, use the following syntax:Table 6.13 provides the syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> the two alternative <str<strong>on</strong>g>for</str<strong>on</strong>g>mats available in <strong>SQL</strong> <strong>to</strong> specifyCHECK c<strong>on</strong>straints during table creati<strong>on</strong>. The syntax is the same in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>.Table 6.13: T-<strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Defining Inline and Out-of-line CHECKC<strong>on</strong>straints in <strong>SQL</strong> <strong>Server</strong>Inline (Column) C<strong>on</strong>straintCREATE TABLE table_name(column_name datatype[ CONSTRAINT c<strong>on</strong>straint_name ] CHECK(c<strong>on</strong>diti<strong>on</strong>)…)Out-of-line (Table) C<strong>on</strong>straintCREATE TABLE table_name(column_name datatype,…[ CONSTRAINT c<strong>on</strong>straint_name ] CHECK(c<strong>on</strong>diti<strong>on</strong>))Unique C<strong>on</strong>straints<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use indexes <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce unique c<strong>on</strong>straints. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, if a uniqueor n<strong>on</strong>-unique index already exists <strong>on</strong> the c<strong>on</strong>straint columns, the index is used <strong>to</strong>en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce the c<strong>on</strong>straint without creating new <strong>on</strong>es. There<str<strong>on</strong>g>for</str<strong>on</strong>g>e, if a user-defined index ispreferred instead of a system-defined (and named) <strong>on</strong>e, it is recommended that the indexbe created first. Unless a clustered index is explicitly specified, <strong>SQL</strong> <strong>Server</strong> creates an<strong>on</strong>clustered index <strong>on</strong> the unique key column(s).An important difference in the implementati<strong>on</strong> of the UNIQUE c<strong>on</strong>straint is <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> allowsmultiple rows with NULL values in all the columns making up the unique c<strong>on</strong>straint,whereas <strong>SQL</strong> <strong>Server</strong> allows <strong>on</strong>ly <strong>on</strong>e row <strong>to</strong> have a NULL value <str<strong>on</strong>g>for</str<strong>on</strong>g> the UNIQUE column.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the UNIQUE, PRIMARY KEY, and FOREIGN KEY c<strong>on</strong>straints can be acomposite of up <strong>to</strong> 32 columns, while in <strong>SQL</strong> <strong>Server</strong> the limit is 16.Unique c<strong>on</strong>straints can be created using Enterprise Manager as well as T-<strong>SQL</strong>statements. To create a UNIQUE c<strong>on</strong>straint using Enterprise Manager, follow these steps:1. In the Table Designer, click the Table and Index Properties butt<strong>on</strong>.2. Select the Indexes/Keys tab and click New. A system-assigned index nameappears with the column name, column order, index filegroup, and fill fac<strong>to</strong>r filled inusing defaults. You will need <strong>to</strong> replace these default values with your own.3. Enter the name of the new index in the Index name text box and select thecolumns <strong>to</strong> be included in the c<strong>on</strong>straint in the correct order in the grid.4. Check the Create UNIQUE check box and select the C<strong>on</strong>straint radio butt<strong>on</strong>.5. Check the Create as CLUSTERED box if a clustered index is <strong>to</strong> be used <strong>to</strong>en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce the c<strong>on</strong>straint. If a n<strong>on</strong>clustered index is chosen, a filegroup can bespecified <str<strong>on</strong>g>for</str<strong>on</strong>g> the index. Because <strong>on</strong>ly a single clustered index can be created <strong>on</strong> atable, and the filegroup cannot be changed from the primary filegroup.6. The equivalent of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s PCTFREE can be specified <str<strong>on</strong>g>for</str<strong>on</strong>g> the index that will becreated <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce the c<strong>on</strong>straint in the Fill Fac<strong>to</strong>r box.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 115 To create a UNIQUE c<strong>on</strong>straint using T-<strong>SQL</strong>, use the following syntax:The <strong>on</strong>ly syntactic difference in the UNIQUE c<strong>on</strong>straint definiti<strong>on</strong> between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong> is with the USING INDEX clause used <strong>to</strong> define the index that en<str<strong>on</strong>g>for</str<strong>on</strong>g>ces thec<strong>on</strong>straint. The USING INDEX clause of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has an equivalent in <strong>SQL</strong> <strong>Server</strong> and canbe used with both column and table c<strong>on</strong>straints. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> table c<strong>on</strong>straint isdescribed in Table 6.14.Table 6.14: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Defining UNIQUE C<strong>on</strong>straints in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong>CREATE TABLE table_nameCREATE TABLE table_name((column_name datatype,column_name datatype,…,…,[ CONSTRAINT c<strong>on</strong>straint_name ] [ CONSTRAINT c<strong>on</strong>straint_name ]UNIQUE ( column_name [, …] ) UNIQUE [ CLUSTERED | NONCLUSTERED ][ USING INDEX [ TABLESPACE( column_name [, …] )tablespace_name ][ WITH FILLFACTOR = fillfac<strong>to</strong>r ][ s<strong>to</strong>rage_definiti<strong>on</strong> ] ][ ON FILEGROUP { filegroup |DEFAULT } ]Primary Key C<strong>on</strong>straintPRIMARY KEY c<strong>on</strong>straints have all the characteristics of UNIQUE c<strong>on</strong>straints, with theadditi<strong>on</strong>al restricti<strong>on</strong> that all primary key columns be NOT NULL. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> creates aUNIQUE index and a NOT NULL c<strong>on</strong>straint <strong>to</strong> implement PRIMARY KEY c<strong>on</strong>straints.With <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i, an existing n<strong>on</strong>-unique index may be used <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce the primary keyc<strong>on</strong>straint. In <strong>SQL</strong> <strong>Server</strong>, if a clustered index does not already exist <strong>on</strong> the table, or an<strong>on</strong>clustered index is not explicitly specified, a unique, clustered index is created <strong>to</strong>en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce the PRIMARY KEY c<strong>on</strong>straint. The following procedures dem<strong>on</strong>strate that it is fareasier <strong>to</strong> use T-<strong>SQL</strong> than Enterprise Manager when it comes <strong>to</strong> creating a PRIMARYKEY c<strong>on</strong>straint. To create a primary key c<strong>on</strong>straint using Enterprise Manager, follow thesesteps:1. In the Table Designer, click and select the colum n(s) that are part of the primarykey (use the Ctrl key <str<strong>on</strong>g>for</str<strong>on</strong>g> this).2. Right-clic k anywhere al<strong>on</strong>g the selected column(s) and click Set Primary Key. Acheck mark appears next <strong>to</strong> the Set Primary Key opti<strong>on</strong>.3. A unique clustered in dex using the naming c<strong>on</strong>venti<strong>on</strong> PK_table_name isau<strong>to</strong>matically created by the system.4. The name and properties of the index can be changed from those assigned by thesystem through the Indexes/Keys pane of the Table and Index Propertieswindow. To create a primary key c<strong>on</strong>straint using T-<strong>SQL</strong>, use the following syntax:<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> differ <strong>on</strong>ly in the USING INDEX part of the PRIMARY KEYc<strong>on</strong>straint syntax. The syntax differs from the UNIQUE c<strong>on</strong>straint definiti<strong>on</strong> <strong>on</strong>ly in theUNIQUE keyword being replaced with PRIMARY KEY. In both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, aNOT NULL c<strong>on</strong>straint is added by the system <str<strong>on</strong>g>for</str<strong>on</strong>g> all primary key columns when <strong>on</strong>e is notexplicitlyspecified.


116 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasThe CREATE TABLE syntax in Table 6.15 is <str<strong>on</strong>g>for</str<strong>on</strong>g> defining primary key c<strong>on</strong>straints and itsassociated index.Table 6.15: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Defining PRIMARY KEY C<strong>on</strong>straints in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong>CREATE TABLE table_nameCREATE TABLE table_name((column_name datatype,column_name datatype,…,…,[ CONSTRAINT c<strong>on</strong>straint_name ][ CONSTRAINT c<strong>on</strong>straint_name ]PRIMARY KEY ( column_name [, …] ) [ PRIMARY KEY [ CLUSTERED |USING INDEX [ TABLESPACENONCLUSTERED ] ( column_name [, …] )tablespace_name ] [ s<strong>to</strong>rage specs ] ] [ WITH FILLFACTOR = fillfac<strong>to</strong>r ] [ ONFILEGROUP { filegroup | DEFAULT } ]andForeign Key C<strong>on</strong>straintA <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straint en<str<strong>on</strong>g>for</str<strong>on</strong>g>ces the rule that a n<strong>on</strong>-null value in <strong>on</strong>e or more columns ofa table (child) must exist in a corresp<strong>on</strong>ding set of columns in the same (self-referential)or another (parent) table. The referenced key columns must possess a primary key orunique key index <strong>on</strong> them.The number and data types of columns specified in the FOREIGN KEY clause shouldmatch the corresp<strong>on</strong>ding columns of the referenced table. FOREIGN KEY c<strong>on</strong>straints in<strong>SQL</strong> <strong>Server</strong> have a restricti<strong>on</strong> of not being able <strong>to</strong> cross database boundaries. In thecase where <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints existing between different schemas of a source<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database are migrated <strong>to</strong> separate databases in <strong>SQL</strong> <strong>Server</strong>, the c<strong>on</strong>straints willhave <strong>to</strong> be replaced with triggers. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the ON DELETE clause is used <strong>to</strong> specifythe acti<strong>on</strong>s that will au<strong>to</strong>matically be undertaken if a parent row is deleted. Additi<strong>on</strong>ally,<strong>SQL</strong> <strong>Server</strong> has the ON UPDATE clause <str<strong>on</strong>g>for</str<strong>on</strong>g> handling updates <strong>to</strong> the parent rows.Table 6.16 shows the availability of various c<strong>on</strong>trol acti<strong>on</strong>s using these clauses in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>and <strong>SQL</strong> <strong>Server</strong>:Table 6.16: Functi<strong>on</strong>ality Available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> with Respect <strong>to</strong>Foreign Key C<strong>on</strong>straintOperati<strong>on</strong> Acti<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>ON DELETE SET NULL Yes NoON DELETE CASCADE Yes YesON DELETE NO ACTION Yes YesON UPDATE CASCADE No YesON UPDATE NO ACTION No YesNote In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the default of NO ACTION (restrict) is assumed <strong>on</strong>ly by the absence ofan O N DELETE { SET NULL | CASCADE } clause in the definiti<strong>on</strong>. In <strong>SQL</strong> <strong>Server</strong>, thedefault is NO ACTION <str<strong>on</strong>g>for</str<strong>on</strong>g> both operati<strong>on</strong>s. To mimic the acti<strong>on</strong> of SET NULL, it has <strong>to</strong>be handled programmatically in the applicati<strong>on</strong> using an appropriate <strong>SQL</strong> statement.Foreign key c<strong>on</strong>straints can be created in <strong>SQL</strong> <strong>Server</strong> usingEnterprise Manager and T-<strong>SQL</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 117 To create a <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straint using Enterprise Manager, follow thesesteps:1. Right-click the table name <strong>on</strong> the table list, click Design Table, and then clickTable and Index Properties.2. Select the Relati<strong>on</strong>ships tab and click New.3. A new relati<strong>on</strong>ship is created with a default name and current table selected in theForeign key table drop-down list. Type in or select (from drop-down list) theappropriate columns involved in the current table (child table). Also select theappropriate table <str<strong>on</strong>g>for</str<strong>on</strong>g> the Parent key table and its parent columns.4. Select appropriate behaviors <str<strong>on</strong>g>for</str<strong>on</strong>g> the trigger in the check boxes at the bot<strong>to</strong>m of thescreen. The important behaviors are Check existing data <strong>on</strong> creati<strong>on</strong> andEn<str<strong>on</strong>g>for</str<strong>on</strong>g>ce relati<strong>on</strong>ship <str<strong>on</strong>g>for</str<strong>on</strong>g> INSERTs and UPDATEs. To create a <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straint using the Database Diagram Wizard, followthese steps:1. Expand <strong>Server</strong>, then Databases, then target database.2. Right-click Diagrams and click New Database Diagram.3. The wizard will lead you through adding the tables <strong>to</strong> be included in the diagram.See Figure 6.7.Figure 6.7Using Database Diagram Wizard <str<strong>on</strong>g>for</str<strong>on</strong>g> creating referentials4. To add a relati<strong>on</strong>ship, select the <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key column of the child table, and drag it <strong>to</strong>the primary or unique key column of the parent table.5. A pop-up dialog will appear with columns filled in based <strong>on</strong> the columns selectedinthe drag and drop. The acti<strong>on</strong>s need not be precise because in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> such as


118 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemasname, primary key, and <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key columns, can be modified be<str<strong>on</strong>g>for</str<strong>on</strong>g>e saving. SeeFigure 6.8.Figure 6.8Choosing the right relati<strong>on</strong>ship properties To create a <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straint using T-<strong>SQL</strong>, use the following syntax:Table 6.17 c<strong>on</strong>tains the syntax <strong>to</strong> add <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints with the acti<strong>on</strong>s of ONDELETE and also the ON UPDATE statement, which do es not exist in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.T able 6.17: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Defining FOREIGN KEY C<strong>on</strong>straints in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong>Operati<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>ON DELETECREATE TABLEtable_ nameCREATE TABLEtable_name(…,(…,column_name datatype,…,[ CONSTRAINTc<strong>on</strong>straint_name ]FOREIGN KEY(column_name [,…]REFERENCES[schema.]ref_table_name(ref_column_name[, …])ON DELETE { SET NULL |column_name datatype,…,[ CONSTRAINTc<strong>on</strong>straint_name ]FOREIGN KEY(column_name [,…]REFERENCESref_table_name(ref_column_name[, …])ON DELETE { CASCADE |


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 119Operati<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>ON UPDATECASCADE }NO ACTION}CREATE TABLEtable_name(…,column_name datatype,…,[ CONSTRAINTc<strong>on</strong>straint_name ]FOREIGN KEY(column_name [,…]REFERENCESref_table_name(ref_column_name[, …])ON UPDATE { CASCADE |NO ACTION}TriggersTriggers are used <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce more complex business rules than can be en<str<strong>on</strong>g>for</str<strong>on</strong>g>ced usingc<strong>on</strong>straints. Triggers are s<strong>to</strong>red procedures that are implicitly executed when certain datamodificati<strong>on</strong> (using data manipulati<strong>on</strong> language statements, also known as DML) isper<str<strong>on</strong>g>for</str<strong>on</strong>g>med against tables and views. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, there can be up <strong>to</strong> twelve combinati<strong>on</strong>s oftrigger executi<strong>on</strong>s (acti<strong>on</strong>s) based <strong>on</strong>:● DML operati<strong>on</strong>: INSERT, UPDATE, DELETE● Timing: BEFORE, AFTER● Level: ROW, STATEMENTTable 6.18 evaluates <strong>SQL</strong> <strong>Server</strong> support <str<strong>on</strong>g>for</str<strong>on</strong>g> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> trigger functi<strong>on</strong>ality.Table 6.18: Functi<strong>on</strong>ality of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Triggers Mapped <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>Trigger Feature <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>DML – INSERT Yes YesDML – UPDATE Column/Row RowDML – DELETE Yes YesTiming – BEFORE Yes Yes (INSTEAD OF)Timing – AFTER Yes YesLevel Row/Statemen tRowViews – INSTEAD OF Yes YesMultiple triggers per acti<strong>on</strong> Yes Yes (first/last specified)The <strong>SQL</strong> <strong>Server</strong> INSTEAD OF triggers are equivalent <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>’s BEFORE triggers.When migrating triggers from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the <strong>on</strong>ly drawback is that <strong>SQL</strong> <strong>Server</strong> does notsupport statement-level triggers. However, there are two pseudo-tables, inserted anddeleted, that are populated during the trig ger executi<strong>on</strong> and which can be used <strong>to</strong>simulate statement-level operati<strong>on</strong>s. These insertedand deleted pseudo tables aresimilar <strong>to</strong> the :old and :new pseudo-rows in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and are populated with all (multiple)rows affected by the trigger executi<strong>on</strong>. The <strong>SQL</strong> <strong>Server</strong> deleted and inserted pseudotablesare available by default and are not specified as part of the trigger definiti<strong>on</strong>. In


120 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the pseudo-rows have <strong>to</strong> be defined in the trigger using the REFERENCINGclause.Note This secti<strong>on</strong> is c<strong>on</strong>cerned <strong>on</strong>ly with creati<strong>on</strong> of the trigger object. A detaileddiscussi<strong>on</strong> <strong>on</strong> trigger logic (code) and its migrati<strong>on</strong> is found in Chapter 11, "Developing:Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>" under the "<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the DataAccess" secti<strong>on</strong>.When multiple triggers exist <strong>on</strong> a table <str<strong>on</strong>g>for</str<strong>on</strong>g> the same acti<strong>on</strong>, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does not guaranteeany particular order of executi<strong>on</strong> of multiple triggers. <strong>SQL</strong> <strong>Server</strong> has the capability <strong>to</strong>specify which trigger should be fired be<str<strong>on</strong>g>for</str<strong>on</strong>g>e (first) and a fter (last) all other triggers usingthe system s<strong>to</strong>red pr ocedure sp_ settriggerorder. This feature has been found useful ine liminating some of the complexities in the code found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> triggers <strong>to</strong> manage thes equence of events.Triggers can be defined <strong>on</strong> tables either using Enterprise Manager or using T-<strong>SQL</strong>. To create a trigger using Enterprise Manager, followthese steps:1. In the Enterprise Manager, expand <strong>Server</strong>, then Databases, then targetdatabase, and then Tables.2. Right-click the table nam e <strong>on</strong> the table list, click All Tasks, and then click ManageTriggers. Or, click the Trigge rs butt<strong>on</strong> in the Table Designer.3. Type in the trigger text using the provided template.4. Click Apply if m ore than <strong>on</strong>e trigger is <strong>to</strong> be created, or OK <strong>to</strong> save all changesand close the dialog box. To create a trigger using T-S QL, use the following syntax:Table 6.19 compares the comm<strong>on</strong>ly used functi<strong>on</strong>ality of the trigger definiti<strong>on</strong> CREATETRIGGER statement in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Table 6.19: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Creating Triggers in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE TRIGGER trigger_name{ BEFORE | AFTER | INSTEAD OF } { {INSERT [ OR ] | DELETE [ OR ] |UPDATE [ OF column_name [, …] ] } }ON table_nameREFERENCING [OLD AS :old] [NEW AS:new][ FOR EACH ROW ]WHEN ( c<strong>on</strong>diti<strong>on</strong> )Pl/ sql_block<strong>SQL</strong> <strong>Server</strong>CREATE TRIGGER trigger_nameON table_name | view_name{ { FOR | AFTER | INSTEAD OF } { [INSERT ] [ , ] [ UPDATE ] [ , ] [DELETE ] }AS[ { IF UPDATE ( column_name )[ { AND | OR } UPDATE ( column_name) ] [ ...n ] |IF ( COLUMNS_UPDATED ( ) {bitwise_opera<strong>to</strong>r } updated_bitmask){ comparis<strong>on</strong>_ opera<strong>to</strong>r }column_bitmask [ ...n ] } ]sql_statement [ ...n ]}}


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 121IndexesThere are two major categories of indexes in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>: B-tree indexes and Bitmapindexes. All other indexes are variati<strong>on</strong>s of these two basic types <strong>to</strong> provide additi<strong>on</strong>alfeatures. Table 6.20 provides a quick comparis<strong>on</strong> of the indexing schemes available in<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>:Table 6.20: Indexing Schemes Available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>Index Scheme <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>B-tree — Unique Yes YesB-tree — N<strong>on</strong>-unique Yes YesB-tree — Composite Yes (32 columns) Yes (16 columns)B-tree — Ascending Yes YesB-tree — Descending Yes YesB-tree — Cluster Yes NoB-tree — Reverse Key Yes NoB-tree — Key Compressed Yes NoB-tree — Functi<strong>on</strong>-based Yes NoB-tree — Index-Organized YesYes (Clustered)TableB-tree — Partiti<strong>on</strong>ed Yes NoBitmap Yes (30 columns) NoBitmap — Join Yes NoB-Tree Indexes<strong>SQL</strong> <strong>Server</strong> offers two types of indexes: clustered and n<strong>on</strong>clustered. Both these typesare based <strong>on</strong> the B-tree data structure. Hence assumpti<strong>on</strong>s can be drawn as <strong>to</strong> theirper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance in the two systems. An important difference between the twoimplementati<strong>on</strong>s is <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does not index rows when all the key columns have null valuesin them, while <strong>SQL</strong> <strong>Server</strong> does.Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> support the following basic versi<strong>on</strong>s of the B-tree index:● Comp osite. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> allows indexes with up <strong>to</strong> 32 columns, whereas <strong>SQL</strong> <strong>Server</strong>allows up <strong>to</strong> 16 columns. While indexes with 16 or more columns are rare, thenumber of columns will have <strong>to</strong> be trimmed down if such indexes were <strong>to</strong> bemigrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.● Unique. Unique indexes are used <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce PRIMARY KEY and UNIQUEc<strong>on</strong>straints. Even though nulls cannot be compared (nor c<strong>on</strong>sidered equal) <str<strong>on</strong>g>for</str<strong>on</strong>g>sake of uniqueness, when two rows are identical, null values are c<strong>on</strong>sidered asidentical. In <strong>SQL</strong> <strong>Server</strong>, primary key c<strong>on</strong>straints cannot have null values, whereasunique indexes allow <strong>on</strong>e row with null value. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer <strong>to</strong> the"Unique C<strong>on</strong>straints" secti<strong>on</strong> earlier in this chapter.● N<strong>on</strong>-unique. This is the basic <str<strong>on</strong>g>for</str<strong>on</strong>g>m of the B-tree or n<strong>on</strong>clustered index, where keyvalues can be repeated.● Ascending. The key values are sorted and s<strong>to</strong>red in ascending order.● Descending. The key values are sorted and s<strong>to</strong>red in descending order.The following list provides variati<strong>on</strong>s of the B-tree index, implemented with a modificati<strong>on</strong><strong>to</strong> the basic B-tree structure, that provide a specific feature:


122 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas●●●●●●Cluster indexes. Such indexes can be found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> clustered tables(clusters). Clustered tables are not supported by <strong>SQL</strong> <strong>Server</strong> and neither arecluster indexes.Index-organized tables. The clustered indexes in <strong>SQL</strong> <strong>Server</strong> are similar <strong>to</strong> theindex organized tables. Refer <strong>to</strong> the discussi<strong>on</strong> under the "Tables" secti<strong>on</strong> earlier inthis chapter.Reverse key indexes. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> developed these indexes <strong>to</strong> reduce c<strong>on</strong>tenti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>index blocks by indexes <strong>on</strong> columns that have sequential values that are writtenalmost simultaneously. This is achieved by reversing the bytes in the key value <strong>to</strong>produce n<strong>on</strong>-sequential numbers. This indexing scheme is not available in<strong>SQL</strong> <strong>Server</strong>. The reverse key index is useful in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Real Applicati<strong>on</strong> Cluster(RAC) implementati<strong>on</strong>s, and there is no disadvantage in migrating such indexes <strong>to</strong>clustered or n<strong>on</strong>clustered indexes.Partiti<strong>on</strong>ed indexes. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, B-tree indexes can be created that are local <strong>to</strong> thepartiti<strong>on</strong> or global <strong>to</strong> the entire table (partiti<strong>on</strong>ed or n<strong>on</strong>- partiti<strong>on</strong>ed). This feature isnot available in <strong>SQL</strong> <strong>Server</strong> and should be replaced by clustered or n<strong>on</strong>clusteredindexes.Key compressed index. In key compressi<strong>on</strong>, the leading subsets of a key can becompressed in a manner similar <strong>to</strong> clustering by s<strong>to</strong>ring the leading subset <strong>on</strong>ly<strong>on</strong>ce <str<strong>on</strong>g>for</str<strong>on</strong>g> repeating values. <strong>SQL</strong> <strong>Server</strong> does not support key compressi<strong>on</strong>.Functi<strong>on</strong>-based index. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, expressi<strong>on</strong>s in the WHERE clause that c<strong>on</strong>tainfuncti<strong>on</strong>s do not use indexes as an access path. To overcome this disadvantage,indexes can be created by applying the functi<strong>on</strong> <strong>to</strong> compute the value of theexpressi<strong>on</strong> and s<strong>to</strong>ring it in an index. For example, if the column part_name isaccessed using the expressi<strong>on</strong> UPPER(part_name), a functi<strong>on</strong>-based index can bedefined <strong>on</strong> UPPER(part_name). <strong>SQL</strong> <strong>Server</strong> does not support functi<strong>on</strong>-basedindexes. There is no other index type in <strong>SQL</strong> <strong>Server</strong> that can provide similarfuncti<strong>on</strong>ality.Bitmap IndexThe bitmap indexes are specia lly designed <str<strong>on</strong>g>for</str<strong>on</strong>g> improving the retrieval of data based <strong>on</strong>columns with very low cardinality. Becaus e maintenance of the bitmap indexes is veryexpensive, their utility is restric ted <strong>to</strong> Data Warehouses and DSS systems where there isvery low or zero update activity.Bitmap indexes are not available in <strong>SQL</strong> <strong>Server</strong> and cannot be substituted with B-treeindexes.I n <strong>SQL</strong> <strong>Server</strong> and versi<strong>on</strong>s of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> be<str<strong>on</strong>g>for</str<strong>on</strong>g>e 9i, indexes are used <strong>on</strong>ly when the leadingsubset of key values are involved. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> introduced the c<strong>on</strong>cept of fastindex scan, whereby the entire index is scanned <str<strong>on</strong>g>for</str<strong>on</strong>g> matching values in the n<strong>on</strong>-leadingkeys by skipping the leading key columns. In <strong>SQL</strong> <strong>Server</strong>, additi<strong>on</strong>al indexes have <strong>to</strong> becreated <str<strong>on</strong>g>for</str<strong>on</strong>g> the n<strong>on</strong>-leading columns <strong>to</strong> provide access paths similar <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Thisrequirement is not documented inside the database and is dependent <strong>on</strong> the <strong>SQL</strong>statements used in applicati<strong>on</strong>s. These situati<strong>on</strong>s can <strong>on</strong>ly be discovered by profiling theapplicati<strong>on</strong> during testing.The various types of indexes can be created using Enterprise Manager, the Create IndexWizard, or T-<strong>SQL</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 123 To create an index using Enterprise Manager, follow these steps:The steps <str<strong>on</strong>g>for</str<strong>on</strong>g> creating an index are very similar <strong>to</strong> that described <str<strong>on</strong>g>for</str<strong>on</strong>g> UNIQUE key. Creati<strong>on</strong>of a n<strong>on</strong>-unique, n<strong>on</strong>clustered index is dem<strong>on</strong>strated here.1. Expand <strong>Server</strong>, then Databases, then target database, and then Tables.2. Right-click the table nam e <strong>on</strong> the table list, click Design Table, and then clickTable and Index Properties.3. Select the Indexes/Keys tab and click New.4. Enter the name of the new ind ex in the Index name text box. Insert the columns orthe index in grid al<strong>on</strong>g with the required sort order fo r the column.5. Uncheck the Create UN IQUE check box <strong>to</strong> specify a n<strong>on</strong>-unique index.6. Select the target filegroup fro m the Index Filegroup drop-down list.7. Click the desired value <str<strong>on</strong>g>for</str<strong>on</strong>g> Fill fac<strong>to</strong>r (equivalent of PCTFREE). To create an index using the Create Index Wizard, follow these steps:1. Expand a server group, and then expand the server in which <strong>to</strong> create the index.2. On the Tools menu, click Wizards.3. Expand Database.4. Double-click Create Index Wizard.5. Complete the steps in the wizard To create an index using T-<strong>SQL</strong>, use the following syntax:Table 6.21 shows the syntax of the CREATE INDEX statement <str<strong>on</strong>g>for</str<strong>on</strong>g> the features andfuncti<strong>on</strong>ality discussed here.Table 6.21: <strong>SQL</strong> statements available <str<strong>on</strong>g>for</str<strong>on</strong>g> Creating Indexes in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE [UNIQUE | BITMAP ]INDEX index_nameON table_name ( column_name[ ASC | DESC ] [, …] )[ physical_attributes ][ { COMPRESS | NOCOMPRESS }prefix_length ][ REVERSE ][ TABLESPACE tablespace_name ][ s<strong>to</strong>rage_descripti<strong>on</strong> ]<strong>SQL</strong> <strong>Server</strong>CREATE [ UNIQUE ] [ CLUSTERED |NONCLUSTERED ] INDEX index_nameON table_name ( column_name[ ASC | DESC ] [, … ] )[ WITH index_opti<strong>on</strong>s ][ ON filegroup ]ViewsVie ws are used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> <strong>to</strong> hide query complexity and encourage queryreuse. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> have added features, such as updateability andinde xes <strong>to</strong> views, <strong>to</strong> improve their utility and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.


124 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasTable 6.22 compares the availability of the various types of views in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>.Table 6.22: Types of Views Available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>View Type <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>Simple Views Yes YesJoin Views Yes YesPartiti<strong>on</strong>ed Views Yes YesRead-<strong>on</strong>ly Views Yes NoUpdateable Views Yes YesInline Views Yes YesObject Views Yes NoThe following are the various types of views available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and the support <str<strong>on</strong>g>for</str<strong>on</strong>g> themin <strong>SQL</strong> <strong>Server</strong>:● Simple views. This view query is based <strong>on</strong> a single table and their migrati<strong>on</strong> istrivial.● Join views. This view query is based <strong>on</strong> more than <strong>on</strong>e table. The join viewsavailable in <strong>SQL</strong> <strong>Server</strong> are less restrictive than their <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> counterparts in theiruse of aggregate functi<strong>on</strong>s in the query. Hence migrating them from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong><strong>SQL</strong> <strong>Server</strong> should not pose any problems. When a view is defined with an outerjoin and is queried with a qualificati<strong>on</strong> <strong>on</strong> a column from the inner table of the outerjoin, the results from <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> can differ.● Partiti<strong>on</strong>ed views. This view query provides a uni<strong>on</strong> of partiti<strong>on</strong>s of data indifferent tables (regular n<strong>on</strong>-partiti<strong>on</strong>ed tables). Use of partiti<strong>on</strong>ed views wascomm<strong>on</strong> in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the introducti<strong>on</strong> of partiti<strong>on</strong>ed tables in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 8.<strong>SQL</strong> <strong>Server</strong> supports the entire range of features that are available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> withrespect <strong>to</strong> partiti<strong>on</strong>ed views.● Read-<strong>on</strong>ly views. This view query with the WITH READ ONLY clause specified <strong>to</strong>curb update activity against the base tables of the view. <strong>SQL</strong> <strong>Server</strong> does not havean equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g> this feature. When migrating a read-<strong>on</strong>ly view, care has <strong>to</strong> betaken <strong>to</strong> ensure that <strong>on</strong>ly SELECT privileges are granted <strong>to</strong> the users.● Updatable views. These are simple, join, or partiti<strong>on</strong>ed views against which DMLstatements can be executed, subject <strong>to</strong> certain restricti<strong>on</strong>s. In <strong>SQL</strong> <strong>Server</strong>, therestricti<strong>on</strong>s can be bypassed (except the use of aggregate functi<strong>on</strong>s) by definingINSTEAD OF triggers <strong>on</strong> the views. The WITH CHECK OPTION clause preventsmodificati<strong>on</strong>s <strong>to</strong> data that violate the criteria in the WHERE clause of the viewquery. DML statements <strong>on</strong> join views can modify data <strong>on</strong>ly in <strong>on</strong>e base table.● Inline views. An inline view is a subquery that is used like a view in the FROMclause of <strong>SQL</strong> statements. <strong>SQL</strong> <strong>Server</strong> fully supports their definiti<strong>on</strong>.● Object views. Object views are virtual object tables that can be used <strong>to</strong>manipulate object data types as well as relati<strong>on</strong>al data cast as objects. Objectviews are not available in <strong>SQL</strong> <strong>Server</strong>and should be recreated (flattened) asregular views.● Indexed views. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does not support creati<strong>on</strong> of indexes <strong>on</strong> views. However,UNIQUE, PRIMARY KEY, and FOREIGN KEY c<strong>on</strong>straints can be defined <strong>on</strong> viewswhich indirectly create indexes. These c<strong>on</strong>straints are a subset of those availablewith tables and work similarly. <strong>SQL</strong> <strong>Server</strong> allows creati<strong>on</strong> of indexes. However thefirst index has <strong>to</strong> be a unique clustered index. Additi<strong>on</strong>al n<strong>on</strong>clustered indexes canthen be created. Thus, <strong>SQL</strong> <strong>Server</strong> can support the migrati<strong>on</strong> of indexed views.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 125Views can be created using Enterprise Manager, the Create View Wizard, or T-<strong>SQL</strong>. To create a view using Enterprise Manager, follow these steps:1. Open Enterprise Manager, expand <strong>Server</strong>, then Databases, and then the targetdatabase.2. Right-click Views and click New View.3. The view can be created using the dia gram and grid panes (<strong>to</strong>p two areas) or byentering the view query in the <strong>SQL</strong> pa ne (SELECT area). See Figure 6.9.Figure 6.9Using the View Designer of Enterprise Manager To create a view using the Create View Wizard, follow these steps:1. Expand a server group and then expand the server in which <strong>to</strong> create the view.2. On the Tools menu, click Wizards.3. Expand Database.4. Double-click Create View Wizard.5. Complete the steps in the wizard.


126 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas To create a view using T-<strong>SQL</strong>, use the following syntax:Table 6.23 offers a comparis<strong>on</strong> of the CREATE VIEW statements in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>.Table 6.23: <strong>SQL</strong> Statement <str<strong>on</strong>g>for</str<strong>on</strong>g> Creating Views in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE [OR REPLACE] [FORCE |NO FORCE] VIEW [schema.]view_name<strong>SQL</strong> <strong>Server</strong>CREATE VIEW [owner.]view_namename [,…] ) ][ ( column_[ ( column_alias [ inline_c<strong>on</strong>straint ] [,…] [, AS select_statemen<strong>to</strong>ut_of_line_c<strong>on</strong>straint ] ) ]AS select_statement[ WITH READ ONLY ][ [ WITH CHECK OPTION ] [CONSTRAINT c<strong>on</strong>straint_name ] ][ WITH CHECK OPTION ]In O racle, views can be created without permissi<strong>on</strong>s <strong>on</strong> the base objects, or even withoutthe base objects existing, by using the FORCE keyword. This is not allowed in<strong>SQL</strong> <strong>Server</strong>. <strong>SQL</strong> <strong>Server</strong> also does not allow ORDER BY and GROUP BY clauses in theview definiti<strong>on</strong>.Note When a view is created in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> using an asterisk (*) in the SELECT clause, theasterisk is expanded <strong>to</strong> the actual column names in the definiti<strong>on</strong> of the view.SQ L <strong>Server</strong> retains the exact definiti<strong>on</strong> used in the DDL. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does the same thingwhen an asterisk (*) is not used. While c<strong>on</strong>verting from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the viewdefiniti<strong>on</strong> may be changed back <strong>to</strong> an asterisk instead of specifying every column.S<strong>to</strong>red ProgramsOra cle and <strong>SQL</strong> <strong>Server</strong> have the capability <strong>to</strong> s<strong>to</strong>re complex business logic (bey<strong>on</strong>dc<strong>on</strong>straints) inside the database. The code <strong>to</strong> support such requirements cannot beprovided by <strong>SQL</strong> because it cannot execute commands based <strong>on</strong> logical c<strong>on</strong>diti<strong>on</strong>s. Italso fails <strong>to</strong> support looping operati<strong>on</strong>s. In spite of recent extensi<strong>on</strong>s <strong>to</strong> <strong>SQL</strong>, such asinco rporati<strong>on</strong> of a CASE expressi<strong>on</strong>, it is still difficult <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m more than <strong>on</strong>e operati<strong>on</strong>based <strong>on</strong> a logical c<strong>on</strong>diti<strong>on</strong> using these methods. The need <strong>to</strong> implement c<strong>on</strong>trolstructures and programming c<strong>on</strong>structs cannot be met with <strong>SQL</strong> al<strong>on</strong>e. Hence <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>and <strong>SQL</strong> <strong>Server</strong> both offer procedural extensi<strong>on</strong>s <strong>to</strong> <strong>SQL</strong>, PL/<strong>SQL</strong>, and Transact-<strong>SQL</strong> ( T-<strong>SQL</strong>), respectively, that offer a more complete envir<strong>on</strong>ment <str<strong>on</strong>g>for</str<strong>on</strong>g> defining s<strong>to</strong>red programs(or subprograms).S<strong>to</strong>red programs provide modularity (<strong>to</strong>p-down design), encapsulati<strong>on</strong> (logic is hidden),abstracti<strong>on</strong> (black box approach), security (<strong>on</strong>ly execute <strong>on</strong> subprogram), andextensibility (user-defined functi<strong>on</strong>ality). Additi<strong>on</strong>ally, existence inside the databasepromotes accessibility (available <strong>to</strong> all users), reuse (available <strong>to</strong> all database users),speed of executi<strong>on</strong> (s<strong>to</strong>red programs are in compiled <str<strong>on</strong>g>for</str<strong>on</strong>g>m), per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance (handling oflarge amounts of data close <strong>to</strong> its source), and reduced resource requirements (reducesnetwork bandwidth, memory, and so <strong>on</strong> because <strong>on</strong>ly the results are transported).In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, Java can be used <strong>to</strong> write native s<strong>to</strong>red procedures and user-defined functi<strong>on</strong>s.A PL/<strong>SQL</strong> procedure can also call external procedures or functi<strong>on</strong>s written in the Cprogramming language and s<strong>to</strong>red in a shared library.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, there are four types of s<strong>to</strong>red programs: functi<strong>on</strong>s, procedures, packages, andtriggers. These objects are very similar in c<strong>on</strong>structi<strong>on</strong>, functi<strong>on</strong>ality,and usage <strong>to</strong> those


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 127used in <strong>SQL</strong> <strong>Server</strong>. Hence the migrati<strong>on</strong> of their structures is trivial. However, becauseof the vast difference between the syntax in the languages (PL/<strong>SQL</strong> and T-<strong>SQL</strong>) used inthese objects, the migrati<strong>on</strong> of the embedded code is far from trivial.Triggers have already been discussed in this chapter. Functi<strong>on</strong>s, procedures, andpackages are covered here.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> ensures the purity of the acti<strong>on</strong>s that are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med inside s<strong>to</strong>red programs.Hence there are no hidden side effects when migrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> and you canc<strong>on</strong>centrate <strong>on</strong> reproducing the logic using T-<strong>SQL</strong>.Here are a few points that c<strong>on</strong>cern all types of s<strong>to</strong>red programs:● Overloading. <strong>SQL</strong> <strong>Server</strong> does not support overloading, and such functi<strong>on</strong>s andprocedures will have <strong>to</strong> be recreated using unique names.● Executi<strong>on</strong> privileges. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> s<strong>to</strong>red programs can be defined <strong>to</strong> execute withdefiner-rights (owner) or invoker-rights (user). <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>ly uses invoker-rights.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> s<strong>to</strong>red programs that are built <strong>on</strong> definer-rights architecture can bec<strong>on</strong>verted <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> invoker-rights subprograms by properly qualifying objectsinside s<strong>to</strong>red programs. With invoker rights, the schema name could also bepassed in and <strong>SQL</strong> dynamically c<strong>on</strong>structed.● Parameters. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> support positi<strong>on</strong>al, named, or mixednotati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> parameters. <strong>SQL</strong> <strong>Server</strong> c an handle all the types of para meters thatare found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, including tables.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has three parameter modes: IN, OUT, and IN OUT. <strong>SQL</strong> <strong>Server</strong> does notallow the IN OUT type of parameters, and this type warrants some rework in theapplicati<strong>on</strong> design when migrating. Hence IN OUT parameters will have <strong>to</strong> bereplaced with two separate IN and OUT parameters. The keyword OUTPUT isused in place of OUT, while the keyword IN does not exist and is implied becauseit is the default mode. Also, even though it is not a good practice, there is norestrictio n <strong>on</strong> the usage of OUT and IN OUT parameters in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> functi<strong>on</strong>s.Violati<strong>on</strong>s of this rule should be trapped and corrected during migrati<strong>on</strong>.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, IN parameters can be given default values. If suchparameters are skipped during a call, the default value is applied. In <strong>SQL</strong> <strong>Server</strong>,this rule holds <str<strong>on</strong>g>for</str<strong>on</strong>g> s<strong>to</strong>red procedures but not <str<strong>on</strong>g>for</str<strong>on</strong>g> functi<strong>on</strong>s. With functi<strong>on</strong>s, thekeyword "default" has <strong>to</strong> be used in the call <strong>to</strong> the functi<strong>on</strong> and cannot be skippedas with s<strong>to</strong>red procedures (which imply the use of the default value).<strong>SQL</strong> <strong>Server</strong> parameters are prefixed by the at (@) symbol.● Using same name as system. If the first three characters of the procedure nameare sp_, <strong>SQL</strong> <strong>Server</strong> searches the master database <str<strong>on</strong>g>for</str<strong>on</strong>g> the procedure. If noqualified procedure name is provided, <strong>SQL</strong> <strong>Server</strong> searches <str<strong>on</strong>g>for</str<strong>on</strong>g> the procedure as ifthe owner name is dbo. To resolve the s<strong>to</strong>red procedure name as a user-defineds<strong>to</strong>red procedure with the same name as a system s<strong>to</strong>red procedure, provide thefully qualified procedure name.Only the migrati<strong>on</strong> of the object structure is provided in this chapter. Refer <strong>to</strong> Chapter 11,"Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> a detailed discussi<strong>on</strong> aboutmigrating the embedded PL/<strong>SQL</strong> code <strong>to</strong> T-<strong>SQL</strong>.Functi<strong>on</strong>sWhile the system provides several built-infuncti<strong>on</strong>s, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> provide thecapability <strong>to</strong> define cus<strong>to</strong>m functi<strong>on</strong>s called user-defined functi<strong>on</strong>s. These user-definedextensi<strong>on</strong>s <strong>to</strong> <strong>SQL</strong> always return a result. They are employed primarily in <strong>SQL</strong>statements.Functi<strong>on</strong>s can be created using Enterprise Manager or T-<strong>SQL</strong>.


128 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas To create a functi<strong>on</strong> using Enterprise Manager, follow these steps:1. Expand a server group, and then expand a server.2. Expand Databases, and then expand the database in which <strong>to</strong> create the functi<strong>on</strong>.3. Right-click User Defined Functi<strong>on</strong>s and select New User Defined Functi<strong>on</strong>.4. In the Text box, enter the text of the functi<strong>on</strong>. Use TAB <strong>to</strong> indent the text of afuncti<strong>on</strong>.5. To check the syntax, click Check Syntax and OK <strong>to</strong> create. To create a functi<strong>on</strong> using T-<strong>SQL</strong>, use the following syntax:Functi<strong>on</strong>s can be created in <strong>SQL</strong> <strong>Server</strong> using the CREATE FUNCTION statement,which is very similar <strong>to</strong> the <strong>on</strong>e found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, as show in Table 6.24.Table 6.24: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Creating Triggers in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE OR REPLACE FUNCTION[schema.]functi<strong>on</strong>_name[ ({parameter [IN] datatype [=default]} [, …]) ]RETURN scalar_expressi<strong>on</strong>{IS | AS}variable_declarati<strong>on</strong>BEGINstatementsRETURN scalar_expressi<strong>on</strong>EXCEPTIONstatementsEND;<strong>SQL</strong> <strong>Server</strong>CREATE FUNCTION [owner.]functi<strong>on</strong>_name[ ({@parameter [AS] datatype [ =default ]} [, …]) ]RETURN scalar_expressi<strong>on</strong>[ AS ]BEGINvariable_declarati<strong>on</strong>statementsRETURN scalar_expressi<strong>on</strong>ENDS<strong>to</strong>red Procedures<strong>SQL</strong> <strong>Server</strong> has s<strong>to</strong>red procedures that closely resemble <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. These s<strong>to</strong>redprocedures provide the capability <strong>to</strong> pass multiple parameters back <strong>to</strong> the callingenvir<strong>on</strong>ment. Another advantage of s<strong>to</strong>red procedures is that they can per<str<strong>on</strong>g>for</str<strong>on</strong>g>m acti<strong>on</strong>s inthe database without being tied <strong>to</strong> a <strong>SQL</strong> statement.S<strong>to</strong>red procedures can be created using the Create S<strong>to</strong>red Procedure Wizard, EnterpriseManager, or T-<strong>SQL</strong>. To create a view using the Create S<strong>to</strong>red Procedure Wizard, follow thesesteps:1. Expand a server group and then expand the server in which <strong>to</strong> create the view.2. On the Tools menu, click Wizards.3. Expand Database.4. Double-click Create S<strong>to</strong>red Procedure Wizard.5. Complete thesteps in the wizard.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 129 To create a s<strong>to</strong>red procedure using Enterprise Manager, follow these steps:1. Expand a server group, and then expand a server.2. Expand Databases, and then expand the database in which <strong>to</strong> create the s<strong>to</strong>redprocedure.3. Right-click S<strong>to</strong>red Procedures and select New S<strong>to</strong>red Procedure.4. In the Text box, enter the text of the s<strong>to</strong>red procedure. Use TAB <strong>to</strong> indent the textwithin.5. To check the syntax, click Check Syntax and OK <strong>to</strong> create. To create a s<strong>to</strong>red procedure using T-<strong>SQL</strong>, use the following syntax:Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer the CREATE PROCEDURE statement, which is verysimilar in structure and is shown in Table 6.25.Table 6.25: <strong>SQL</strong> Statements <str<strong>on</strong>g>for</str<strong>on</strong>g> Creating Procedures in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE OR REPLACE PROCEDURE[schema.]procedure_name[ ({parameter [IN|OUT|IN OUT]datatype [= default]} [, …]) ]{IS | AS}variable_declarati<strong>on</strong>BEGINstatementsEXCEPTIONstatementsEND;<strong>SQL</strong> <strong>Server</strong>CREATE PROCEDURE [owner.]procedure_name[ ({@parameter [AS] datatype [ =default ] [OUTPUT]} [, …]) ]ASBEGINvariable_declarati<strong>on</strong>statementsENDPackagesOne of the main differentia<strong>to</strong>rs between s<strong>to</strong>red procedures and packages is the capability<strong>to</strong> declare variables in the package header that act as global variables. <strong>SQL</strong> <strong>Server</strong> doesnot have packages, and these have <strong>to</strong> be replaced with s<strong>to</strong>red procedures. However,<strong>SQL</strong> <strong>Server</strong> allows the nesting of procedures, and this capability can be used <strong>to</strong> simulatethe structure of packages by nesting functi<strong>on</strong>s and procedures. Variables can be madeavailable <strong>to</strong> all the nested functi<strong>on</strong>s and procedures by declaring them in the outmost (ormain) procedure. This, however, does not provide database-wide accessibility <strong>to</strong> thesevariables, a shortcoming which has <strong>to</strong> be accommodated by migrating the global variablefrom the package <strong>to</strong> the applicati<strong>on</strong> code.<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s <str<strong>on</strong>g>for</str<strong>on</strong>g> Objects not Found in <strong>SQL</strong> <strong>Server</strong>Some <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> objects, such as syn<strong>on</strong>yms and sequences, are widely used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>applicati<strong>on</strong>s. However, there is no equivalent object with similar functi<strong>on</strong>ality in<strong>SQL</strong> <strong>Server</strong>. Finding soluti<strong>on</strong>s <strong>to</strong> implement the logic and functi<strong>on</strong>ality around theseobjects in <strong>SQL</strong> <strong>Server</strong> is critical <strong>to</strong> the migrati<strong>on</strong>.Syn<strong>on</strong>ymsIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, syn<strong>on</strong>yms are aliases <str<strong>on</strong>g>for</str<strong>on</strong>g> tables, views, sequences, functi<strong>on</strong>s, procedures, andpackages. The primary purpose of using syn<strong>on</strong>yms is <str<strong>on</strong>g>for</str<strong>on</strong>g> locati<strong>on</strong> transparencyandnaming transparency. By creating public syn<strong>on</strong>yms or private syn<strong>on</strong>yms (<str<strong>on</strong>g>for</str<strong>on</strong>g> each user),


130 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemasapplicati<strong>on</strong>s can be written without schema qualificati<strong>on</strong> in the <strong>SQL</strong> code because thequalifier is defined in the syn<strong>on</strong>yms. The original object names can also be hidden.Syn<strong>on</strong>yms <str<strong>on</strong>g>for</str<strong>on</strong>g> tables are more easily migrated by substituting them with views. Viewsprovide the required locati<strong>on</strong> and naming transparency as well. For example, a privatesyn<strong>on</strong>ym, CLINTB.DEPT, which c<strong>on</strong>nects <strong>to</strong> the table HR.DEPARTMENT, can ber eplaced in <strong>SQL</strong> <strong>Server</strong> by a VIEW as follows:CREATE VIEW CLINTB.DEPT AS SELECT * FROM HR.DEPARTMENTOne of the known drawbacks when creating SELECT * views in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> is that anychanges that are made <strong>to</strong> the base table definiti<strong>on</strong> in terms of adding, dropping, andrenaming columns are not au<strong>to</strong>matically reflected in the view definiti<strong>on</strong>. This is because<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> c<strong>on</strong>verts the query piece:SELECT * FROM table_namein<strong>to</strong>S ELECT column_name [, …] FROM table_nameC<strong>on</strong>sequently, when a column is added <strong>to</strong> the base table, the view definiti<strong>on</strong> does notchange. Dropping or renaming a column invalidates the view. However, <strong>SQL</strong> <strong>Server</strong> doesnot have this problem because the view DDL is s<strong>to</strong>red as it was written, that is, SELECT* FROM table_name.I t is not possible <strong>to</strong> find an object-based soluti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> syn<strong>on</strong>yms c<strong>on</strong>necting <strong>to</strong> other typesof objects, such as procedures and sequences. The simplest soluti<strong>on</strong> is <strong>to</strong> qualify theobject schema or owner in the applicati<strong>on</strong> rather than resolve it at the database loginlevel.The inherent quality of <strong>SQL</strong> <strong>Server</strong> in resoluti<strong>on</strong> of objects can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> providing asoluti<strong>on</strong>. Syn<strong>on</strong>yms are usually employed in situati<strong>on</strong>s where there are multiple versi<strong>on</strong>sof the same applicati<strong>on</strong> being used <strong>to</strong> support different clients, with each client having itsown schema. The schema that will be used is driven by the user login and not theapplicati<strong>on</strong> itself. This can be achieved in <strong>SQL</strong> <strong>Server</strong> by setting the default database <str<strong>on</strong>g>for</str<strong>on</strong>g>a user account and giving the login the appropriate privileges at the object level. Thisscheme will work as l<strong>on</strong>g as all the objects that will be accessed are in a single databaseand it is set as the default database <str<strong>on</strong>g>for</str<strong>on</strong>g> the user. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about theseissues, refer <strong>to</strong> Chapter 7, "Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Users."SequencesIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, sequences are aut<strong>on</strong>omous schema objects that can be used <strong>to</strong> generatenumbers that are in sequential order. In applicati<strong>on</strong>s, sequences are comm<strong>on</strong>ly used <strong>to</strong>produce artificial keys <str<strong>on</strong>g>for</str<strong>on</strong>g> tables which do not have a natural key, or the natural key is <strong>to</strong>ol<strong>on</strong>g. <strong>SQL</strong> <strong>Server</strong> does not have an equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g> sequences. However, a <strong>SQL</strong> <strong>Server</strong>table can have columns that are defined with the IDENTITY property, which simulates thebehavior of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> sequences. The IDENTITY column is an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> sequence and tablecolumn rolled in<strong>to</strong> <strong>on</strong>e, that is, the column definiti<strong>on</strong> includes the sequence definiti<strong>on</strong>.The syntax of the <strong>SQL</strong> <strong>Server</strong> IDENTITY property isIDENTITY [(seed, increment)]The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> start with is replaced by the <strong>SQL</strong> <strong>Server</strong> seed.The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> increment by is equivalent <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> incrementThe <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> maxvalue is provided by the <strong>SQL</strong> <strong>Server</strong> column data type.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 131Table 6.26 shows the implementati<strong>on</strong> of the IDENTITY property feature in <strong>SQL</strong> <strong>Server</strong>and what would be the equivalent in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.Table 6.26: Implementati<strong>on</strong> of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Sequence in <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>CREATE SEQUENCE sequence_nameSTART WITH 1 INCREMENT BY 1CREATE TABLE table_name (column1NUMBER DEFAULTsequence_name.NEXTVAl,column2 …);INSERT INTO table_name (column2, …)VALUES ( … )CREATE TABLE table_name (column1NUMBER,column2 …);INSERT INTO table_name (column1,column2, …) VALUES(sequence_name.NEXTVAL, … )<strong>SQL</strong> <strong>Server</strong>-CREATE TA BLE table_name (column1NUMBER IDENTITY(1,1),column2 …);INSERT INTO table_name (column2, …)VALUES ( … )CREATE TABLE table_name (column1NUMBER IDENTITY(1,1),column2 …);INSERT INTO table_name (column2, …)VALUES ( … )One of the advantages of sequences being independent objects is that they can be used<strong>to</strong> supply a unique identifier across multiple tables. This property of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> sequences isnot inherent in <strong>SQL</strong> <strong>Server</strong>’s IDENTITY property. If an identifier is required <strong>to</strong> be uniqueacross tables (or even databases across the globe), use the uniqueidentifier data type,which can be populated using the NEWID() functi<strong>on</strong>. The IDENTITY column can <strong>on</strong>lyhandle unique values and hence it cannot support the cycle feature of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> sequence.A maximum value also cannot be set but can be en<str<strong>on</strong>g>for</str<strong>on</strong>g>ced by choosing an appropriatesized data type <str<strong>on</strong>g>for</str<strong>on</strong>g> the IDENTITY column.Note There is no sufficient in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> inside the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong> figure out howand where a sequence is used. Hence the applicati<strong>on</strong>'s documentati<strong>on</strong>, code, ordeveloper will have <strong>to</strong> be c<strong>on</strong>sulted <strong>to</strong> learn which sequence is used <strong>to</strong> populate acolumn. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is then used <strong>to</strong> define an IDENTITY column in that table.Database Links<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database links are used <strong>to</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>m a bridge between databases (instances). Remoteand distributed transacti<strong>on</strong>s can be executed against the remote database using thedatabase link. <strong>SQL</strong> <strong>Server</strong>provides similar functi<strong>on</strong>ality under the linked server.


132 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasTable 6.27 compares some of the characteristics of database links in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>.Table 6.27: Comparis<strong>on</strong> of Database Links in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>Attribute<str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong>Link Types Public and Private PublicDatabase Types Homogeneous Homogeneous andHeterogeneousCREATE [ PUBLIC ] DATABASELINK [ CONNECT TO {sp_addlinkedserver [ @server= ] 'server'CURRENT_USER | user [ , [ @srvproduct = ]IDENTIFIED BY password } ] 'product_name' ]USING 'c<strong>on</strong>nect_string'[ , [ @provider = ]'provider_name' ][ , [ @datasrc = ]'data_source' ][ , [ @locati<strong>on</strong> = ] 'locati<strong>on</strong>' ][ , [ @provstr = ]'provider_string' ][ , [ @catalog = ] 'catalog'Note The provider_name <str<strong>on</strong>g>for</str<strong>on</strong>g> an OLE DB-based c<strong>on</strong>necti<strong>on</strong> <strong>to</strong> another <strong>SQL</strong> <strong>Server</strong> is'<strong>SQL</strong>OLEDB'.The following example shows the use of sp_addlinkedserver <strong>to</strong> create a linked server <strong>to</strong>c<strong>on</strong>nect <strong>to</strong> another database <str<strong>on</strong>g>for</str<strong>on</strong>g> executing distributed queries:sp_addlinkedserver@server='CORP2',@srvproduct='',@provider='<strong>SQL</strong>OLEDB',@datasrc='SHUTTLE\CORP2'Sample Schema Object Migrati<strong>on</strong>The following example illustrates the schema owner and schema objects migrati<strong>on</strong> taskof the database migrati<strong>on</strong>. The HR schema has been used in this example.1. Create the <strong>SQL</strong> <strong>Server</strong> login account (database authenticated).The following commands create a database-authenticated login with name HR.Use MASTEREXEC sp_addlogin@loginame='HR',@passwd='HR',@defdb='HRDATA'2. Create user account in the database.The following commands create a user account <str<strong>on</strong>g>for</str<strong>on</strong>g> the HR login in the HRDATAdatabase in which objects will be created.Use HRDATAEXEC sp_grantdbaccess@loginame='HR',


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 133@name_in_db='HR'3. Gra nt privileges <strong>to</strong> create objects in the database.Priv ileges can be granted <strong>to</strong> the schema owner <strong>to</strong> create objects in a databaseusing either the CREATE permissi<strong>on</strong>s or the db_owner fixed database role.a.b.Grant complete authority <strong>on</strong> the database.The following command can be used <strong>to</strong> grant the db_owner role:EXEC sp_addrolemember@rolename='db_owner',@membername='HR'Grant privileges <strong>to</strong> create objects <strong>on</strong>ly.The following commands can be executed <strong>to</strong> <strong>on</strong>ly grant permissi<strong>on</strong> <strong>to</strong> createobjects:GRANT CREATE FUNCTION TO HRGRANT CREATE PROCEDURE TO HRGRANT CREATE TABLE TO HRGRANT CREATE VIEW TO HR4. Create sequences.While sequences cannot be migrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about theseq uences in the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database should be extracted first. Because sequencesare migrated <strong>to</strong> IDENTITY columns in tables, the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about sequences isrequired <strong>to</strong> appropriately define tables (in the next step).The following command extracts the required in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> sequences.SELECT sequence_name, min_value, max_value, increment_byFROM dba_sequencesWHERE sequence_owner = 'HR'The following output is obtained:SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BYDEPARTMENTS_SEQ 1 9990 10EMPLOYEES_SEQ 1 999999999999999999999999999 1LOCATIONS_SEQ 1 9900 100The three sequences in the HR schema are assumed <strong>to</strong> be used <strong>to</strong> populate thecolumns DEPARTMENTS.DEPARTMENT_ID, EMPLOYEES.EMPLOYEE_ID andLOCATIONS.LOCATION_ID, respectively.5. Create tables.There are two opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> how <strong>to</strong> migrate tables. Opti<strong>on</strong> <strong>on</strong>e is <strong>to</strong> create tables in aspecific order based <strong>on</strong> the <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints (parent tables first). Opti<strong>on</strong> twois <strong>to</strong> create tables in any order, leaving out the <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints and thenadding them after all the tables have been created.a. Obtain a list of tables.If opti<strong>on</strong> <strong>on</strong>e is followed, the dependenci es between tables and the right orderin which <strong>to</strong> create the tables is required. There are several scripts available(mostly PL/<strong>SQL</strong>-based) <strong>to</strong> produce such a list. Tables without anydependencies <str<strong>on</strong>g>for</str<strong>on</strong>g>m the first level, and other levels are <str<strong>on</strong>g>for</str<strong>on</strong>g>med based <strong>on</strong> thenesting of the dependencies.Note N<strong>on</strong>e of the available scripts will work when there are interdependenciesbetween tables that <str<strong>on</strong>g>for</str<strong>on</strong>g>m a closed loop. The following script shows suchcircular dependencies thatmake these scripts not viable.


134 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasSELECT table_name parent_table_name, NULL child_table_nameFROM dba_tables utWHERE owner = 'HR'AND NOT EXISTS (SELECT 'x'FROM user_c<strong>on</strong>straints ucWHERE c<strong>on</strong>straint_type = 'R'AND ut.table_name = uc.table_name)UNION ALLSELECT p.table_name parent_table_name,c.table_name child_table_nameFROM dba_c<strong>on</strong>straints p, dba_c<strong>on</strong>straints cWHERE p.owner = c.ownerAND p.owner = 'HR'AND p.c<strong>on</strong>straint_type IN ('P','U')AND c.c<strong>on</strong>straint_type = 'R'AND p.c<strong>on</strong>straint_name = c.r_c<strong>on</strong>straint_nameNote In the following output there is a parent-child relati<strong>on</strong>ship betweenEMPLOYEES and DEPARTMENTS in both directi<strong>on</strong>s that creates the loop.PARENT_TABLE_NAME CHILD_TABLE_NAMEJOBSREGIONSREGIONSCOUNTRIESLOCATIONSDEPARTMENTSEMPLOYEESDEPARTMENTSDEPARTMENTS EMPLOYEESJOBSEMPLOYEESEMPLOYEESEMPLOYEESJOBSJOB_HISTORYEMPLOYEESJOB_HISTORYDEPARTMENTS JOB_HISTORYCOUNTRIESLOCATIONSTo implement opti<strong>on</strong> two, first obtain a list of all tables that need <strong>to</strong> be migratedusing the following command:SELECT table_name, tablespace_name, iot_typeFROM dba_tablesWHERE owner = 'HR'The output obtained is:TABLE_NAMECOUNTRIESTABLESPACE_NAMEIOT_TYPEIOTDEPARTMENTS EXAMPLEEMPLOYEES EXAMPLEJOBSEXAMPLEJOB_HISTORY EXAMPLELOCATIONS EXAMPLEREGIONS EXAMPLE


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 135b.Extract DDL al<strong>on</strong>g with c<strong>on</strong>straints.There are several scripts and <strong>to</strong>ols thattable object.can be used <strong>to</strong> extract the DDL <str<strong>on</strong>g>for</str<strong>on</strong>g> theFor an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i database, the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>-supplied package DBMS_METADATAcan be used. First, execute the following in <strong>SQL</strong>*Plus <strong>to</strong> define the output style.set pagesize 0set l<strong>on</strong>g 10000EXECUTEDBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE', FALSE);EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'TABLESPACE', TRUE);EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, '<strong>SQL</strong>TERMINATOR', TRUE);EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'CONSTRAINTS', TRUE);EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'REF_CONSTRAINTS', TRUE);EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'CONSTRAINTS_AS_ALTER', TRUE);Then execute DBMS_METADATA.get_ddl <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the tables. The followingtwo examples show how <strong>to</strong> extract the DDL <str<strong>on</strong>g>for</str<strong>on</strong>g> entire tables using thisprocedure:SELECT dbms_metadata.get_ddl('TABLE', 'COUNTRIES', 'HR')FROM DUAL;The output is as follows:CREATE TABLE "HR"."COUNTRIES"("COUNTRY_ID" CHAR(2) CONSTRAINT "COUNTRY_ID_NN" NOT NULL ENABLE,"COUNTRY_NAME" VARCHAR2(40),"REGION_ID" NUMBER,CONSTRAINT "COUNTRY_C_ID_PK" PRIMARY KEY ("COUNTRY_ID") ENABLE) ORGANIZATION INDEXNOCOMPRESS PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGINGTABLESPACE "EXAMPLE"PCTTHRESHOLD 50;ALTER TABLE "HR"."COUNTRIES" ADD CONSTRAINT"COUNTR_REG_FK" FOREIGN KEY ("REGION_ID")REFERENCES "HR"."REGIONS" ("REGION_ID") ENABLE;Execute the following command <strong>to</strong> obtain the definiti<strong>on</strong> of the LOCATIONStable.SELECT dbms_metadata.get_ddl('TABLE', 'LOCATIONS', 'HR')FROM DUAL;The output returned is:CREATE TABLE "HR"."LOCATIONS"("LOCATION_ID" NUMBER(4,0),"STREET_ADDRESS" VARCHAR2(40),"POSTAL_CODE" VARCHAR2(12),"CITY" VARCHAR2(30) CONSTRAINT "LOC_CITY_NN" NOT NULL ENABLE,"ST ATE_PROVINCE"VARCHAR2(25),"COUNTRY_ID" CHAR(2)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGINGTABLESPACE "EXAMPLE" ;


136 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasCREATE UNIQUE INDEX "HR"."LOC_ID_PK" ON"HR"."LOCATIONS" ("LOCATION_ID")PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGINGTABLESPACE "INDX" ;ALTER TABLE "HR"."LOCATIONS" ADD CONSTRAINT"LOC_ID_PK" PRIMARY KEY ("LOCATION_ID")USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGINGTABLESPACE "INDX" ENABLE;ALTER TABLE "HR"."LOCATIONS" ADD CONSTRAINT"LOC_C_ID_FK" FOREIGN KEY ("COUNTRY_ID")REFERENCES "HR"."COUNTRIES" ("COUNTRY_ID") ENABLE;c. C<strong>on</strong>vert the extracted <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DDL <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> syntax.In this step, the table DDL is c<strong>on</strong>verted al<strong>on</strong>g with c<strong>on</strong>straint and indexdefiniti<strong>on</strong>s. Foreign key c<strong>on</strong>straints are handled separately in the next step.Create clustered indexes be<str<strong>on</strong>g>for</str<strong>on</strong>g>e creating any n<strong>on</strong>-clustered indexes. Ifclustered indexes are planned <str<strong>on</strong>g>for</str<strong>on</strong>g> a table, defer creati<strong>on</strong> of n<strong>on</strong>clusteredindexes (as part of PRIMARY KEY or UNIQUE c<strong>on</strong>straint definiti<strong>on</strong>) during thetable creati<strong>on</strong> in this step.The first table in the example, COUNTRIES, is an index-organized table. For<strong>SQL</strong> <strong>Server</strong>, it is c<strong>on</strong>verted in<strong>to</strong> a heap with a clustered index <strong>on</strong> the primarykey, COUNTRY_ID.Note In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, there is a single datatype of the number variety which isc<strong>on</strong>strained with appropriate scale. While c<strong>on</strong>verting <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the datatype which is closest in scale needs <strong>to</strong> be used, as has been dem<strong>on</strong>strated inthe example.The following commands are used <strong>to</strong> create the COUNTRIES andLOCATIONS tables respectively.CREATE TABLE HR.COUNTRIES(COUNTRY_ID CHAR(2) CONSTRAINT NN_COUNTRY_ID NOT NULL,COUNTRY_NAME VARCHAR(40),REGION_ID NUMERIC,CONSTRAINT PK_COUNTRY_C_ID PRIMARY KEY CLUSTERED (COUNTRY_ID)ON HR_INDX)CREATE TABLE HR.LOCATIONS(LOCATION_ID SMALLINT NOT NULL,STREET_ADDRESS VARCHAR (40),POSTAL_CODE VARCHAR(12),CITY VARCHAR(30) CONSTRAINT NN_LOC_CITY NOT NULL,STATE_PROVINCE VARCHAR(25),COUNTRY_ID CHAR(2))ALTER TABLE HR. LOCATIONS ADD CONSTRAINTPK__ID PRIMARY KEY NONCLUSTERED (LOCATION_ID)ON HR_INDX


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 1376.d.Create the <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints.After all the tables have been created, the <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints can becreated in any order.The following commands create <str<strong>on</strong>g>for</str<strong>on</strong>g>eign keys <strong>on</strong> the COUNTRIES andLOCATIONS tables.ALTER TABLE HR.COUNTRIES ADD CONSTRAINTFK_COUNTR_REG FOREIGN KEY (REGION_ID)REFERENCES HR.REGIONS (REGION_ID);ALTER TABLE HR.LOCATIONS ADD CONSTRAINTFK_LOC_C_ID FOREIGN KEY (COUNTRY_ID)REFERENCES HR.COUNTRIES (COUNTRY_ID);e. Extract and migrate the table comments.The following command can be used <strong>to</strong> extract comments in tables in the HRschema.SELECT table_name, commentsFROM dba_tab_commentsWHERE owner = 'HR'AND comments IS NOT NULLThe output returned c<strong>on</strong>tains the comments <str<strong>on</strong>g>for</str<strong>on</strong>g> the tables in the HR schema,such as COUNTRIES, DEPARTMENTS, EMPLOYEES, JOBS,JOB_HISTORY and LOCATIONS. The output can then be copied in<strong>to</strong> thestatements <str<strong>on</strong>g>for</str<strong>on</strong>g> adding comments <strong>to</strong> tables in <strong>SQL</strong> <strong>Server</strong>.The following is an example of the use of the sp_addextendedpropertyprocedure <strong>to</strong> add a comment <strong>on</strong> the COUNTRIES table.sp_addextendedproperty 'comment', 'country table. C<strong>on</strong>tains 25 rows.References with locati<strong>on</strong>s table.', 'user', HR, 'table', countriesf. Extract and migrate the column comments:SELECT table_name, column_name, commentsFROM dba_col_commentsWHERE owner = 'HR'AND comments IS NOT NULLThe output c<strong>on</strong>tains the column level comments.The following is an example of the use of the sp_addextendedpropertyprocedure <strong>to</strong> add a comment <strong>on</strong> the REGION_ID column of the COUNTRIEStable.sp_addextendedproperty 'comment', 'Regi<strong>on</strong> ID <str<strong>on</strong>g>for</str<strong>on</strong>g> the country. Foreignkey <strong>to</strong> regi<strong>on</strong>_id column in the departments table.' , 'user', hr,'table', countries, 'column', regi<strong>on</strong>_idCreate triggers.This step dem<strong>on</strong>strates how <strong>to</strong> migrate the table triggers from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong><strong>SQL</strong> <strong>Server</strong>. The logic (code) that is embedded in the triggers is not discussedhere. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer <strong>to</strong> the "<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data Access" secti<strong>on</strong> inChapter 11, "Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>."SELECT table_name, 'CRE ATE TRIGGER ' || descripti<strong>on</strong> headerFROM dba_triggersWHERE owner = table_ownerAND table_owner = 'HR'AND base_object_type = 'TABLE'TABLE_NAME HEADEREMPLOYEES CREATE TRIGGER secure_employees


138 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasBEFORE INSERT OR UPDATE OR DELETE ON employeesEMPLOYEES CREATE TRIGGER update_job_his<strong>to</strong>ryAFTER UPDATE OF job_id, department_id ON employeesFOR EACH ROWThe equivalent syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> can be generated with the aid of Table 6.24.The commands <str<strong>on</strong>g>for</str<strong>on</strong>g> creating the secure_ employees and update_job_his<strong>to</strong>rytriggers will c<strong>on</strong>vert as:7.CREATE TRIGGER secure_employeesON employeesINSTEAD OF INSERT, UPDATE, DELETEAS…GOCREATE TRIGGER update_job_his<strong>to</strong>ryON employeesAFTER UPDATEAS…GOIF (UPDATE(job_id) or UPDATE(department_id))Create indexes.All indexes related <strong>to</strong> c<strong>on</strong>straints should have been created in Substep 5.b. Thisstep covers the indexes that are not related <strong>to</strong> any c<strong>on</strong>straints.The following query can be used <strong>to</strong> retrieve in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> indexes in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> thatare not related <strong>to</strong> any c<strong>on</strong>straints. This query will work <strong>on</strong>ly in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i becausethe data dicti<strong>on</strong>ary be<str<strong>on</strong>g>for</str<strong>on</strong>g>e this release of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does not have the columns used inthis query.SELECT i.table_name, i.index_name, c.column_name, i.uniqueness,i.tablespace_name, i.pct_freeFROM dba_indexes i, dba_ind_columns cWHERE i.table_name = c.table_nameAND i.index_name = c.index_nameAND i.owner = c.index_ownerAND i.owner = 'HR'AND (i.owner, i.index_name) NOT IN(SELECT index_owner, index_nameFROM dba_c<strong>on</strong>straintsWHERE owner = 'HR'AND index_name IS NOT NULL)ORDER BY i.table_name, i.index_name, c.column_positi<strong>on</strong>The output obtained has been <str<strong>on</strong>g>for</str<strong>on</strong>g>matted as follows:TABLE_NAME INDEX_NAMECOLUMN_NAMEUNIQUENESSTABLESPACE_NAMEPCT_FREEDEPARTMENTSDEPT_LOCATION_IX LOCATION_ID NONUNIQUEINDX 10EMPLOYEES EMP_DEPARTMENT_IXINDX 10EMPLOYEES EMP-JOB-IXINDX 10DEPARTMENT_IDJOB_IDNONUNIQUENONUNIQUE


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 139EMPLOYEES EMP_MANAGER_IX MANAGER_ID NONUNIQUEINDX 10EMPLOYEES EMP_NAME_IX LAST_NAME NONUNIQUEINDX 10EMPLOYEES EMP_NAME_IXFIRST_NAMENONUNIQUEINDX10JOB_HISTORYJHIST_ DEPARTMENT_IX DEPARTMENT_ID NONUNIQUEINDX10JOB_HISTORYJHIST_EMPLOYEE_IX EMPLOYEE_ID NONUNIQUEINDX10JOB_HISTORYJHIST_ JOB_IX JOB_ID NONUNIQUEINDX10LOCATIONS LOC_CITY_IX CITY NONUNIQUEINDX10LOCATIONS LOC_COUNTRY_IX COUNTRY_ID NONUNIQUEINDX10LOCATIONS LOC_STATE_PROVINCE_IX STATE_PROVINCE NONUNIQUEINDX10This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> can be used <strong>to</strong> create indexes in <strong>SQL</strong> <strong>Server</strong> as follows:CREATE NONCLUSTEREDINDEX hr.dept_locati<strong>on</strong>_ixON hr.departments(locati<strong>on</strong>_id)WITH FILLFACTOR = 90ON HR_INDXCREATE NONCLUSTERED INDEX hr.emp_name_ixON hr.employees(last_name, first_name)WITH FILLFACTOR = 90ON HR_INDXBecause indexes have been created over several steps, you should verify that anequivalent index has been created in <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> each index in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, generate a listing of all indexes using the following command:8.SELECT i.table_name, i.index_name,c.column_name, i.uniqueness, i. tablespace_name,i.pct_freeFROM dba_indexes i, dba_ind_columns cWHERE i.table_name = c.table_nameAND i.index_name = c.index_nameAND i.owner = c.index_ownerAND i.owner = 'HR'ORDER BY i.table_name, i.index_name, c.column_positi<strong>on</strong>In <strong>SQL</strong> <strong>Server</strong>, execute the following command <strong>on</strong> each table with the table namesubstituted <str<strong>on</strong>g>for</str<strong>on</strong>g> name <strong>to</strong> retrieve in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the indexes available <str<strong>on</strong>g>for</str<strong>on</strong>g> the table:sp_helpindex [ @objname = ] 'name'Create views.Extract the views and their definiti<strong>on</strong> from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> using the following command:SELECT view_name, textFROM dba_viewsWHERE owner = 'HR'The output provides the view query.


140 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasThe query <str<strong>on</strong>g>for</str<strong>on</strong>g> DEPT is as follows:select "DEPARTMENT_ID", "DEPARTMENT_NAME", "MANAGER_ID", "LOCATION_D","DEPT_LOC"from hr.departmentsThe query <str<strong>on</strong>g>for</str<strong>on</strong>g> EMB_DETAILS_VIEW is as follows:SELECTe.employee_id,e.job_id,e.manager_id,e.department_ id,d.locati<strong>on</strong>_id,l.country_id,e.first_name,e.last_name,e.salary,e.commissi<strong>on</strong>_pct,d.department_ name,j.job_title,l.city,l.state_province,c.country_name,r.regi<strong>on</strong>_nameFROMemployees e,departments d,jobs j,locati<strong>on</strong>s l,countries c,regi<strong>on</strong>s rWHERE e.department_id = d.department_idAN D d.locati<strong>on</strong>_id = l.locati<strong>on</strong>_idAND l.country_id = c.country_idAN D c.regi<strong>on</strong>_id = r.regi<strong>on</strong>_idAND j.job_id = e.job_idWITH READ ONLYFor the view DEPT, the view text shows capitalized names enclosed in doublequotes <str<strong>on</strong>g>for</str<strong>on</strong>g> the column names:select "DEPARTMENT_ID", "DEPARTMENT_NAME", "MANAGER_ID", "LOCATION_D","DEPT_LOC" from hr.departmentsThis is an indicati<strong>on</strong> that the column names were filled in by the system, and theoriginal DDL <str<strong>on</strong>g>for</str<strong>on</strong>g> the CREATE VIEW dept is as follows:select * from hr.departmentsAs pointed out in the discussi<strong>on</strong> <strong>on</strong> using views instead of syn<strong>on</strong>yms <str<strong>on</strong>g>for</str<strong>on</strong>g> tables,<strong>SQL</strong> <strong>Server</strong> retains the exact definiti<strong>on</strong> used in the DDL. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does the samething when an asterisk (*) is not used. This behavior is shown in theEMP_DETAILS_VIEW view text. Thus, while c<strong>on</strong>verting the syntax, the DDL maybe changed back <strong>to</strong> an asteriskinstead of specifying every column.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 141Note The DEPT view was added <strong>to</strong> the HR schema <strong>to</strong> dem<strong>on</strong>strate this point.The EMP_DETAILS_VIEW can be created under the HR schema using thefollowing command:CREATE VIEW hr.EMP_DETAILS_VIEW ASSELECTe.employee_id,e.job_id,e.manager_id,e.department_id,d.locati<strong>on</strong>_id,l.country_id,e. first_name,e.last_name,e.salary,e.commissi<strong>on</strong>_pct,d.department_name,j.job_title,l.city,l.state_province,c.country_name,r.regi<strong>on</strong>_nameFROM hr.employees e INNER JOIN hr.departments dON e.department_id = d.department_idINNER JOIN hr.locati<strong>on</strong>s lON d.locati<strong>on</strong>_id = l.locati<strong>on</strong>_idINNER JOIN hr.countries cON l.country_id = c.country_idINNER JOIN hr.regi<strong>on</strong>s rON c.regi<strong>on</strong>_id = r.regi<strong>on</strong>_idINNER JOIN hr.jobs jON j.job_id = e.job_id;The WITH READ ONLY clause will have <strong>to</strong> be en<str<strong>on</strong>g>for</str<strong>on</strong>g>ced by ensuring <strong>on</strong>ly SELECTprivilege is given <strong>to</strong> users.9. Create functi<strong>on</strong>s, s<strong>to</strong>red procedures, and packages.The following command can be used <strong>to</strong> get a listing of all functi<strong>on</strong>s defined by theschema owner, HR:SELECT object_name, object_typeFROM dba_objectsWHERE owner = 'HR'AND object_type IN ('FUNCTION', 'PROCEDURE', 'PACKAGE', 'PACKAGE BODY')The output retuned is:OBJECT_NAME OBJECT_TYPEADD_JOB_HISTORY PROCEDURESECURE_DML PROCEDUREThe source code of each of these objects can be extracted from the data dicti<strong>on</strong>aryusing the command:


142 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> SchemasSELECT textFROM dba_sourceWHERE owner = 'HR'AND NAME = 'ADD_JOB_HISTORY'ORDER BY lineThe output is:TEXTPROCEDURE add_job_his<strong>to</strong>ry( p_emp_id job_his<strong>to</strong>ry.employee_id%type, p_start_date job_his<strong>to</strong>ry.start_date%type, p_end_date job_his<strong>to</strong>ry.end_date%type, p_job_id job_his<strong>to</strong>ry.job_id%type, p_department_id job_his<strong>to</strong>ry.department_id%type)ISBEGININSERT INTO job_his<strong>to</strong>ry (employee_id, start_date,end_date, job_id, department_id)VALUES(p_emp_id, p_start_date, p_end_date, p_job_id, p_department_id);END add_job_his<strong>to</strong>ry;An overview of the ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t in migrating functi<strong>on</strong>s, s<strong>to</strong>red procedures, and packageshas been given in the "S<strong>to</strong>red Programs" secti<strong>on</strong> of this chapter. For a detaileddiscussi<strong>on</strong> of migrating the code, refer <strong>to</strong> the "<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data Access" secti<strong>on</strong>in Chapter 11.10. Create syn<strong>on</strong>yms.Syn<strong>on</strong>yms are used with n<strong>on</strong>-schema users <strong>to</strong> provide locati<strong>on</strong> transparency.Because <strong>SQL</strong> <strong>Server</strong> does not support syn<strong>on</strong>yms, the <strong>SQL</strong> will have <strong>to</strong> bemodified <strong>to</strong> c<strong>on</strong>tain a schema prefix.Note An <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schema could potentially have objects or properties that are not inuse. Examples of such objects are disabled c<strong>on</strong>straints, invalid views, invalidsyn<strong>on</strong>yms, invalid functi<strong>on</strong>, invalid procedures, and dropped column (not purgedfrom table). Although it is not necessary <strong>to</strong> migrate these objects <strong>to</strong> the newenvir<strong>on</strong>ment, certain clients may differ in this regard.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 1437Developing: Databases —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database UsersIntroducti<strong>on</strong> and GoalsChapter 6, "Developing: Database — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas," c<strong>on</strong>centrated strictly <strong>on</strong> themigrati<strong>on</strong> of the schema, its owner, and objects. The other class of database users is the<strong>on</strong>e that accesses the data in the tables of these schemas. These users do not own anyobjects, such as tables or views, but may have some syn<strong>on</strong>yms that may point <strong>to</strong> thetables and views in the applicati<strong>on</strong> schema. The ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t in migrating these users <strong>to</strong>Microsoft® <strong>SQL</strong> <strong>Server</strong> is in creating the users and reproducing the privileges theypossess in the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database. The privileges may be granted <strong>to</strong> the user directly orthrough roles. The migrati<strong>on</strong> of roles is also discussed in this chapter.The steps in migrating the users are:1. Create the user account.2. Create roles and grant privileges.Create User AccountsA detailed discussi<strong>on</strong> of database accounts, authenticati<strong>on</strong>, and password managementwas provided in the "Create the Schema Owner" secti<strong>on</strong> of Chapter 6. The creati<strong>on</strong> ofuser accounts does not differ from the creati<strong>on</strong> of schema accounts in any respect. Thedifference is in the privileges that they are granted. Figure 7.1 shows the relati<strong>on</strong>shipbetween database users, roles, and schema objects.


144 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database UsersFigure 7.1Dependencies in the migrati<strong>on</strong> of users from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>The following query can be run in the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong> create a list of users thathave privileges <strong>on</strong> any object in a specific schema. The query has been c<strong>on</strong>strained <strong>to</strong><strong>on</strong>ly a specific schema and its users. This aids in situati<strong>on</strong>s where <strong>on</strong>ly a subset of theschemas and the related users are migrated from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.SELECT granteeFROM dba_tab_privsWHERE owner = usernameUNIONSELECT granteeFROM dba_col_privsWHERE owner = usernameThe grantee could be a user or a role. As with the case of the schema owner, thefollowing query can be used <strong>to</strong> retrieve the characteristics of any login.SELECT du.username,DECODE(du.password,'EXTERNAL','EXTERNAL','DB') "AUTHENTICATION MODE",du.default_tablespace, du.temporary_tablespace,dp.resource_name, dp.limitFROM dba_users du, dba_profiles dpWHERE du.profile = dp.profileAND dp.resource_type = 'PASSWORD'AND du.username = usernameThe system s<strong>to</strong>red procedure sp_grantlogin is used <strong>to</strong> create a <strong>SQL</strong> <strong>Server</strong> login <str<strong>on</strong>g>for</str<strong>on</strong>g> adomain-authenticated account, and sp_addlogin is used <strong>to</strong> create a <strong>SQL</strong> <strong>Server</strong>authenticated account. The procedure sp_grantdbaccess is used <strong>to</strong> create user


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 145accounts in the individual databases <str<strong>on</strong>g>for</str<strong>on</strong>g> these logins. User accounts should be created ina database <strong>on</strong>ly if there are objects in the database the user needs <strong>to</strong> access.Note While migrating <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> accounts, there may be user accounts that are locked.The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBA of the original envir<strong>on</strong>ment should be c<strong>on</strong>sulted be<str<strong>on</strong>g>for</str<strong>on</strong>g>e makingdecisi<strong>on</strong>s <strong>on</strong> whether <strong>to</strong> migrate these accounts.Create Roles and Grant PrivilegesA privilege is permissi<strong>on</strong> (as it is called in <strong>SQL</strong> <strong>Server</strong>) <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m work inside thedatabase. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> provide two sets of privileges: system privileges andobject privileges.Table 7.1 provides terms relating <strong>to</strong> privileges in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> that can helpavoid any c<strong>on</strong>fusi<strong>on</strong> during a migrati<strong>on</strong>.Table 7.1: Privilege Terms Used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> TerminologyPrivilegeSystem privilegeObject privilegePredefined role permissi<strong>on</strong> (<str<strong>on</strong>g>for</str<strong>on</strong>g> example,DBA)Grantee<strong>SQL</strong> <strong>Server</strong> TerminologyPermissi<strong>on</strong>Statement permissi<strong>on</strong>Object permissi<strong>on</strong>Implied permissi<strong>on</strong>s (<str<strong>on</strong>g>for</str<strong>on</strong>g> example,sysadmin)Security accountWhile <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has several object privileges, the <strong>on</strong>es comm<strong>on</strong>ly granted <strong>to</strong> users areSELECT, INSERT, DELETE, and UPDATE <strong>on</strong> tables and EXECUTE <strong>on</strong> s<strong>to</strong>redprograms. <strong>SQL</strong> <strong>Server</strong> has the same object privileges.System and object privileges can be granted <strong>to</strong> users either directly or through roles.<strong>SQL</strong> <strong>Server</strong> also offers the WITH GRANT OPTION clause <str<strong>on</strong>g>for</str<strong>on</strong>g> object privileges.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> differ a lot in the system privileges that are available. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> hasvery granular (more than 100) system privileges. <strong>SQL</strong> <strong>Server</strong> system privileges, calledstatement permissi<strong>on</strong>s, are restricted <strong>to</strong> the following list:● BACKUP DATABASE● BACKUP LOG● CREATE DATABASE● CREATE DEFAULT● CREATE FUNCTION● CREATE PROCEDURE● CREATE RULE● CREATE TABLE● CREATE VIEWThe rest of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> system privileges are bundled in<strong>to</strong> several large fixed roles. Forexample, the fixed database role db_datareader is equivalent <strong>to</strong> the SELECT ANYTABLE system privilege in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer predefined roles and user-defined roles. The predefinedroles have powerful system and object privileges <strong>on</strong> the data dicti<strong>on</strong>ary and the instance.


146 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database UsersThe "Roles" <strong>to</strong>pic in <strong>SQL</strong> <strong>Server</strong> Books Online provides a list of fixed server roles andfixed database roles and their descripti<strong>on</strong>. User-defined roles can be granted system aswell as object privileges.The privileges <str<strong>on</strong>g>for</str<strong>on</strong>g> administrative users should be revisited when migrating <strong>to</strong> a<strong>SQL</strong> <strong>Server</strong> database because each database is far more self-c<strong>on</strong>tained with respect <strong>to</strong>administrati<strong>on</strong>. Fixed database roles can be granted privileges <strong>on</strong> a single databaseinstead of the system-wide powers af<str<strong>on</strong>g>for</str<strong>on</strong>g>ded by the DBA role in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. A completediscussi<strong>on</strong> of the system privileges and their equivalents in <strong>SQL</strong> <strong>Server</strong> is bey<strong>on</strong>d thescope of this guidance. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the fixed server roles and fixeddatabase roles available in <strong>SQL</strong> <strong>Server</strong> and their descripti<strong>on</strong>s, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/architec/8_ar_da_3xns.asp.There are two important s<strong>to</strong>red procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> granting system privileges in <strong>SQL</strong> <strong>Server</strong>:sp_addsrvrolemember can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> granting fixed system roles andsp_addrolemember can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> granting fixed database roles.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, roles are available at the instance or server level and can be granted privileges<strong>on</strong> more than <strong>on</strong>e schema. <strong>SQL</strong> <strong>Server</strong> user-defined roles are local <strong>to</strong> a database andowned by a user. Hence, when migrating a role from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, a role has <strong>to</strong>be created in each of the databases in which privileges have <strong>to</strong> be granted. To grant privileges and roles <strong>to</strong> a user, follow these steps:1. Create role(s) in each of the <strong>SQL</strong> <strong>Server</strong> database(s) that will be used <strong>to</strong> c<strong>on</strong>trolthe permissi<strong>on</strong> given <strong>to</strong> users. A role can be created in a database using thefollowing commands:Use databaseGOsp_addrole [ @rolename = ] 'role_name'[ , [ @ownername = ] 'owner' ]GOWhere role_name is the name of the role <strong>to</strong> be created and owner is the user whowill own the role (which will normally be the schema owner or a security account<str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong>).2. System level privileges can either be granted <strong>to</strong> the role created in step 1 ordirectly <strong>to</strong> the user. The following statement can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> granting systemprivileges <strong>to</strong> roles and users:GRANT {ALL | system_privilege_name}TO {user_name | role_name}Where system_privilege_name is the system privilege <strong>to</strong> be granted, user_name isthe name of the user <strong>to</strong> whom the grant is made, and role_name is the name of therole through which the privileges will be granted <strong>to</strong> the user.3. As with system privileges, object privileges can be granted directly <strong>to</strong> the user orthrough roles. The following statement can be used <strong>to</strong> grant object privileges <strong>to</strong>users and roles:GRANT {ALL | object_privilege_name}ON object_nameTO {user_name | role_name}[WITH GRANT OPTION]Where object_privilege_name is the object privilege <strong>to</strong> be granted, object_name isthe object <strong>on</strong> which the privilege is granted, user_name is the name of the user <strong>to</strong>whom the grant is made, and role_name is the name of the role through which theprivileges will be granted <strong>to</strong> the user.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 147Object privileges can also be granted at the more granular column level instead of<strong>on</strong> the entire table. The following statement can be used <strong>to</strong> grant privileges <strong>on</strong> <strong>on</strong>eor more columns of a table:GRANT {ALL | object_privilege_name}ON table_name ( column_name [,…] )TO {user_name | role_name}[WITH GRANT OPTION]Where object_privilege_name is the object privilege <strong>to</strong> be granted, table_name isthe table <strong>to</strong> which the column bel<strong>on</strong>gs, column_name is the specific column <strong>on</strong> whichthe privilege is being granted, user_name is the name of the user <strong>to</strong> whom the grantis made, and role_name is the name of the role through which the privileges will begranted <strong>to</strong> the user.4. If privileges are being granted through a role, the role can be granted <strong>to</strong> a userusing the following command:sp_addrolemember [ @rolename = ] 'role_name' ,[ @membername = ] 'user_name'Where role_name is the name of the role <strong>to</strong> be granted and user_name is the targetuser.Sample User Migrati<strong>on</strong>When a user is migrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the same security architecture canbe maintained by creating roles and granting privileges in a functi<strong>on</strong>ally equivalentmanner. The difference in the implementati<strong>on</strong> is depicted in Figure 7.1.Privileges <strong>on</strong> objects in a database are given <strong>to</strong> a local user account at the databaselevel and do not transgress database boundaries. This implies that, <str<strong>on</strong>g>for</str<strong>on</strong>g> a server orinstance level login, a user account has <strong>to</strong> be created in each of the databases that itneeds privileges in (either directly or through roles). The following steps are a practicalexample of how <strong>to</strong> migrate the security architecture of an applicati<strong>on</strong> and its user from<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. This example is an extenuati<strong>on</strong> of the migrati<strong>on</strong> of the HR schemain <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> which was started in Chapter 6.1. Create the user account in <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> each of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> users.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, there is a single user account that is granted privileges <strong>on</strong> variousschemas. In <strong>SQL</strong> <strong>Server</strong>, the single user account translates <strong>to</strong> a two-tierimplementati<strong>on</strong>.a. Obtain a list of user accounts in the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database that have <strong>to</strong> be migrated<strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. The list can be obtained using the following statement:SELECT granteeFROM dba_tab_privsWHERE owner = 'HR'UNIONSELECT granteeFROM dba_col_privsWHERE owner = 'HR'where owner is the name of the schema whose security is being migrated.The following is the output <str<strong>on</strong>g>for</str<strong>on</strong>g> the HR schema.GRANTEEOE


148 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Usersb.Obtain the characteristics of user accounts in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> that were identified insubstep a.The following statement can be executed <strong>to</strong> gather in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> each of theuse rs <strong>to</strong> be migrated:SELECT du.username,DECODE(du.password,'EXTERNAL','EXTERNAL','DB')"AUTHENTICATION MODE",du.default_tablespace, du.temporary_tablespace,dp.resource_name, dp.limitFROM dba_users du, dba_profiles dpWHERE du.profile = dp.profileAND dp.resource_type = 'PASSWORD'AND du.username = 'OE'where OE is the name of the user that is being migrated.The privileges granted <strong>to</strong> OE user are:USERNAME AUTHENTICATION MODE DEFAULT_TABLESPACETEMPORARY_TABLESPACE RESOURCE_NAMELIMITOEDBEXAMPLETEMPFAILED_LOGIN_ATTEMPTS UNLIMITEDOEDBEXAMPLETEMPPASSWORD_LIFE_TIME UNLIMITEDOEDBEXAMPLETEMPPASSWORD_REUSE_TIME UNLIMITEDOEDBEXAMPLETEMPPASSWORD_REUSE_MAX UNLIMITEDOEDBEXAMPLETEMPPASSWORD_VERIFY_FUNCTION NULLOEDBEXAMPLETEMP PASSWORD_LOCK_TIME UNLIMITEDOE DB EXAMPLETEMP PASSWORD_GRACE_TIME UNLIMITEDc.Create <strong>SQL</strong> <strong>Server</strong> login accounts that provide access <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong>instance.Because the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> account in this example is database-authenticated andn<strong>on</strong>e of the password features are in use, the <strong>SQL</strong> <strong>Server</strong> login can be createdas a <strong>SQL</strong> <strong>Server</strong>-authenticated login.The following commands can be executed <strong>to</strong> create the <strong>SQL</strong> <strong>Server</strong> login <str<strong>on</strong>g>for</str<strong>on</strong>g>the user OE with the password OE in the HRDATA database in<strong>to</strong> which the HRschema's objects are migrated:Use MASTEREXEC sp_addlogin@loginame='OE',@passwd='OE',@defdb='HRDATA'd. Create a user account in each of the databases in which the schema's objectshave been migrated.The databases in which user accounts have <strong>to</strong> be created depend <strong>on</strong> the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> schemas <str<strong>on</strong>g>for</str<strong>on</strong>g> which the user has privileges and the <strong>SQL</strong> <strong>Server</strong>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 149database <strong>to</strong> which they have been migrated. The following statement can beused <strong>to</strong> see the schemas <strong>on</strong> which the user OE has been granted privileges.SELECT ownerFROM dba_tab_privsWHERE grantee = 'OE'UNIONSELECT ownerFROM dba_col_privsWHERE grantee = 'OE'The output of the statement is as follows:OWNERHRSYSIn Chapter 6, the HR schema was migrated <strong>to</strong> the HRDATA database in<strong>SQL</strong> <strong>Server</strong>. SYS is the data dicti<strong>on</strong>ary owner, which translates <strong>to</strong> masterdatabase in <strong>SQL</strong> <strong>Server</strong>. However, because the data dicti<strong>on</strong>ary is dividedbetween the master database and the applicati<strong>on</strong> (user-created) databases,<str<strong>on</strong>g>for</str<strong>on</strong>g> an applicati<strong>on</strong> user, an account in the master database may not benecessary and should be created after proper scrutiny of the securityrequirements.The following commands can be used <strong>to</strong> create a user <str<strong>on</strong>g>for</str<strong>on</strong>g> the OE login in theHRDATA database:Use HRDATAEXEC sp_grantdbaccess@loginame='OE',@name_in_db='OE'2.Create roles through which the privileges will be granted <strong>to</strong> users.Only those roles that are granted <strong>to</strong> users and schemas that are being migratedwill be created in <strong>SQL</strong> <strong>Server</strong>. Also, the role has <strong>to</strong> be created in each of thedatabases with the applicati<strong>on</strong> schema as the owner.The following statement can be used <strong>to</strong> retrieve the roles that have been granted<strong>to</strong> the user OE:SELECT granted_role, admin_opti<strong>on</strong>FROM dba_role_privsWHERE grantee = 'OE'The following is the output <str<strong>on</strong>g>for</str<strong>on</strong>g> the OE user:3.GRANTED_ROLECONNECTRESOURCEADMIN_OPTIONNONOThe CONNECT and RESOURCE roles are both system roles. No applicati<strong>on</strong> rolesare in use <str<strong>on</strong>g>for</str<strong>on</strong>g> this schema. Hence all system and object privileges will be granteddirectly <strong>to</strong> the user. If you want <strong>to</strong> introduce roles in <strong>SQL</strong> <strong>Server</strong>, it should beper<str<strong>on</strong>g>for</str<strong>on</strong>g>med at this point.Grant privileges and/or roles <strong>to</strong> the user.The roles that were identified in Step 2 are granted here.The CONNECT role gives the user the capability <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database. In <strong>SQL</strong> <strong>Server</strong>, the same privileges are inherently granted when thelogin and user accounts are created. The RESOURCE role gives the capability <strong>to</strong>create objects in the database. Thereis no role in <strong>SQL</strong> <strong>Server</strong> that provides the


150 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Database Userssame level of privileges as RESOURCE. As a result, the following privileges aregranted.GRANT CREATE FUNCTION TO OEGRANT CREATE PROCEDURE TO OEGRANT CREATE TABLE TO OEGRANT CREATE VIEW TO OEThe following statement is used <strong>to</strong> retrievethe OE user:system and object privileges granted <strong>to</strong>SELECT do.object_type Lvl, dtp.privilege, dtp.grantable, dtp.owner,dtp.table_name, NULL column_nameFROM dba_tab_privs dtp, dba_objects doWHERE dtp.owner = do.ownerAND dtp.table_name = do.object_nameAND grantee = 'OE'UNIONSELECT 'Column', privilege, grantable, owner, table_name, column_nameFROM dba_col_privsWHERE grantee = 'OE'UNIONSELECT 'Sys Priv', privilege, admin_opti<strong>on</strong>, NULL, NULL, NULLFROM dba_sys_privsWHERE grantee = 'OE'ORDER BY privilege, grantable,owner, table name, column nameThe following output is returned <str<strong>on</strong>g>for</str<strong>on</strong>g> the OE user:LVL PRIVILEGE GRANTABLEOWNER TABLE_NAME COLUMN_NAMESys Priv CREATE SNAPSHOT NOSys Priv QUERY REWRITENOSys Priv UNLIMITED TABLESPACENOTable EXECUTE NO SYS DBMS_STATSTable REFERENCES NO HR COUNTRIESTable REFERENCES NO HR EMPLOYEESTable REFERENCES NO HR LOCATIONSTable SELECT NO HR COUNTRIESTable SELECT NO HR DEPARTMENTSTable SELECT NO HR EMPLOYEESTable SELECT NOHR JOBSTable SELECT NOHR JOB_HISTORYTable SELECT NOHR LOCATIONSBased <strong>on</strong> the preceding output, grant statements can be devised as follows:GRANT SELECT ON countries <strong>to</strong> OE;GRANT SELECT ON departments <strong>to</strong> OE;GRANT SELECT ON employees <strong>to</strong> OE;GRANT SELECT ON jobs <strong>to</strong> OE;GRANT SELECT ON job_his<strong>to</strong>ry <strong>to</strong> OE;GRANT SELECT ON locati<strong>on</strong>s <strong>to</strong> OE;<strong>SQL</strong> <strong>Server</strong> does not c<strong>on</strong>tain equivalents <str<strong>on</strong>g>for</str<strong>on</strong>g> CREATE SNAPSHOT, QUERYREWRITE, REFERENCES, and UNLIMITED TABLESPACE privileges.The CREATE SNAPSHOT privilege is related <strong>to</strong> replicati<strong>on</strong>, and the QUERYREWRITE privilege is related<strong>to</strong> data warehousing, and both are bey<strong>on</strong>d the scope


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 151of this guide. The REFERENCES privilege is <str<strong>on</strong>g>for</str<strong>on</strong>g> creating <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straintsacross schemas which are not allowed in <strong>SQL</strong> <strong>Server</strong>. <strong>SQL</strong> <strong>Server</strong> does notimpose s<strong>to</strong>rage quotas <strong>on</strong> schemas; an equivalent <str<strong>on</strong>g>for</str<strong>on</strong>g> REFERENCES is notneeded in <strong>SQL</strong> <strong>Server</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 1538Developing: Databases —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the DataIntroducti<strong>on</strong> and GoalsMigrati<strong>on</strong> of the data represents the final task in the migrati<strong>on</strong> of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong>Microsoft® <strong>SQL</strong> <strong>Server</strong>. Even though <strong>SQL</strong> <strong>Server</strong> offers several <strong>to</strong>ols that make thebulk transfer of data from an external source easier, aspects of the migrati<strong>on</strong> that cannotbe au<strong>to</strong>mated, such as planning the migrati<strong>on</strong> and validating that the data has beenmoved completely and without error, should be prioritized.The data migrati<strong>on</strong> task can be broken up in<strong>to</strong> the following three subtasks:1. Planning. It is important <strong>to</strong> understand the migrati<strong>on</strong> opti<strong>on</strong>s, evaluate thecharacteristics of the source data, and evaluate envir<strong>on</strong>mental and businessc<strong>on</strong>straints.2. Executi<strong>on</strong>. This subtask involves preparing the database and transferring thedata.3. Validati<strong>on</strong>. This subtask accounts <str<strong>on</strong>g>for</str<strong>on</strong>g> all the data and verifies data integrity.Planning the Data Migrati<strong>on</strong>There are two planning prerequisites. Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e making any decisi<strong>on</strong>s, you should first fullyunderstand the various opti<strong>on</strong>s available <str<strong>on</strong>g>for</str<strong>on</strong>g> transferring the data from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database, particularly the advantages and limitati<strong>on</strong>s of eachof the opti<strong>on</strong>s. The sec<strong>on</strong>d prerequisite is <strong>to</strong> document all the fac<strong>to</strong>rs or characteristics ofthe original envir<strong>on</strong>ment that could influence your decisi<strong>on</strong> making from the availableopti<strong>on</strong>s. These prerequisites are discussed in detail under the following headings.Opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> Migrati<strong>on</strong>In an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> scenario, the two avenues <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating data are <strong>to</strong>either push the data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, or <strong>to</strong> pull the data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> in<strong>to</strong><strong>SQL</strong> <strong>Server</strong>.Even though <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> can communicate with heterogeneous databases, the operati<strong>on</strong> is<strong>on</strong>ly at a transacti<strong>on</strong>al level and cannot be taken advantage of <str<strong>on</strong>g>for</str<strong>on</strong>g> bulk data operati<strong>on</strong>s asneeded in a migrati<strong>on</strong> situati<strong>on</strong>. The <strong>on</strong>ly specialized utility <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> provides <str<strong>on</strong>g>for</str<strong>on</strong>g> exportingdata out of the database is the export utility exp. This utility can <strong>on</strong>ly create dumps inbinary <str<strong>on</strong>g>for</str<strong>on</strong>g>mat that cannot be used <str<strong>on</strong>g>for</str<strong>on</strong>g> importing in<strong>to</strong> a n<strong>on</strong>-<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.


154 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data<strong>SQL</strong> <strong>Server</strong> is built <str<strong>on</strong>g>for</str<strong>on</strong>g> bulk copying of data, with specialized features and interfaces <strong>to</strong> alarg e host of data sources. Figure 8.1 shows the various paths that offer bulk copyfuncti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> moving data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.Figure 8.1Paths <str<strong>on</strong>g>for</str<strong>on</strong>g> accessing an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database from <strong>SQL</strong> <strong>Server</strong>Data can be migrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> using <strong>on</strong>e of the following opti<strong>on</strong>s:● Bulk Copy Program (bcp). bcp is a command line utility that uses the ODBC bulkcopy API in <strong>SQL</strong> <strong>Server</strong>. bcp cannot c<strong>on</strong>nect <strong>to</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database and, whenemployed <str<strong>on</strong>g>for</str<strong>on</strong>g> moving data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the data has <strong>to</strong> be an ASCIItext file. Multiple copies of bcp can be run in parallel while working <strong>on</strong> the sametarget table. The number of parallel sessi<strong>on</strong>s is limited by the number of CPUs <strong>on</strong>the server.For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about using the bcp utility with Microsoft <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong> the"bcp Utility" article available athttp://msdn.microsoft.com/library/default.asp? url=/library/enus/coprompt/cp_bcp_61et.asp.● BULK INSERT. BULK INSERT is a T-<strong>SQL</strong> statement. This statement has thesame kind of functi<strong>on</strong>ality as bcp and can be used <strong>to</strong> import <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> data that hasbeen captured in a text file. This operati<strong>on</strong> scales linearly with the number ofCPUs, but it is limited <strong>to</strong> <strong>on</strong>e thread per CPU.For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the complete BULK INSERT T-<strong>SQL</strong> statement and its usage,refer <strong>to</strong> http://msdn.microsoft.com/library/default.asp?url=/library/enus/tsqlref/ts_ba-bz_4fec.asp.● Data Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> Service (DTS). DTS is a powerful set of GUI <strong>to</strong>ols that canbe used <strong>to</strong> extract, trans<str<strong>on</strong>g>for</str<strong>on</strong>g>m, and populate <strong>SQL</strong> <strong>Server</strong> databases from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 155E ven though the functi<strong>on</strong>ality <strong>to</strong> trans<str<strong>on</strong>g>for</str<strong>on</strong>g>m data during the migrati<strong>on</strong> exists, anassumpti<strong>on</strong> made during this discussi<strong>on</strong> is that no trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> of the source data isrequired. The BULK INSERT T-<strong>SQL</strong> statement has been documented in <strong>SQL</strong> <strong>Server</strong>Books Online as the fastest bulk copy method because it executes with the <strong>SQL</strong> <strong>Server</strong>process. In c<strong>on</strong>trast, bcp and DTS are external utilities that are running as their ownprocesses. As a result, they have the overhead of having <strong>to</strong> communicate withS QL <strong>Server</strong> (using IPC) and pass it data from the source. When bcp and DTS are run <strong>on</strong>a client computer, there is network overhead as well.bcp is faster than DTS when importing very large quantities of data in<strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, butit lacks some of the features of DTS. Studies have ranked bcp first in speed, followed byBULK INSERT, and then DTS. Refer <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> Magazine article "Showdown—bc p vs. DTS" available at http://www.winnetmag.com/Articles/Print.cfm?ArticleID =19760.Other fac<strong>to</strong>rs must be c<strong>on</strong>sidered in making a migrati<strong>on</strong> strategy decisi<strong>on</strong>. These fac<strong>to</strong>rsare discussed under the following heading.The Microsoft <strong>SQL</strong> <strong>Server</strong> Migrati<strong>on</strong> Assistant (SSMA) provides the Schema and DataMig ra<strong>to</strong>r <strong>to</strong>ol, which can migrate the schema and also move the data. The data ismigrated using the <strong>SQL</strong> <strong>Server</strong> Linked <strong>Server</strong> feature <strong>to</strong> c<strong>on</strong>nect directly <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>through the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Gateway. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the Schema and Data Migra<strong>to</strong>r and<strong>to</strong> download the <strong>to</strong>ol refer <strong>to</strong> http://www.microsoft.com/sq l/migrati<strong>on</strong>. The beta versi<strong>on</strong> ofthis <strong>to</strong>ol is available as of the date of publishing this soluti<strong>on</strong>. Versi<strong>on</strong> 1.0 of the <strong>to</strong>ol isslated <strong>to</strong> be available in June 2005.Fac<strong>to</strong>rs in Migrati<strong>on</strong>databases. DTS wizards make the entire process of defining and per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming theimport very easy. DTS provides access <strong>to</strong> the BULK INSERT statement in the DTSBulk Insert task. In additi<strong>on</strong> <strong>to</strong> working with text files, DTS can use OLE DB andODBC providers <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database. The direct c<strong>on</strong>nectivity <strong>to</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> provides the capability <strong>to</strong> work with binary large objects (BLOBs).For an overview of DTS, refer <strong>to</strong>http://msdn.microsoft.com/<strong>SQL</strong>/sqlwarehouse/DTS/default.aspx?pull=/library/en-us/dnsql2k/html/dts_overview.asp.Given the various opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the choice isinfluenced by several business and envir<strong>on</strong>ment fac<strong>to</strong>rs. Some of the important fac<strong>to</strong>rs(the more critical <strong>on</strong>es stated first) are:● Volume of data. The amount of data that has <strong>to</strong> be migrated is the number <strong>on</strong>efac<strong>to</strong>r. High volumes of data require more s<strong>to</strong>rage, more processing power, largernetwork bandwidth, larger migrati<strong>on</strong> window, and increased risk of failure.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> how <strong>to</strong> optimize large data imports in <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/optimsql/odp_tun_1a_5gyt.asp.● Migrati<strong>on</strong> window. The time window available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrati<strong>on</strong> may necessitatemultiple parallel sessi<strong>on</strong>s, more resources, and staging of data.● Type of data. The existence of BLOBs can be handled <strong>on</strong>ly by DTS.● <strong>Server</strong> processing capacity. Running bcp <strong>on</strong> the same server as the databasereduces network overhead of bcp talking <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, but it c<strong>on</strong>sumes CPU <strong>on</strong>the server.● S<strong>to</strong>rage availability. The amount of s<strong>to</strong>rage available in both the source andtarget envir<strong>on</strong>ment influences the choice of migrati<strong>on</strong> method and strategy. Forexample, moving the text files <strong>on</strong> <strong>to</strong> the target server reduces network overhead.


156 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data●●●●The c<strong>on</strong>figurati<strong>on</strong> of s<strong>to</strong>rage also affects the speed of migrati<strong>on</strong>, such as puttingthe source text file and the database files <strong>on</strong> separate disks or devices.Data source. The capability <strong>to</strong> create flat files in the source envir<strong>on</strong>ment affectsthe choice of migrati<strong>on</strong> method. A fixed-field <str<strong>on</strong>g>for</str<strong>on</strong>g>mat source file takes a lot mores<strong>to</strong>rage and is c<strong>on</strong>siderably slower. Delimited <str<strong>on</strong>g>for</str<strong>on</strong>g>mat is recommended.Type of database. Batch, OLTP, or DSS database type defines the type ofschema objects and their characteristics.Recovery Model. Database recovery models should be set <strong>to</strong> simple or bulk-Use proven methods. Only use methods and opti<strong>on</strong>s that have proven <strong>to</strong> work bylogged <strong>to</strong> minimize logging of BULK INSERT. The capability <strong>to</strong> do so can beaffected if there are databases being shared by other applicati<strong>on</strong>s that are in useduring the migrati<strong>on</strong>.the industry and <str<strong>on</strong>g>for</str<strong>on</strong>g> the envir<strong>on</strong>ment. For example, OLE DB has been proven <strong>to</strong> befaster than ODBC while providing all of the same features.Migrati<strong>on</strong> StrategyThe following are some of the fac<strong>to</strong>rs that can c<strong>on</strong>tribute <strong>to</strong> the creati<strong>on</strong> of a robustmigrati<strong>on</strong> strategy:● Minimize logging. The acti<strong>on</strong>s that should be taken <strong>to</strong> minimize logging are:● Set the database recovery model <strong>to</strong> bulk-logged or simple.● Use TABLOCK hint during bulk loading.● The target table should either be empty or no indexes should be defined <strong>on</strong> it.● Disable or drop all triggers <strong>on</strong> the target table.● Drop replicati<strong>on</strong> <strong>on</strong> the target table.●●●●●●●Reduce operati<strong>on</strong>s overhead. You should drop indexes, c<strong>on</strong>straints, defaults,and identity operati<strong>on</strong>s. When a clustered index is planned <str<strong>on</strong>g>for</str<strong>on</strong>g> a table, order thedata while creating the output file from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The BULK INSERT statementaccepts the ORDER clause and the bcp utility accepts the ORDER hint <strong>to</strong> specifythe sort of the data files. Avoid c<strong>on</strong>current access by other users <strong>to</strong> the tablesbeing loaded. The TABLOCK hint can be used while per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming BULK INSERT orbcp.Improve parallelism. With a large amount of data (which is the assumpti<strong>on</strong> madethroughout this secti<strong>on</strong>), the best per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance can <strong>on</strong>ly be achieved by per<str<strong>on</strong>g>for</str<strong>on</strong>g>mingloads in parallel. The parallelism can be inter-table or intra-table.Avoid side effects. Turn off triggers, bypass identity, bypass default columnsetting, and drop replicati<strong>on</strong>.Reduce complexity. When the source database has a large number of tables,break it down in<strong>to</strong> logical subsets and stage data, if necessary. Importing static andhis<strong>to</strong>rical data can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in advance.Reduce risk. Break down larger source data text files using either an edi<strong>to</strong>r or byspecifying ranges in the <strong>SQL</strong> queries that are used <str<strong>on</strong>g>for</str<strong>on</strong>g> exporting the data in<strong>to</strong> spoolfiles. Any failures that occur when dealing with large files waste time andresources. In a migrati<strong>on</strong> c<strong>on</strong>taining very volatile data, the migrati<strong>on</strong> should becompleted in a single stage instead of multiple stages.Commit more resources. Additi<strong>on</strong>al CPU, memory, and s<strong>to</strong>rage should beacquired <str<strong>on</strong>g>for</str<strong>on</strong>g> the migrati<strong>on</strong>.Auditing. Include audit steps during the process. This enables trapping of errorsas they occurduring the transfer of data.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 157Table 8.1 details the suitable method of data porting <str<strong>on</strong>g>for</str<strong>on</strong>g> different migrati<strong>on</strong> envir<strong>on</strong>ments.Table 8.1: Data Migrati<strong>on</strong> Opti<strong>on</strong>sScenarioData migrati<strong>on</strong> envir<strong>on</strong>ments that have high per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancereq uirements and have huge volumes of data <strong>to</strong> betransferredMethods of data migrati<strong>on</strong> that use a small amount of scripts bcpApplicati<strong>on</strong>s that need <strong>to</strong> use scripts <strong>on</strong> the data transferprocessAp plicati<strong>on</strong>s that require high-powered trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> ofmoderate volumes of dataTab les c<strong>on</strong>tain large objects (LOB) such as RAW, LONG,BLOB, and CLOBRecommended methodbcp or BULK INSERTBULK INSERTHere are some additi<strong>on</strong>al c<strong>on</strong>siderati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> planning the migrati<strong>on</strong>:● The final strategy should be based <strong>on</strong> the amount of time available <str<strong>on</strong>g>for</str<strong>on</strong>g> the actualdeployment and cu<strong>to</strong>ver.● The per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of the load operati<strong>on</strong> should be dependent <strong>on</strong> the chosenstrategy.● Instead of sticking <strong>to</strong> a single method, a combinati<strong>on</strong> of methods can be employedbased <strong>on</strong> the strengths and weaknesses of the individual methods. For example,DTS need not be used as the migrati<strong>on</strong> method just because there are LOBcolumns.● The tables in the migrati<strong>on</strong> can be broken up and a combinati<strong>on</strong> of methods couldbe used, taking advantage of the strengths of each.● Parallel operati<strong>on</strong> should be applied <strong>on</strong> large tables.● The per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of bcp versus BULK INSERT has been found <strong>to</strong> vary. Test boththese approaches in your scenario be<str<strong>on</strong>g>for</str<strong>on</strong>g>e making a decisi<strong>on</strong>.● Test data files should be created and the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of the various methodsmeasured in the target envir<strong>on</strong>ment.● A pro<strong>to</strong>type of the final strategy should be created and the process should bepracticed and perfected be<str<strong>on</strong>g>for</str<strong>on</strong>g>e deployment.DTSDTSExecuting the Data Migrati<strong>on</strong>This secti<strong>on</strong> details the steps <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating data. The secti<strong>on</strong> has beenbroken in<strong>to</strong> three tasks:1. Pre-implementati<strong>on</strong>2. Implementati<strong>on</strong>3. Post-implementati<strong>on</strong>Each of these tasks is discussed in detail under the following headings.


158 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the DataPre-Implementati<strong>on</strong> TasksThe following tasks have <strong>to</strong> be completed be<str<strong>on</strong>g>for</str<strong>on</strong>g>e per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the migrati<strong>on</strong>:1. Back up the database.Delete any test data from the target database and create a full backup of the emptydatabase. Res<strong>to</strong>ring the backup will be faster than the work involved in rolling backa failed or incomplete migrati<strong>on</strong>.2.Export <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> data in<strong>to</strong> text files.Data from each table that has <strong>to</strong> be migrated is exported in<strong>to</strong> comma-delimitedASCII text files.Note The string data should be opti<strong>on</strong>ally enclosed in double quotati<strong>on</strong> marks (")in case there are commas in the column data. The date fields can be exported inthe desired <str<strong>on</strong>g>for</str<strong>on</strong>g>mat using the TO_CHAR functi<strong>on</strong>.Sample:In <strong>SQL</strong>*Plus, c<strong>on</strong>nect <strong>to</strong> the schema and execute the following command:desc countriesThe output is:Name Null? Type----------------------------------------- -------- -----------------COUNTRY_IDCOUNTRY_NAMEREGION_IDNOT NULL CHAR(2)VARCHAR2(40)NUMBERCreate a .sql file (example countries.sql) with the following c<strong>on</strong>tent:set pages 0set lines 10000set trimspool <strong>on</strong>set feedback offspool /data/dump/countries.csvselect country_id||','||country_name||','||regi<strong>on</strong>_idfrom countries;spool offExecuting this file using <strong>SQL</strong>*Plus produces the following text file that can beimported in<strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.Note If these commands are typed at the command prompt inside the <strong>SQL</strong>*Plusutility in Microsoft Windows®, the output file will c<strong>on</strong>tain extraneous promptcommands at the beginning and end of the file. This does not occur if thecommands are executed from a file.AR,Argentina,2AU,Australia,3BE,Belgium,1BR,Brazil,2CA,Canada,2CH,Switzerland,1CN,China,3DE,Germany,1


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 159DK,Denmark,1EG,Egypt,4FR,France,1HK,H<strong>on</strong>gK<strong>on</strong>g,3IL,Israel,4IN,India,3IT,Italy,1JP,Japan,3KW,Kuwait,4MX,Mexico,2NG,Nigeria,4NL,<strong>Net</strong>herlands,1SG,Singapore,3UK,United Kingdom,1US,United States of America,2ZM,Zambia,4ZW,Zimbabwe,4Note Using <strong>SQL</strong>*Plus and the spool command is the best way <strong>to</strong> create commaseparated(CSV) exports of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> table data. Other soluti<strong>on</strong>s available based <strong>on</strong>the functi<strong>on</strong>ality currently available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are DBMS_OUTPUT, UTL_FILE, andPro*C. For details <strong>on</strong> the various methods, refer <strong>to</strong>http://ask<strong>to</strong>m.oracle.com/~tkyte/flat/index.htmlHowever, these opti<strong>on</strong>s should be employed <strong>on</strong>ly if the data is being manipulatedduring the output process because there are per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance overheads in their use.3. Set the recovery model of the <strong>SQL</strong> <strong>Server</strong> database.Change the recovery model of the target <strong>SQL</strong> <strong>Server</strong> database <strong>to</strong> bulk-logged orsimple. Bulk-logged mode is preferred.The following command sets the recovery model of a database <strong>to</strong> bulk-logged:ALTER DATABASE database_nameSET RECOVERY BULK_LOGGEDwhere database_name is the name of the database whose recovery model has <strong>to</strong> beset.4. Disable all c<strong>on</strong>straints.Identify and disable all c<strong>on</strong>straints, including CHECK, PRIMARY KEY, FOREIGNKEY, and UNIQUE. Create scripts <strong>to</strong> res<strong>to</strong>re them.In <strong>SQL</strong> <strong>Server</strong>, <strong>on</strong>ly FOREIGN KEY and CHECK c<strong>on</strong>straints can be disabled.The following command can be used <strong>to</strong> disable FOREIGN KEY and CHECKc<strong>on</strong>straints of a <strong>SQL</strong> <strong>Server</strong> table:ALTER TABLE table_name NOCHECK CONSTRAINT ALLwhere table_name is the name of the table whose c<strong>on</strong>straints have <strong>to</strong> be disabled.PRIMARY KEY and UNIQUE c<strong>on</strong>straints have <strong>to</strong> be dropped.The following command can be used <strong>to</strong> drop PRIMARY and UNIQUE by specifyingtheir name:ALTER TABLE table_name DROP CONSTRAINT c<strong>on</strong>straint_namewhere c<strong>on</strong>straint_name is the name of the c<strong>on</strong>straint and table_name is the name ofthe table in which the c<strong>on</strong>straint exists.


160 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the DataNote By default, c<strong>on</strong>straints are not checked when using bcp.5. Disable all triggers.Disable triggers <strong>on</strong> all tables in<strong>to</strong> which data will be loaded.The following command can be used <strong>to</strong> disable all triggers <strong>on</strong> a table.ALTER TABLE table_name DISABLE TRIGGER ALLwhere table_name is the name of the table <strong>on</strong> which the triggers have <strong>to</strong> bedisabled.6. Drop all indexes.Drop all remaining indexes using the following command after saving the script <strong>to</strong>recreate them.DROP INDEXtable_name.index_namewhere index_name is the name of the index <strong>to</strong> be dropped and table_name is thetable <strong>on</strong> which the index exists.7. Handle IDENTITY column inserts.Let explicit values be copied in<strong>to</strong> columns of a table with the Identity property.SET IDENTITY_INSERT table_name ONThis setting can be used <strong>on</strong>ly <strong>on</strong> a single table at a time. So ensure that this is setbe<str<strong>on</strong>g>for</str<strong>on</strong>g>e importing a table, or use the functi<strong>on</strong>ality in the method being used. In bcp,the same thing can be achieved using the -E switch. In BULK INSERT, use theKEEPIDENTITY argument.BULK INSERT 'table_name' FROM 'data file' WITH KEEPIDENTITY8. Back up the database.Create a full backup after the data migrati<strong>on</strong> be<str<strong>on</strong>g>for</str<strong>on</strong>g>e per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming any validati<strong>on</strong> ortesting.Implementati<strong>on</strong> TasksThe implementati<strong>on</strong> is the actual transfer of data from the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong> thetarget <strong>SQL</strong> <strong>Server</strong> database. The implementati<strong>on</strong> can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in <strong>on</strong>e step or in twosteps. In the single step, implementati<strong>on</strong> data is streamed directly from the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. In the two step process, data is extracted from the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database in<strong>to</strong> files and then loaded in<strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database.S QL <strong>Server</strong> provides the following three <strong>to</strong> ols <str<strong>on</strong>g>for</str<strong>on</strong>g> loading data in<strong>to</strong> a database:● The bulk copy program (bcp)● The BULK INSERT statement● Data Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> Services (DTS)The use of these three <strong>to</strong>ols in transferring data in<strong>to</strong> <strong>SQL</strong> <strong>Server</strong> is discussed under thefollowing headings.Using bcpThe bcp utility can be accessed from the command prompt. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> use isprovided here:bcp database_name.owner.table_name in data_file –t field_termina<strong>to</strong>r –Sserver_name\instance_name–U username –P password –c –t ,


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 161where database_name.owner.table_name is the fully qualified name of the table in<strong>to</strong> whichthe data is <strong>to</strong> be loaded, data_file is the name of the text file c<strong>on</strong>taining the data,field_termina<strong>to</strong>r is the character that is used <strong>to</strong> delimit columns in a row,server_name\instance_name is the <strong>SQL</strong> <strong>Server</strong> instance, username is the login name, andpassword is the password <str<strong>on</strong>g>for</str<strong>on</strong>g> the user login.-c specifies that the data in the file is in the character data type-t specifies the field termina<strong>to</strong>rFigure 8.2 shows the results of executing this command at the Windows commandprompt.Figure 8.2Importing data from a text file using bcpTo make the bcp process repeatable, a <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file should be created. The <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file canbe created interactively by executing the b cp command, as shown in Figure 8.3.Figure 8.3Creating a <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file <str<strong>on</strong>g>for</str<strong>on</strong>g> use with bcp imports


162 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the DataThe <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file looks like this:8.031 <strong>SQL</strong>CHAR 0 2 "," 1 COUNTRY_ID <strong>SQL</strong>_Latin1_General_CP1_CI_AS2 SQ LCHAR 0 40 "," 2 COUNTRY_NAME <strong>SQL</strong>_Latin1_General_CP1_CI_AS3 <strong>SQL</strong>NUMERIC 0 19 "\r\n" 3 REGION_ID ""Refer <strong>to</strong> the <strong>to</strong>pic "Using Format Files" in <strong>SQL</strong> <strong>Server</strong> Books Online <str<strong>on</strong>g>for</str<strong>on</strong>g> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>about <str<strong>on</strong>g>for</str<strong>on</strong>g>mat files.Note The <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file will have <strong>to</strong> be modified <strong>to</strong> handle text files that c<strong>on</strong>tain columndata values and which are enclosed by quotati<strong>on</strong> marks (").The <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> future imports in<strong>to</strong> the same table by using the -f switch.This is illustrated in Figure 8.4. In the example, the <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file is assumed <strong>to</strong> have beencopied <strong>to</strong> C:.Figure 8.4Importing data from a text file using bcp <str<strong>on</strong>g>for</str<strong>on</strong>g>mat fileTable 8.2 c<strong>on</strong>tains the additi<strong>on</strong>al arguments that are relevant while importing largevolumes of data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.Table 8.2: Additi<strong>on</strong>al Arguments of the bcp UtilityArgument (or opti<strong>on</strong>)Descripti<strong>on</strong>-k bypasses DEFAULT definiti<strong>on</strong>-h "hints" bulk copy hints-E allows Identity insert-a network packets size 512 <strong>to</strong> 65536 (default4096)-e error_file logs errors during the import-b batch_size uses default, which is all rows in the fileNote Hidden characters in text files can cause problems such as the "unexpected nullfound" error. Care has <strong>to</strong> be taken when opening and manipulating text files c<strong>on</strong>tainingdata.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 163Using BULK INSERTThe BULK INSERT T-<strong>SQL</strong> statement provides the same functi<strong>on</strong>ality as the bcp utility.The major difference is that this functi<strong>on</strong>ality is from within a database sessi<strong>on</strong>.The following statement achieves the same work as was dem<strong>on</strong>strated with bcp:BULK INSERT hrdata.hr.countries FROM 'c:\countries.csv'WITH (DATAFILETYPE = 'char',FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')Note Only members of the sysadmin role can use BULK INSERT.Table 8.3 c<strong>on</strong>tains additi<strong>on</strong>al arguments that need <strong>to</strong> be used while importing largeamounts of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> data.Table 8.3: Additi<strong>on</strong>al Arguments Available with the BULK INSERT CommandArgument (or opti<strong>on</strong>)Descripti<strong>on</strong>-k bypasses DEFAULT definiti<strong>on</strong>TABLOCKlocksKEEPIDENTITYallows values <strong>to</strong> be specified <str<strong>on</strong>g>for</str<strong>on</strong>g> identitycolumnFIRE_TRIGGERS trigger executi<strong>on</strong> is not suppressedCHECK_CONSTRAINTSc<strong>on</strong>straints <strong>on</strong> table have <strong>to</strong> be checkedBATCHSIZEuse default, which is all rows in the fileNote For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the bulk copy operati<strong>on</strong>s and <strong>on</strong> improving itsper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, refer <strong>to</strong> "Optimizing Bulk Copy Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance" athttp://msdn.microsoft.com/library/en-us/optimsql/od p_tun_1a_5gyt.asp?frame=true,and "Bulk Copy Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance C<strong>on</strong>siderati<strong>on</strong>s" at http://msdn.microsoft.com/library/en-us/adminsql/ad_impt_bcp_5zqd.asp.For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> different switches available with Bulk Insert, refer <strong>to</strong>http ://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ba-bz_4fec.asp.Using DTSThis secti<strong>on</strong> is used <strong>to</strong> dem<strong>on</strong>strate how DTS wizards can be used <strong>to</strong> import data in<strong>to</strong><strong>SQL</strong> <strong>Server</strong> tables from text files and directly from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database. The DTS Import/Export Wizard can be launched from Enterprise Managerusing the following steps or using the DTS Import Wizard:1. Expand <strong>Server</strong>.2. Right-click Databases, click All Tasks, and then click Import Data.3. Click the Next butt<strong>on</strong> <strong>on</strong> the wizard's Welcome screen.4. The next window presented is <str<strong>on</strong>g>for</str<strong>on</strong>g> choosing the data source. In the DataSource drop-down list choose Text File. Pick the file c<strong>on</strong>taining <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tabledata in the File name text box.


164 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data5. The file <str<strong>on</strong>g>for</str<strong>on</strong>g>mat characteristics are chosen in the next window. The file typeshould be ANSI, and the row delimiter should be {CR}{LF}. If column datavalues are quoted, it can be specified in the Text qualifier field. The delimitercharacter, which is a comma (,), is specified in the next screen.6. The Microsoft OLE DB Provider <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> should be chosen as thedestinati<strong>on</strong> and the server and login in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> provided <str<strong>on</strong>g>for</str<strong>on</strong>g> the target<strong>SQL</strong> <strong>Server</strong> instance.DTS offers the opti<strong>on</strong> of executing the import, saving it <strong>to</strong> a DTS package andscheduling. For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> how <strong>to</strong> schedule DTS packages, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dtssql/dts_pkgmng_4hm6.asp.DTS from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DatabaseThe steps in creating a DTS package <strong>to</strong> c<strong>on</strong>nect and import data directly from the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database is very similar <strong>to</strong> the process described in the previous secti<strong>on</strong>. Instead ofpointing the source <strong>to</strong> a file, an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database is specified through an OLE DB orODBC provider <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The DTS Import/Export Wizard can be launched from Enterprise Managerusing the following steps or using the DTS Import Wizard:1. Expand <strong>Server</strong>.2. Right-click Databases, click All Tasks, and then click Import Data.3. Click the Next butt<strong>on</strong> <strong>on</strong> the wizard's Welcome screen.4. The next window presented is <str<strong>on</strong>g>for</str<strong>on</strong>g> choosing the data source. In the Data Sourcedrop-down list, choose the Microsoft ODBC Driver <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Enter the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database alias and login in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.5. The Microsoft OLE DB Provider <str<strong>on</strong>g>for</str<strong>on</strong>g> SL <strong>Server</strong> should be chosen as the destinati<strong>on</strong>and the server and login in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> provided <str<strong>on</strong>g>for</str<strong>on</strong>g> the target <strong>SQL</strong> <strong>Server</strong> instance.6. The next screen offers the opti<strong>on</strong> of copying data from a table (or view) or using aquery.7. If the table or view opti<strong>on</strong> is chosen, the next screen provides a list of tables andviews available <str<strong>on</strong>g>for</str<strong>on</strong>g> import. The destinati<strong>on</strong> table name and trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> has <strong>to</strong> be provided al<strong>on</strong>g with the source table/view.8. If query opti<strong>on</strong> is chosen, the next screen provides a window <str<strong>on</strong>g>for</str<strong>on</strong>g> entering the querystatement. The destinati<strong>on</strong> table and trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> can be entered in the nextscreen.9. The executi<strong>on</strong> of the import can be d<strong>on</strong>e immediately or scheduled <str<strong>on</strong>g>for</str<strong>on</strong>g> a later time.Note DTS has the capability of reading the table descripti<strong>on</strong> from the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databaseand creating tables in <strong>SQL</strong> <strong>Server</strong>. The wizard has been found <strong>to</strong> be faulty in its choiceof equivalent data types <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> tables.Data can be migrated directly out of the database instead of through an intermediary fileif the interc<strong>on</strong>nect between the servers hosting the two databases is very fast. Also, noadditi<strong>on</strong>al s<strong>to</strong>rage is required <str<strong>on</strong>g>for</str<strong>on</strong>g> the data files <strong>on</strong> the two servers. Use of files can reducethe deployment time if the data export can be d<strong>on</strong>e in advance and staged <str<strong>on</strong>g>for</str<strong>on</strong>g> import.For a case study <strong>on</strong> incrementally loading tables using the <strong>SQL</strong> <strong>Server</strong> bulk load opti<strong>on</strong>s,refer <strong>to</strong>http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/incbulkload.mspx.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 165Post-Implementati<strong>on</strong> TasksThe following tasks have <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> ensure the success of the data transfer. Thetasks per<str<strong>on</strong>g>for</str<strong>on</strong>g>med here undo the changes that were made <strong>to</strong> the schema <str<strong>on</strong>g>for</str<strong>on</strong>g> affecting thedata transfer, such as disabling of c<strong>on</strong>straints and triggers. Chapter 9, "Developing:Databases — Unit Testing the Migrati<strong>on</strong>" has a more detailed discussi<strong>on</strong> of per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming thefirst two tasks as a part of testing the migrated database.1. Validate the data migrati<strong>on</strong>.Th e validati<strong>on</strong> tasks are discussed in detail in the "Validating the Data Migrati<strong>on</strong>"secti<strong>on</strong> later in this chapter.2. Re-enable the c<strong>on</strong>straints.Enable all c<strong>on</strong>straints, including CHECK, PRIMARY KEY, FOREIGN KEY, andUNIQUE. Use the scripts that were created while disabling the c<strong>on</strong>straints.FOREIGN KEY and CHECK c<strong>on</strong>straints can be enabled using the following syntax:ALTER TABLE table_name CHECK CONSTRAINT ALLwhere table_name is the table <strong>on</strong> which the CHECK c<strong>on</strong>straints have <strong>to</strong> be enabled.PRIMARY KEY and UNIQUE c<strong>on</strong>straints will have <strong>to</strong> be recreated using theoriginal DDL. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> allows multiple rows where all columns (nullable) of aUNIQUE c<strong>on</strong>straint have NULL values. <strong>SQL</strong> <strong>Server</strong> treats NULL as duplicates(instead of an unknown value) <str<strong>on</strong>g>for</str<strong>on</strong>g> the purpose of uniqueness. Hence creating aUNIQUE c<strong>on</strong>straint would return an error if such a c<strong>on</strong>diti<strong>on</strong> exists. Because itwould be difficult <strong>to</strong> create values, the best way <strong>to</strong> maintain the status quo wouldbe <strong>to</strong> replace the UNIQUE c<strong>on</strong>straint with a trigger that accomplishes the samething.3. Recreate the indexes.The c<strong>on</strong>straint indexes can be recreated using the saved scripts. Multiple indexes<strong>on</strong> a single table can be created in parallel using different client sessi<strong>on</strong>s.4. Enable the triggers.Identify and enable all triggers by using the following syntax:ALTER TABLE table_name ENABLE TRIGGER ALLwhere table_name is the table <strong>on</strong> which the triggers are <strong>to</strong> be enabled.5. Set the recovery model.Res<strong>to</strong>re the recovery model of the <strong>SQL</strong> <strong>Server</strong> database <strong>to</strong> the original setting(normally full) by using the following syntax:ALTER DATABASE database_nameSET RECOVERY FULL6. Capture data statistics.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the steps necessary <strong>to</strong> capture data statistics required by the optimizer.7. Back up the database.Create a full backup of the entire server, including the user databases. This is thefirst valid backup of the migrated database.Validating the Data Migrati<strong>on</strong>The following major tasks have <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> validate the migrated data:1. Verify the data transfer.The logs or audit files <str<strong>on</strong>g>for</str<strong>on</strong>g> the data transfers should be checked <str<strong>on</strong>g>for</str<strong>on</strong>g> errors orfailures. After this processis complete, row counts of every table in the destinati<strong>on</strong><strong>SQL</strong> <strong>Server</strong> database should be matched <strong>to</strong> the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database. If any


166 Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> the Data2.discrepancy is found in the counts, troubleshooting should include identifying themissing records and viewing the logs and audit files <str<strong>on</strong>g>for</str<strong>on</strong>g> error messages that canprovide reas<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> the failure. The data transfer process should take in<strong>to</strong>c<strong>on</strong>siderati<strong>on</strong> any changes in the logical model between the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database and <strong>SQL</strong> <strong>Server</strong>. A more stringent check is difficult <str<strong>on</strong>g>for</str<strong>on</strong>g> large databases.More validati<strong>on</strong> of the data transfer occurs in the next step as part of the dataintegrity checks.Validate the data integrity.Integrity is au<strong>to</strong>matically checked when creating or enabling c<strong>on</strong>straints. The WITHCHECK clause has <strong>to</strong> be used when adding c<strong>on</strong>straints. Data integrity checking isthreatened when migrating databases which lack proper primary key c<strong>on</strong>straintsand <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key c<strong>on</strong>straints. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the functi<strong>on</strong>ality available withcheck c<strong>on</strong>straints, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_aa-az_3ied.asp.In many cases, there are no strict equivalents of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> datatypes in <strong>SQL</strong> <strong>Server</strong>.Hence the integrity of such data has <strong>to</strong> be tested <strong>to</strong> ensure that there is norounding or truncati<strong>on</strong>, and that the exact value is s<strong>to</strong>red.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 1679Developing: Databases — UnitTesting the Migrati<strong>on</strong>Introducti<strong>on</strong> and GoalsThe final task <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in the Developing Phase is <strong>to</strong> test the database. Becauseeverything except the core database design has been trans<str<strong>on</strong>g>for</str<strong>on</strong>g>med, it is very important <strong>to</strong>thoroughly test every aspect of the Microsoft® <strong>SQL</strong> <strong>Server</strong> database be<str<strong>on</strong>g>for</str<strong>on</strong>g>e release <strong>to</strong>the producti<strong>on</strong> envir<strong>on</strong>ment. Testing should cover the hardware, the <strong>SQL</strong> <strong>Server</strong>installati<strong>on</strong>, security, database objects, data, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.The descripti<strong>on</strong>s of the testing process <str<strong>on</strong>g>for</str<strong>on</strong>g> databases and applicati<strong>on</strong>s is divided in<strong>to</strong>smaller pieces and spread out between the Developing and Stabilizing Phases. Testing<str<strong>on</strong>g>for</str<strong>on</strong>g> integrity and functi<strong>on</strong>ality of the migrated database is covered in this chapter.Additi<strong>on</strong>al applicati<strong>on</strong>-based testing of the database is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med as part of testing theapplicati<strong>on</strong>. Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance can be verified <strong>on</strong>ly through the benchmarking and piloting thatis per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in the Stabilizing Phase.Objectives of TestingThe following areas should be tested:● Physical architecture of the database. Have the data files, transacti<strong>on</strong> log,tablespaces, and other items that comprise the database been created correctly?Has the <strong>SQL</strong> <strong>Server</strong> instance been properly c<strong>on</strong>figured?● Security. Have the logins and users been correctly created? Have the appropriatepermissi<strong>on</strong>s been assigned? Is the database physically secure?● Logical architecture of the database. Have the tables, views, s<strong>to</strong>red procedures,triggers, and other database objects been created successfully?● Data. Have the c<strong>on</strong>tents of the tables been transferred correctly? Do tables c<strong>on</strong>tainthe correct numbers of rows? Is the data valid?● Functi<strong>on</strong>ality. Do the s<strong>to</strong>red procedures, triggers, views, and other itemscomprising Transact-<strong>SQL</strong> code operate in the same manner as the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>objects?● Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. Does resp<strong>on</strong>se time and throughput meet requirements and matchuser expectati<strong>on</strong>s?


168 Developing: Databases — Unit Testing the Migrati<strong>on</strong>TheTesting ProcessThe database is tested in three different stages of the migrati<strong>on</strong>:●●●Developing Phase — DatabaseIn this stage, the database is unit tested <str<strong>on</strong>g>for</str<strong>on</strong>g> all the comp<strong>on</strong>ents that have beenmigrated, which includes the database architecture, the schema, the users, andthe data. This type of testing is covered in the rest of this secti<strong>on</strong>.Developing Phase — Applicati<strong>on</strong>In this phase, the database is tested with respect <strong>to</strong> the applicati<strong>on</strong> support. Thisprimarily tests that all the objects required by the applicati<strong>on</strong> are present andper<str<strong>on</strong>g>for</str<strong>on</strong>g>m as expected. The applicati<strong>on</strong>-related testing is covered in the applicati<strong>on</strong>development Chapters 11 through 17.Stabilizing PhaseIn the Stabilizing Phase, more thorough tests are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <str<strong>on</strong>g>for</str<strong>on</strong>g> integrati<strong>on</strong>,per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, stress, and scalability. This phase is described in Chapter 18.This secti<strong>on</strong> describes the testing process that is followed during the Developing Phase<str<strong>on</strong>g>for</str<strong>on</strong>g> the database. The testing is interspersed with the steps in the migrati<strong>on</strong> of thedatabase. The procedure <str<strong>on</strong>g>for</str<strong>on</strong>g> migrati<strong>on</strong> and testing is illustrated in the flowchart in Figure9.1.Figure 9.1Data migrati<strong>on</strong> test procedure


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 169The tasks <strong>on</strong> the left half, namely, migrating the architecture, migrating the schema,migrating the users, and migrating the data, are part of the database migrati<strong>on</strong> and arecovered in chapters 5 through 8. The success of these tasks is validated as databaseintegrity testing and data validati<strong>on</strong>. Details regarding these two types of testing appearunder the following headings.Test Database IntegrityAfter the database schema has been created in the target database, an integrity testshould be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med be<str<strong>on</strong>g>for</str<strong>on</strong>g>e starting the data migrati<strong>on</strong>. This should cover the physicaldatabase structure, the schema, and the schema objects.There is no <strong>to</strong>ol available <str<strong>on</strong>g>for</str<strong>on</strong>g> comparing the integrity and validity of the <strong>SQL</strong> <strong>Server</strong>objects as compared <strong>to</strong> the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> objects. Unit testing has <strong>to</strong> rely <strong>on</strong> theexperience and expertise of the database designers or administra<strong>to</strong>rs who are per<str<strong>on</strong>g>for</str<strong>on</strong>g>mingthe mapping. However, a true unit test would be <strong>to</strong> load data from the source objects andrun <strong>SQL</strong> with identical functi<strong>on</strong>ality in the two envir<strong>on</strong>ments. Any discrepancies should be<strong>on</strong>ly as a known (explainable) c<strong>on</strong>sequence of the migrati<strong>on</strong>.The following tasks are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> ensure database integrity:● Unit test the schema objects. The type and number of each object in the original<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database has <strong>to</strong> be compared <strong>to</strong> that in the <strong>SQL</strong> <strong>Server</strong> database. Queriescan be written in the two databases (<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>) <strong>to</strong> produce a count ofeach type of object. However, the counts in the two soluti<strong>on</strong>s may not matchbecause there is no <strong>on</strong>e-<strong>to</strong>-<strong>on</strong>e equivalency <str<strong>on</strong>g>for</str<strong>on</strong>g> every object.● Verify that data elements have been created as per the mapping. The propertrans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> of the data type and domain values of the columns — as well as anyc<strong>on</strong>straints, such as NULL and CHECK c<strong>on</strong>straint <strong>on</strong> the columns — have <strong>to</strong> beverified be<str<strong>on</strong>g>for</str<strong>on</strong>g>e per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the data migrati<strong>on</strong>. A representative set of data from theoriginal <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> this purpose.● Verify that all c<strong>on</strong>straints are in place. For each table having a parent-childrelati<strong>on</strong>ship, referential integrity is checked.● Functi<strong>on</strong>s, triggers, and s<strong>to</strong>red procedures have been accuratelytrans<str<strong>on</strong>g>for</str<strong>on</strong>g>med. S<strong>to</strong>red procedures, triggers, and views can be tested by using anidentical set of representative data in the source and migrated databases.Executi<strong>on</strong> of test cases against these objects should produce identical results.● Verify the data access. Additi<strong>on</strong>al indexes may be present in <strong>SQL</strong> <strong>Server</strong> <strong>to</strong> offsetfeatures such as fast full index scans in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> that can use the n<strong>on</strong>-leadingcolumns of indexes. It should be verified that all objects in the original <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database have been successfully migrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. A complete set of T-<strong>SQL</strong> statements should be obtained from the applicati<strong>on</strong> development team andeach of them verified <str<strong>on</strong>g>for</str<strong>on</strong>g> optimal data access paths.If the applicati<strong>on</strong> has been migrated, running a few frequently used business transacti<strong>on</strong>swould ensure whether the schema has been successfully migrated. After the correctnessof the database structure and its objects is guaranteed, data migrati<strong>on</strong> can proceed.Test SecurityThe security mechanisms available with <strong>SQL</strong> <strong>Server</strong> and Windows are significantlydifferent from those used by <strong>UNIX</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The difference in the authenticati<strong>on</strong>mechanisms is especially important because it affects the user login process. Forexample, the requirements of password management functi<strong>on</strong>ality, such as aging,locking, and password strength will require that Windows authenticati<strong>on</strong> be used in placeof database authenticati<strong>on</strong>. The system privileges available in the two databases differ


170 Developing: Databases — Unit Testing the Migrati<strong>on</strong>significantly. You must verify that <strong>on</strong>ly authenticated, authorized users have access <strong>to</strong> theobjects in the database. You must also verify that <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> users and roles have beencorrectly mapped <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> users and roles, and that all objects in the databasehave the appropriate access rights granted <strong>to</strong> them.Validate DataThe existence of indexes and c<strong>on</strong>straints during data migrati<strong>on</strong> adversely affects theper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of the data migrati<strong>on</strong>. The firing of triggers can corrupt the data and produceundesirable effects. There<str<strong>on</strong>g>for</str<strong>on</strong>g>e, these objects have <strong>to</strong> be disabled or dropped. A negativeaspect of these acti<strong>on</strong>s is that data is not checked <str<strong>on</strong>g>for</str<strong>on</strong>g> correctness or completenessduring the migrati<strong>on</strong> and has <strong>to</strong> be validated after the migrati<strong>on</strong>. No special plans areneeded <str<strong>on</strong>g>for</str<strong>on</strong>g> validating data integrity. The database itself checks the integrity of the datawhen the c<strong>on</strong>straints are enabled using the WITH CHECK clause. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong><strong>on</strong> check c<strong>on</strong>straints in <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_aa-az_3ied.asp.The two types of tests that have <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> validate the data are discussed in the"Validating the Data Migrati<strong>on</strong>" secti<strong>on</strong> in Chapter 8.Note One of the comm<strong>on</strong> risks involved in data migrati<strong>on</strong> is the lack of a proper orcomplete set of c<strong>on</strong>straints in the database. In many applicati<strong>on</strong>s, the c<strong>on</strong>straints arebuilt in<strong>to</strong> the applicati<strong>on</strong>. In such cases, the development team will have <strong>to</strong> be involvedin c<strong>on</strong>structing <strong>SQL</strong>-based tests <strong>to</strong> verify data integrity by identifying such rules in theapplicati<strong>on</strong>.Validate the Migrati<strong>on</strong>After data migrati<strong>on</strong> is complete, tests have <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong> the database as a whole.Testing should cover the database architecture, database objects, data, and users. Inadditi<strong>on</strong>, the database c<strong>on</strong>nectivity, security, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance have <strong>to</strong> be tested. Forin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> client c<strong>on</strong>nectivity <strong>to</strong> the database, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_1_client_5er7.asp.A discussi<strong>on</strong> of the security architecture in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong> is available in Appendix A: "<strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Professi<strong>on</strong>als." AppendixB: "Getting the Best out of <strong>SQL</strong> <strong>Server</strong> 2000 and Windows" c<strong>on</strong>tains several references<strong>on</strong> <strong>SQL</strong> <strong>Server</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.While in smaller databases the data migrati<strong>on</strong> validati<strong>on</strong> can be exhaustive, in very largedatabases, some simpler tests (such as counts using various groupings) may be used.The following checks are recommended:● Develop group functi<strong>on</strong>s based <strong>on</strong> type of data.For example, a business-related check can be implemented by calculating the sumof the balances in all accounts.● Develop group functi<strong>on</strong>s based <strong>on</strong> time.● Check <str<strong>on</strong>g>for</str<strong>on</strong>g> record counts.● Use the applicati<strong>on</strong> <strong>to</strong> compare the summary reports.● Check <str<strong>on</strong>g>for</str<strong>on</strong>g> ad-hoc c<strong>on</strong>trol <strong>to</strong>tals.For example, after ledger data of a financial applicati<strong>on</strong> has been migrated, addingup the account numbers in that ledger has no business validity. However, this adhocc<strong>on</strong>trol <strong>to</strong>tal could reveal if all the data in the row has been migratedsuccessfully.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 171The <strong>SQL</strong> <strong>Server</strong> Migrati<strong>on</strong> Assistant offers a Migrati<strong>on</strong> Tester <strong>to</strong>ol that verifies themigrated objects (procedures, functi<strong>on</strong>s, and views) by generating its own set of testdata. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the Migrati<strong>on</strong> Tester and <strong>to</strong> download it refer <strong>to</strong>http://www.micro soft.com/sql/migrati<strong>on</strong>. The beta versi<strong>on</strong> of this <strong>to</strong>ol is available as of thedate of publishing this soluti<strong>on</strong>. Versi<strong>on</strong> 1.0 of the <strong>to</strong>ol is slated <strong>to</strong> be available in June2005.A test that validates the entire migrati<strong>on</strong> is the running of producti<strong>on</strong> reports andapplicati<strong>on</strong> with producti<strong>on</strong>-quality data. The same reports should be executed againstthe original database and the migrated database using a snapshot (or copy) of producti<strong>on</strong>data. Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and other vital database statistics, such as cache per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance andlocking, can be gathered.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 17310Developing: Applicati<strong>on</strong>s —Introducti<strong>on</strong>Introducti<strong>on</strong> and GoalsThe focus of Chapters 10 through 17 is c<strong>on</strong>necting existing <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> applicati<strong>on</strong>s in the<strong>UNIX</strong> envir<strong>on</strong>ment <strong>to</strong> the migrated Microsoft® <strong>SQL</strong> <strong>Server</strong> database. This chapterserves as an introducti<strong>on</strong> <strong>to</strong> the applicati<strong>on</strong>-oriented development chapters.The following list provides an overview of the c<strong>on</strong>tent in each of the applicati<strong>on</strong>-orienteddevelopment chapters:● Chapter 11, Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>. This chapterprovides a detailed discussi<strong>on</strong> of the <strong>SQL</strong> usage differences between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong>. Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> of PL/<strong>SQL</strong> <strong>to</strong> T-<strong>SQL</strong> is also covered.● Chapter 12, Developing: Applicati<strong>on</strong>s — Perl. This chapter discusses thestrategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating a Perl applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> use with the <strong>SQL</strong> <strong>Server</strong>envir<strong>on</strong>ment.● Chapter 13, Developing: Applicati<strong>on</strong>s — PHP. This chapter discusses thestrategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating a PHP applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> use with the <strong>SQL</strong> <strong>Server</strong>envir<strong>on</strong>ment.● Chapter 14, Developing: Applicati<strong>on</strong>s — Java. This chapter discusses thestrategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating a Java applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> use with the <strong>SQL</strong> <strong>Server</strong>envir<strong>on</strong>ment.● Chapter 15, Developing: Applicati<strong>on</strong>s — Pyth<strong>on</strong>. This chapter discusses thestrategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating a Pyth<strong>on</strong> applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> use with the <strong>SQL</strong> <strong>Server</strong>envir<strong>on</strong>ment.● Chapter 16, Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*C. This chapter discusses thestrategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating a Pro*C applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> use with the <strong>SQL</strong> <strong>Server</strong>envir<strong>on</strong>ment.● Chapter 17, Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms. This chapter discussesthe strategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> use with the<strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ment.No applicati<strong>on</strong> migrati<strong>on</strong> will be successful without a clear understanding of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>technologies that are fac<strong>to</strong>rs during an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database migrati<strong>on</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. Anoverview of these basic technologies and specific migrati<strong>on</strong>c<strong>on</strong>siderati<strong>on</strong>s is discussed


174 Developing: Applicati<strong>on</strong>s — Introducti<strong>on</strong>in the following two secti<strong>on</strong>s. The applicati<strong>on</strong> ecosystem can be broken in<strong>to</strong> the followingtwo tiers:● Data access● Programming language and c<strong>on</strong>nectivity tierData access comprises the comp<strong>on</strong>ents of the applicati<strong>on</strong> that interact with the databasedata. <strong>SQL</strong> is the language used <str<strong>on</strong>g>for</str<strong>on</strong>g> retrieving and manipulating the database data. Theapplicati<strong>on</strong> developer is resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> ensuring that applicati<strong>on</strong>s designed <str<strong>on</strong>g>for</str<strong>on</strong>g> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>source database work the same way with the migrated <strong>SQL</strong> <strong>Server</strong> target database. Thechanges required vary based <strong>on</strong> the programming language support and the API librariesavailable <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>. The migrati<strong>on</strong> of <strong>SQL</strong> and PL/<strong>SQL</strong> comp<strong>on</strong>ents <strong>to</strong> T-<strong>SQL</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>msa comm<strong>on</strong> requirement, irrespective of the changes <strong>to</strong> the rest of the applicati<strong>on</strong>. Themigrated applicati<strong>on</strong>s then have <strong>to</strong> be tested against the migrated <strong>SQL</strong> <strong>Server</strong> database<strong>to</strong> ensure their original functi<strong>on</strong>ality.From an applicati<strong>on</strong> developer's perspective, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> manage data insimilar ways. The internal differences between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> are significant, butif managed properly, these differences will have minimal impact <strong>on</strong> a migratedapplicati<strong>on</strong>.Applicati<strong>on</strong> Migrati<strong>on</strong> StrategiesThere are four different strategies <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong> migrati<strong>on</strong> that are discussed throughoutthe development chapters. These strategies include:● Interoperati<strong>on</strong>. The applicati<strong>on</strong> comp<strong>on</strong>ents remain in the <strong>UNIX</strong> envir<strong>on</strong>ment.● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. The applicati<strong>on</strong>is migrated <strong>to</strong> run <strong>on</strong> the .NET framework.● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft Win32® plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Theapplicati<strong>on</strong> is migrated <strong>to</strong> run <strong>on</strong> the Windows® envir<strong>on</strong>ment using the Win32 API.● Quick port using Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5. The applicati<strong>on</strong> is ported <strong>to</strong>use Interix within the Windows envir<strong>on</strong>ment.Each of the four strategies is discussed in more detail under the following headings. One,some, or all of these soluti<strong>on</strong> design strategies <str<strong>on</strong>g>for</str<strong>on</strong>g>ms the basis of the soluti<strong>on</strong> c<strong>on</strong>ceptthat was completed during the Envisi<strong>on</strong>ing Phase. Even when the goal is <strong>to</strong> standardize<strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, some of these strategies may be employed as intermediarysteps in a multi-phased migrati<strong>on</strong>.In general, .NET development is favored over Win32, but a number of recommendati<strong>on</strong>sin the following chapters provide guidance <strong>on</strong> migrating <strong>to</strong> a Win32 soluti<strong>on</strong>. Thisin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is provided in cases where a Win32 migrati<strong>on</strong> is the most cost-effective andstraight<str<strong>on</strong>g>for</str<strong>on</strong>g>ward development route.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> these migrati<strong>on</strong> strategies, see "Applicati<strong>on</strong> and DatabaseMigrati<strong>on</strong> <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> Design Strategy" in Chapter 2, "Envisi<strong>on</strong>ing Phase."Interoperati<strong>on</strong>In this strategy, the applicati<strong>on</strong> remains <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, while <strong>on</strong>ly the database ismigrated <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. This strategy is employed when minorchanges can be made <strong>to</strong> the source code, c<strong>on</strong>necti<strong>on</strong> strings, or the c<strong>on</strong>nectivity layer <strong>to</strong>allow <str<strong>on</strong>g>for</str<strong>on</strong>g> the change in the back end database.Often, an interoperati<strong>on</strong> strategy is used as an interim step in a phased migrati<strong>on</strong>. Thisstrategy allows <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong> <strong>to</strong> be quickly c<strong>on</strong>nected <strong>to</strong> the soluti<strong>on</strong>'s <strong>SQL</strong> <strong>Server</strong>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 175database with minimal risk or ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t. However, this would not be an adequate soluti<strong>on</strong> if<strong>on</strong>e of the business requirements <str<strong>on</strong>g>for</str<strong>on</strong>g> the migrati<strong>on</strong> project is eliminati<strong>on</strong> of the <strong>UNIX</strong>envir<strong>on</strong>ment.Port or Rewrite <strong>to</strong> .NET FrameworkThe .NET framework is the next generati<strong>on</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m from Microsoft <str<strong>on</strong>g>for</str<strong>on</strong>g> building,deploying, and running Windows applicati<strong>on</strong>s. It provides a highly productive, standards-envir<strong>on</strong>ment <str<strong>on</strong>g>for</str<strong>on</strong>g> integrating existing investments with next-based, multi-languagegenerati<strong>on</strong> applicati<strong>on</strong>s and services. When porting or rewriting, migrati<strong>on</strong> <strong>to</strong> the .NETplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m is preferred because it is the current development plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m <str<strong>on</strong>g>for</str<strong>on</strong>g> Windowsapplicati<strong>on</strong>s.When migrating an applicati<strong>on</strong> <strong>to</strong> the .NET framework, there are two different opti<strong>on</strong>s.One is <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m a full port of the applicati<strong>on</strong>, and the other is <strong>to</strong> rewrite the applicati<strong>on</strong>using the .NET applicati<strong>on</strong> programming interfaces (APIs).As of this writing, with the increased adopti<strong>on</strong> of the .NET Framework in the industry, theavailability of the .NET APIs <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong> porting are expanding. For some of thelanguages, the drivers are in beta with support being improved <strong>to</strong> include all functi<strong>on</strong>ality.Verify the stability of the library and the support <str<strong>on</strong>g>for</str<strong>on</strong>g> all the functi<strong>on</strong> calls needed <str<strong>on</strong>g>for</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong> when picking a driver.A rewrite of the applicati<strong>on</strong> is required when there is no support <strong>on</strong> the .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m <str<strong>on</strong>g>for</str<strong>on</strong>g>the language in use. An example of this would be an applicati<strong>on</strong> based <strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms.The best opti<strong>on</strong> in this case would be <strong>to</strong> rewrite the applicati<strong>on</strong> <strong>on</strong> Windows using VisualBasic® .NET.Rewriting an applicati<strong>on</strong> can potentially pose challenges. It can be a time-c<strong>on</strong>suming,risky, and costly opti<strong>on</strong>. The risk inherent in a rewrite is that the business logic or animportant functi<strong>on</strong>ality is inadvertently changed while rewriting the code. Careful testingand stabilizing of the rewritten applicati<strong>on</strong> needs <strong>to</strong> be c<strong>on</strong>ducted <strong>to</strong> ensure properbusiness logic and functi<strong>on</strong>ality. The following chapters provide detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong>database c<strong>on</strong>nectivity and the code changes needed <strong>to</strong> migrate <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong>soluti<strong>on</strong>. Rewriting an applicati<strong>on</strong> requires additi<strong>on</strong>al knowledge bey<strong>on</strong>d the scope of thisguide. Where appropriate, this guide provides references <strong>to</strong> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> aboutrewriting.Port or Rewrite <strong>to</strong> Win32Th e Win32 API is the primary programming interface <strong>to</strong> the Windows operating systemfamily, including Windows® 2003. The Win32 API provides functi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> processes,memory management, security, windowing, and graphics.C<strong>on</strong>sidering the benefits of migrati<strong>on</strong> <strong>to</strong> the .NET Framework, the <strong>on</strong>ly reas<strong>on</strong> <strong>to</strong> migrate<strong>to</strong> the Win32 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m is that migrati<strong>on</strong> <strong>to</strong> .NET is not technically feasible <str<strong>on</strong>g>for</str<strong>on</strong>g> yourorganizati<strong>on</strong>. As with the previous strategy, two migrati<strong>on</strong> opti<strong>on</strong>s are available whenmoving <strong>to</strong> a Win32-based plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. The first is <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m a port of the applicati<strong>on</strong>, andthe other is <strong>to</strong> rewrite the applicati<strong>on</strong> using the Win32 APIs.A port can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> most applicati<strong>on</strong>s that have been developed in Java, Perl, PHP, orPyth<strong>on</strong>, which are available <strong>on</strong> both the <strong>UNIX</strong> and Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms. APIs are available<str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> in a majority of cases. A port requires minimum changes <strong>to</strong> be d<strong>on</strong>e <strong>to</strong>the source code, and a port uses <strong>UNIX</strong>-standard compatible libraries and utilities thatexist <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Compared <strong>to</strong> a port, the source code in a rewrite requiresc<strong>on</strong>siderable changes <strong>to</strong> operate in the new envir<strong>on</strong>ment. When possible, c<strong>on</strong>siderrewriting the applicati<strong>on</strong> using .NET instead of Win32.


176 Developing: Applicati<strong>on</strong>s — Introducti<strong>on</strong>Quick Port Using Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>Applicati<strong>on</strong>s <strong>on</strong> <strong>UNIX</strong> can be rehosted <strong>to</strong> an envir<strong>on</strong>ment <strong>on</strong> Windows (Interix) that issimilar <strong>to</strong> <strong>UNIX</strong>. Interix is a complete, POSIX-compliant (Portable Operating SystemInterface) development envir<strong>on</strong>ment that is tightly integrated with the Windows kernel. Itis a part of the Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 product suite from Microsoft.One of the quickest migrati<strong>on</strong> paths possible is <strong>to</strong> port the code directly <strong>to</strong>Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>. Interix allows native <strong>UNIX</strong> applicati<strong>on</strong>s and scripts <strong>to</strong> workal<strong>on</strong>gside Windows applicati<strong>on</strong>s. The best way <strong>to</strong> view Interix is <strong>to</strong> understand it as aPOSIX-compliant versi<strong>on</strong> of <strong>UNIX</strong> built <strong>on</strong> <strong>to</strong>p of the Windows kernel. Importantly, Interixis not an emulati<strong>on</strong> of the <strong>UNIX</strong> envir<strong>on</strong>ment <strong>on</strong> the Windows APIs. Migrati<strong>on</strong> usingWindows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> involves obtaining the source code, installing it in the Interixdevelopment envir<strong>on</strong>ment, modifying the c<strong>on</strong>figurati<strong>on</strong> scripts and makefiles, andrecompiling the applicati<strong>on</strong>. This strategy is referred <strong>to</strong> as a quick port. As with any othermigrati<strong>on</strong> strategies, the data access (<strong>SQL</strong>, PL/<strong>SQL</strong>) has <strong>to</strong> be migrated <strong>to</strong> target a<strong>SQL</strong> <strong>Server</strong> database. A quick port is preferred if the client applicati<strong>on</strong> is closely tied <strong>to</strong><strong>UNIX</strong> utilities that are not available <strong>on</strong> Windows. This approach cannot rely <strong>on</strong> speciallibraries <str<strong>on</strong>g>for</str<strong>on</strong>g> which the source code is not available. Also, quick ports usingWindows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> cannot take advantage of most standard Windowsfuncti<strong>on</strong>ality.The ported applicati<strong>on</strong> may be successful immediately, or it may require modificati<strong>on</strong>s <strong>to</strong>account <str<strong>on</strong>g>for</str<strong>on</strong>g> the new hardware plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, the target operating systems, and localc<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. It may not be possible <strong>to</strong> determine whether a quick port ispossible without actually c<strong>on</strong>ducting the port. Extensive testing of the applicati<strong>on</strong> isessential after the port <strong>to</strong> ensure that all features have been migrated successfully.Scenarios and CasesIn the following chapters, these migrati<strong>on</strong> strategies are discussed in relati<strong>on</strong> <strong>to</strong> comm<strong>on</strong>applicati<strong>on</strong> languages. All four strategies may not be available, feasible, or desirable <str<strong>on</strong>g>for</str<strong>on</strong>g>each of the languages. For example, per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming a quick port usingWindows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> is not discussed in the Perl chapter because Perl can runnatively <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Because the facilities available <strong>to</strong> Perl <strong>on</strong> Windows aremuch richer (including .NET) than those available <strong>to</strong> Perl <strong>on</strong> Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>,migrating Perl applicati<strong>on</strong>s <strong>to</strong> a Windows envir<strong>on</strong>ment is preferred.Throughout Chapters 11 through 17, the migrati<strong>on</strong> strategies are divided in<strong>to</strong> specificscenarios that may be similar <strong>to</strong> existing situati<strong>on</strong>s that you will encounter. Each scenariomay be split in<strong>to</strong> individual cases that detail the various opti<strong>on</strong>s available <str<strong>on</strong>g>for</str<strong>on</strong>g> a givenscenario. For example, the migrati<strong>on</strong> strategy of porting may best apply <strong>to</strong> your situati<strong>on</strong>.In porting PHP applicati<strong>on</strong>s <strong>to</strong> run in the Windows envir<strong>on</strong>ment scenario, there are threecases that are discussed based <strong>on</strong> the database driver being utilized. These individualcases include detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> regarding the use of ORA, OCI8, or ODBC databasedrivers <strong>to</strong> maintain c<strong>on</strong>nectivity in the soluti<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 17711Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong>andPL/<strong>SQL</strong>Introducti<strong>on</strong>A lthough <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and Microsoft® <strong>SQL</strong> <strong>Server</strong> both use the ANSI <strong>SQL</strong> language, eachuses proprietary extensi<strong>on</strong>s <strong>to</strong> add functi<strong>on</strong>ality. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> uses PL/<strong>SQL</strong>, while <strong>SQL</strong> <strong>Server</strong>uses Transact <strong>SQL</strong>. This cha pter focuses <strong>on</strong> applicati<strong>on</strong> code that may need <strong>to</strong> bemodified <str<strong>on</strong>g>for</str<strong>on</strong>g> use with <strong>SQL</strong> <strong>Server</strong> because of these extensi<strong>on</strong>s.This chapter should be used in c<strong>on</strong>juncti<strong>on</strong> with Chapters 12 through 17. These chaptersprovide in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong>-specific languages, including Perl, PHP, Java, Pyth<strong>on</strong>,Pro*C, and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms.No applicati<strong>on</strong> migrati<strong>on</strong> will be successful without a cle ar understanding of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>technologies that come in<strong>to</strong> play during an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database migrati<strong>on</strong> <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong>plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. The strategy <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong> c<strong>on</strong>versi<strong>on</strong> is broken down in<strong>to</strong> the following twosegments:● Data access, which is discussed in this chapter.● Programming language a nd c<strong>on</strong>nectivity tier, which are discussed in Chapters 12through 17.<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Data AccessThe applicati<strong>on</strong> c<strong>on</strong>versi<strong>on</strong> development team is resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> ensuring thatapplicati<strong>on</strong>s designed <str<strong>on</strong>g>for</str<strong>on</strong>g> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> source database work the same way with themigrated <strong>SQL</strong> <strong>Server</strong> target database.The applicati<strong>on</strong> migrati<strong>on</strong> process may appearcomplicated. Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e doing the migrati<strong>on</strong> ofthe <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> producti<strong>on</strong> database, the DBA or applicati<strong>on</strong> developer should install a<strong>SQL</strong> <strong>Server</strong> test database. Applicati<strong>on</strong>s can then be modified and tested, if necessary, <strong>to</strong>ensure their original functi<strong>on</strong>ality with the <strong>SQL</strong> <strong>Server</strong> database. Testing is necessarybecause of the core differences between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.There are some architectural differences between each RDBMS. The terminology used<strong>to</strong> describe <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> architecture often has a completely different meaning in Microsoft<strong>SQL</strong> <strong>Server</strong>; <str<strong>on</strong>g>for</str<strong>on</strong>g> example, the term database has a different meaning. Additi<strong>on</strong>ally, both


178 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> have made many proprietary extensi<strong>on</strong>s <strong>to</strong> the <strong>SQL</strong>-92 standard.These extensi<strong>on</strong>s are discussed throughout this chapter.F rom an applicati<strong>on</strong> develope r's perspective , <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> manage data insimilar ways. The internal differences between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> are significant, butif managed properly, have mi nimal impact <strong>on</strong> a migrated applicati<strong>on</strong>.The most signif icant migrati<strong>on</strong> issue that c<strong>on</strong>fr<strong>on</strong>ts the developer is the implementati<strong>on</strong> ofthe <strong>SQL</strong>-92 <strong>SQL</strong> language standard and the extensi<strong>on</strong>s that each RDBMS has <strong>to</strong> offer.Some developers use <strong>on</strong>ly st andard <strong>SQL</strong> language statements, preferring <strong>to</strong> keep theirprogram code as generic as possible. Generally, this means restricting program code <strong>to</strong>the entry-level <strong>SQL</strong>-92 standard, which is implemented c<strong>on</strong>sistently across manydatabase products, including <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Using RDBMS-specific extensi<strong>on</strong>s might produce unneeded complexity in the programcode during the migrati<strong>on</strong>. For example, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s DECODE functi<strong>on</strong> is a n<strong>on</strong>standard<strong>SQL</strong> extensi<strong>on</strong> specific <strong>to</strong> Ora cle. The CASE expressi<strong>on</strong> in <strong>SQL</strong> <strong>Server</strong> is notimplemented in all database products.B oth the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DECODE and the <strong>SQL</strong> <strong>Server</strong> CASE expressi<strong>on</strong>s can per<str<strong>on</strong>g>for</str<strong>on</strong>g>msophisticated c<strong>on</strong>diti<strong>on</strong>al evaluati<strong>on</strong>s from within a query. The alternative <strong>to</strong> using thesefuncti<strong>on</strong>s is <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the functi<strong>on</strong> programmatically, which could require substantiallymore data be retrieved from the RDBMS.<strong>SQL</strong> has seen several sets of standards implemented and embraced by AmericanNati<strong>on</strong>al Standards Institute ( ANSI) and Internati<strong>on</strong>al Standards Organizati<strong>on</strong> (ISO).Although there are several enhancement releases of each standard set, the majorreleases are S QL-86, <strong>SQL</strong>-89 (also called <strong>SQL</strong>1), <strong>SQL</strong>-92 (also called <strong>SQL</strong>2) and <strong>SQL</strong>-99 (also called <strong>SQL</strong>3), with <strong>SQL</strong>-99 merging ANSI and ISO standards in<strong>to</strong> <strong>on</strong>e set.There are four levels or sets of features in <strong>SQL</strong>-92: entry-level, transiti<strong>on</strong>al, intermediate,and full. <strong>SQL</strong> <strong>Server</strong> 2000 Transact-<strong>SQL</strong> complies with the entry level of the <strong>SQL</strong>-92standard, and it supports many additi<strong>on</strong>al features from the intermediate and full levels ofthe standard.<strong>SQL</strong>-99 has two sets of features: core and n<strong>on</strong>-core. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i fully supports a majority ofthe core <strong>SQL</strong>-99 features, and it partially supports the n <strong>on</strong>-core features.T he <strong>SQL</strong>-92 entry-level feature set is very similar <strong>to</strong> the <strong>SQL</strong>-99 core feature set, whichm eans <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i supports entry level feature s of <strong>SQL</strong>-92 entry level. Even though bothsupport many of t he standard features, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> do not use the samesyntax. In additi<strong>on</strong>, each RDBMS has its own unique functi<strong>on</strong>ality and extensi<strong>on</strong>s.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> statements and Microsoft <strong>SQL</strong> <strong>Server</strong> T-<strong>SQL</strong> are compatible with each otherin several areas with minimal changes in the syntax. All the basic and advancedfuncti<strong>on</strong>ality furnished by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> can be achieved in <strong>SQL</strong> <strong>Server</strong> with ease.Though both these RDBMSs can be used <strong>to</strong> build robust and efficient systems, they differr adically in the administrative functi<strong>on</strong>s and plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m dependence.This secti<strong>on</strong> shows how <strong>to</strong> arrive at T-<strong>SQL</strong> equivalents <str<strong>on</strong>g>for</str<strong>on</strong>g> the most comm<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong>u sages, and it includes comprehensive coverage of all a spects of the <strong>SQL</strong> languagei mplementati<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 179Sample TablesThe following tables are used in all the exa mples in this chapter.Table 11.1: Category TableCOLUMN_NAME DATATYPE CONSTRAINTCATEGORYID VARCHAR(10) Primary KeyCATEGORYNAMEDESCRIPTIONTable 11.2: Cus<strong>to</strong>mer TableVARCHAR(40)VARCHAR(50)COLUMN_NAME DATATYPE CONSTRAINTCUSTOMERID VARCHAR(10) Primary KeyCOMPANYNAMECONTACTNAMECONTACTTITLEADDRESSCITYREGIONPOSTALCODECOUNTRYPHONEFAXTable 11.3: Employee TableVARCHAR(40)VARCHAR(40)VARCHAR(40)VARCHAR(50)VARCHAR(30)VARCHAR(30)VARCHAR(10)VARCHAR(30)NUMERIC(10.0)NUMERIC(10.0)COLUMN_NAME DATATYPE CONSTRAINTEMPLOYEEID VARCHAR(10) Primary KeyLASTNAMEFIRSTNAMETITLETITLEOFCOURTESYBIRTHDATEHIREDATEADDRESSCITYPOSTALCODECOUNTRYVARCHAR(40)VARCHAR(40)VARCHAR(40)VARCHAR(50)DATETIMEDATETIMEVARCHAR(40)VARCHAR(30)NUMERIC(10.0)VARCHAR(10)REPORTINGTO VARCHAR(10) Foreign Key


180 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>Table 11.4: OrderMaster TableCOLUMN_NAME DATATYPE CONSTRAINTORDERID VARCHAR(10) Primary KeyCUSTOMERID VARCHAR(10) Foreign KeyEMPLOYEEID VARCHAR(10) Foreign KeyORDERDATEREQUIREDDATESHIPPEDDATESHIPVIAFREIGHTDATETIMEDATETIMEDATETIMEVARCHAR(30)NUMERIC(10.0)SHIPNAMEVARCHAR( 30)SHIPADDRESSSHIPCITYSHIPREGIONSHIPPOSTALCODETable 11.5: OrderDetails TableVARCHAR(30)VARCHAR(10)VARCHAR(30)VARCHAR(10)COLUMN_NAME DATATYPE CONSTRAINTORDERID VARCHAR(10) Foreign KeyPRODUCTID VARCHAR(10) Foreign KeyUNITPRICEQUANTITYDISCOUNTTable 11.6: OrderPrice TableNUMERIC(10.2)NUMERIC(10.0)NUMERIC(10.0)COLUMN_NAME DATATYPE CONSTRAINTORDERID VARCHAR(10) Foreign KeyPRODUCTID VARCHAR(10) Foreign KeyREVISEDPRICEREVISEDONTable 11.7: Product TableNUMERIC(10.2)DATETIMECOLUMN_NAME DATATYPE CONSTRAINTPRODUCTID VARCHAR(10) Primary KeyPRODUCTNAMEVARCHAR(30)SUPPLIERID VARCHAR(30) Foreign KeyCATEGORYID VARCHAR(10) Foreign KeyQUANTITYPERUNITUNITPRICENUMERIC(10.0)NUMERIC(10.2)UNITINSTOCK NUMERIC(10.0)UNITSONORDERREORDERLEVELDISCONTINUEDNUMERIC(10.0)NUMERIC(10.0)NUMERIC(10.0)


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 181Table 11.8: Shippers TableCOLUMN_NAME DATATYPE CONSTRAINTSHIPPERID VARCHAR(10) Primary KeyCOMPANYNAMEVARCHAR(30)PHONENUMERIC(10.0)Table 11.9: Suppliers TableCOLUMN_NAME DATATYPE CONSTRAINTSUPPLIERID INT DENTITY Primary KeyCOMPANYNAMEVARCHAR(30)CONTACTNAMEVARCHAR(30)CONTACTTITLEVARCHAR(40)ADDRESSVARCHAR(40)CITYVARCHAR(30)POSTALCODENUMERIC(10.0)COUNTRYVARCHAR(40)PHONENUMERIC(10)FAXNUMERIC(10)Table 11.10: ShippedOrders TableCOLUMN_NAME DATATYPE CONSTRAINTORDERID VARCHAR(10) Foreign KeyCUSTOMERID VARCHAR(10) Foreign KeyEMPLOYEEID VARCHAR(10) Foreign KeyORDERDATEDATETIMEREQUIREDDATEDATETIMESHIPPEDDATEDATETIMESHIPVIAVARCHAR(30)FREIGHTNUMERIC(10.0)SHIPNAMEVARCHAR(30)SHIPADDRESSVARCHAR(30)SHIPCITYVARCHAR(10)SHIPREGIONVARCHAR(30)SHIPPOSTALCODE VARCHAR(10)Migrati<strong>on</strong> Process OverviewRecommended high-level steps <str<strong>on</strong>g>for</str<strong>on</strong>g> the migrati<strong>on</strong> process include:1. Extracti<strong>on</strong> of data access. Identify the <strong>SQL</strong> statements used in the applicati<strong>on</strong>and make sure it will work with <strong>SQL</strong> <strong>Server</strong>. If some <strong>SQL</strong> statements are database-specific, rewrite them <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>.2. Transacti<strong>on</strong> management. Accommodate changes in the transacti<strong>on</strong> because ofthe migrati<strong>on</strong>.


182 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>3. Fetch strategy. Pay special attenti<strong>on</strong> <strong>to</strong> cursor management and rewrite it ineasier way by making use of effective cursor management available in<strong>SQL</strong> <strong>Server</strong> 2000. Try <strong>to</strong> avoid cursors being used by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> applicati<strong>on</strong> ifpossible.4. Subprograms c<strong>on</strong>versi<strong>on</strong>. Identify all the procedures, functi<strong>on</strong>s, and triggers andrewrite in T-<strong>SQL</strong>.5. Job scheduling. Batch jobs that are written in PL/<strong>SQL</strong> should be rewritten.6. Interface file c<strong>on</strong>versi<strong>on</strong>. For any inbound (text file -> table) jobs, pay attenti<strong>on</strong> <strong>to</strong>the interface file and make sure there are no problems with the current <str<strong>on</strong>g>for</str<strong>on</strong>g>mat ofthe interface file. Pay attenti<strong>on</strong> <strong>to</strong> any outbound interface as well. Keep in mind thatthe date <str<strong>on</strong>g>for</str<strong>on</strong>g>mat between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> are different.7. Workflow au<strong>to</strong>mati<strong>on</strong>. Workflow au<strong>to</strong>mati<strong>on</strong> is implemented in the applicati<strong>on</strong>.The creati<strong>on</strong>of Mail Ids is required.8. Per<str<strong>on</strong>g>for</str<strong>on</strong>g>man ce tuning. Tune the T-<strong>SQL</strong> statements wherever it is required.During these steps, the developer should look at the applicati<strong>on</strong> code and startc<strong>on</strong>verting <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>-specific code in<strong>to</strong> T-<strong>SQL</strong> compatible code. All major <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> commandsand how <strong>to</strong> c<strong>on</strong>vert them in<strong>to</strong> T-<strong>SQL</strong> are discussed in detail throughout this chapter.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> both provide extensive support <str<strong>on</strong>g>for</str<strong>on</strong>g> XML, whose migrati<strong>on</strong> is notwithin the scope of this guide. For details <strong>on</strong> the SML support available in <strong>SQL</strong> <strong>Server</strong>refer <strong>to</strong> http://msdn.microsoft.com/library/default.asp?url=/library/enus/architec/8_ar_cs_9oj8.asp.Step 1: Extracti<strong>on</strong> of Data AccessThe first step is <strong>to</strong> identify the <strong>SQL</strong> used in the applicati<strong>on</strong>. <strong>SQL</strong> includes DataManipulati<strong>on</strong> Language (DML), Data Query Language (DQL or, simply, queries), andopera<strong>to</strong>rs. The majority of <strong>SQL</strong> syntax is comm<strong>on</strong> between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> withminor variati<strong>on</strong>s.There are several different types of in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in the <strong>SQL</strong> code that will need <strong>to</strong> beidentified. If these types do not comply with the specificati<strong>on</strong>s and syntax of <strong>SQL</strong> <strong>Server</strong>,this in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> will need <strong>to</strong> be modified. An in-depth discussi<strong>on</strong> of the following <strong>to</strong>pics isincluded in this secti<strong>on</strong>:● Opera<strong>to</strong>rs● Functi<strong>on</strong>s● Queries● Data Manipulati<strong>on</strong> Language (DML)Opera<strong>to</strong>rsOpera<strong>to</strong>rs are used <str<strong>on</strong>g>for</str<strong>on</strong>g> many different purposes in <strong>SQL</strong>. Table 11. 11 displays theseo pera<strong>to</strong>rs by type.Table 11.11 : Comm<strong>on</strong>ly Used Opera<strong>to</strong>rsOpera<strong>to</strong>r Type ExampleArithmetic +, -, *, /Comparis<strong>on</strong> =, , =LogicalAND,OR, NOT , XOR


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 183These opera<strong>to</strong>rs may play a role in the SELECT clause of a query ( <str<strong>on</strong>g>for</str<strong>on</strong>g> reportingpurposes), or they may be used in a PL/<strong>SQL</strong> block <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming various calculati<strong>on</strong>s <strong>to</strong>complete the transacti<strong>on</strong>.The in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> under the following heading describes how each of the opera<strong>to</strong>rs is usedi n <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Opera<strong>to</strong>r PrecedenceWhen multiple arithmetic opera<strong>to</strong>rs are used in a single query, the processing of theoperati<strong>on</strong> takes place according <strong>to</strong> the precedence of the opera<strong>to</strong>rs. The precedencel evel of arithmetic opera<strong>to</strong>rs in an expressi<strong>on</strong> is multiplicati<strong>on</strong> (*), divisi<strong>on</strong> (/), modulo (%),additi<strong>on</strong> (+), c<strong>on</strong>catenati<strong>on</strong> (+), and subtracti<strong>on</strong> (-). Equati<strong>on</strong>s c<strong>on</strong>tained withinparentheses take precedence and are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med first. The order of executi<strong>on</strong> is from left<strong>to</strong> right.C<strong>on</strong>catenati<strong>on</strong> Opera<strong>to</strong>rsC<strong>on</strong>catenati<strong>on</strong> is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med differently between <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Thec<strong>on</strong>catenati<strong>on</strong> opera<strong>to</strong>r (<str<strong>on</strong>g>for</str<strong>on</strong>g> character strings) used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> is “||” or CONCAT(string1,string2). The following example shows this syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> each usage. Each of thesestatements will produce the same result in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.SELECT FI RSTNAME || LASTNAME NAME FROM EMPLOYEESELECT CONCAT(FIRSTNAME, LASTNAME) NAME FROM EMPLOYEE;In these statements, the first name is c<strong>on</strong>catenated with the last name and the label <str<strong>on</strong>g>for</str<strong>on</strong>g>the field is NAME. <strong>SQL</strong> <strong>Server</strong> uses a different opera<strong>to</strong>r <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>catenati<strong>on</strong>. Thec<strong>on</strong>catenati<strong>on</strong> op era<strong>to</strong>r (<str<strong>on</strong>g>for</str<strong>on</strong>g> character strings) used in <strong>SQL</strong> <strong>Server</strong> is “+.” The followingexample shows the first name c<strong>on</strong>catenated with the last name, al<strong>on</strong>g with empty spacein between the names. The label<str<strong>on</strong>g>for</str<strong>on</strong>g> the field is NAME.SELECT FIRSTNAME + ‘ ‘ + LASTNAME As NAME FROM EMPLOYEEComparis<strong>on</strong> Opera<strong>to</strong>rsC<strong>on</strong>diti<strong>on</strong>s are evaluated using comparis<strong>on</strong> opera<strong>to</strong>rs, including "=", ">" and ">=", “


184 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>Opera<strong>to</strong>r MeaningALL TRUE if all of a set of comparis<strong>on</strong>s are TRUEANDTRUE if both Boolean expressi<strong>on</strong>s are TRUEANY TRUE if any <strong>on</strong>e of a set of comparis<strong>on</strong>s is TRUEBETWEEN TRUE if the operand is within a rangeEXISTSINTRUE if a subquery c<strong>on</strong>tains any rowsTRUE if the operand is equal <strong>to</strong> <strong>on</strong>e of a list of expressi<strong>on</strong>sLIKE TRUE if the opera nd matches a patternNOT Reverses the value of any other Boolean opera<strong>to</strong>rSOMEIS NULLTRUE if some of a set of comparis<strong>on</strong>s are TRUETRUE if operand is NULLIS NOT NULL TRUE if operand is not NULLORDatatype PrecedenceTRUE if either Boolean express i<strong>on</strong> is TRUEEach column valu e and c<strong>on</strong>stant in a <strong>SQL</strong> statement has a datatype that is associatedwith a specific s<strong>to</strong>rage <str<strong>on</strong>g>for</str<strong>on</strong>g>mat, c<strong>on</strong>straints, and a valid range of values. When a table iscreated, a datatype is specified fo r each column.Arithmetic operati<strong>on</strong>s per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong> columns and c<strong>on</strong>stants of different datatypes, suchas INT and SMALLINT, are called as mixed mode arithmetic operati<strong>on</strong>s. In mixed modearithmetic operati<strong>on</strong>s, the lower d atatype value is c<strong>on</strong>verted in<strong>to</strong> a h igher datatype valueaccording <strong>to</strong> datatype precedence.Datatype c<strong>on</strong>versi<strong>on</strong> is often needed <strong>to</strong> attain compatibility during calculati<strong>on</strong>,c<strong>on</strong>catenati<strong>on</strong>, or comparis<strong>on</strong> of values.Functi<strong>on</strong>sIn many places, built-in functi<strong>on</strong>s are used <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>versi<strong>on</strong> and <str<strong>on</strong>g>for</str<strong>on</strong>g> o ther purposes. Somecomm<strong>on</strong>ly used functi<strong>on</strong>s are defined and discussed here with examples provided <str<strong>on</strong>g>for</str<strong>on</strong>g>their use. Some f uncti<strong>on</strong>s that are available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are not available in<strong>SQL</strong> <strong>Server</strong> 2000 or earlier versi<strong>on</strong>s. However, those functi<strong>on</strong>s canbe written in<strong>SQL</strong> <strong>Server</strong> with the same name and the same fun cti<strong>on</strong>ality. They are called user-definedfuncti<strong>on</strong>s. Some user-defined functi<strong>on</strong>s are described later in this chapter.Number and Mathematical Functi<strong>on</strong>sTable 11.13 details the differences in syntax and usage between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.These functi<strong>on</strong>s are all mathematically based.Table 11.13: Mathematical Functi<strong>on</strong>s in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Descripti<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> <strong>SQL</strong> <strong>Server</strong>Functi<strong>on</strong> Example Functi<strong>on</strong> ExampleABSReturns the ABS (-20) ABS ABS(-20)absolute valueof nACOSReturns cosineof n. n must bebetween –1and 1ACOS (.4) ACOS ACOS(.4)


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 185CEIL Returns the CEIL (12.3) CEILING CEILING (12.3)smallest returns 13returns 13integer greaterthan nFLOOR Returns the FLOOR (12.3) FLOOR FLOOR (12.3)smallestinteger smallerthan nreturns 12returns 12MODReturns the MOD (12,5) % 12%5 returns 2reminder of mdivided by nreturns 2POWER Computes thevalue ofPOWER (10,5)returns 100000POWER POWER (10,5)returns 100000argument 1raised <strong>to</strong> thepower ofargument 2ROUNDReturns thenearest valueof the decimalas per theprecisi<strong>on</strong>specifiedTruncates thedecimalROUND(10.125,2)ROUNDROUND(10.125,2)returns 10.13 returns 10.130TRUNC TRUNC (12.54) CONVERTreturns 12CONVERT(INTEGER,12.54) returns12Character Functi<strong>on</strong>sTable 11.14 details the differences in syntax and usage between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.These functi<strong>on</strong>s are all related <strong>to</strong> text strings and characters.Table 11.14: Character Functi<strong>on</strong>s in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Functi<strong>on</strong>Descripti<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>ExampleCHR Returns the CHR (65)character <str<strong>on</strong>g>for</str<strong>on</strong>g> returns Athe ASCII valueCONCAT Appends two CONCATstring value s ('Tom', 'Mike')return TomMikeINITCAP GivesINITCAP ('terryuppercase <strong>to</strong>adams') returnsthe title (TitleTerry Adamscase)<strong>SQL</strong> <strong>Server</strong> <strong>SQL</strong> <strong>Server</strong>Functi<strong>on</strong> ExampleCHAR CHAR (65)returns A+ 'Tom' + 'Mike'returns TomMikeNo equivalentfuncti<strong>on</strong>An algorithmcan be written<str<strong>on</strong>g>for</str<strong>on</strong>g> equivalentfuncti<strong>on</strong>ality


186 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>LOWERReturns thelowercase ofthe stringLOWER ('TIM')returns timLOWERLTRIM Trims the LTRIM (' TIM') LTRIMleading spacesin a givenreturns 'TIM'StringREPLACE Replaces a REPLACEREPLACEmatching String ('TIM','I','o')with a new returns ToMString in agiven StringRPADPad characters RPADNo equivalent<strong>to</strong> the right side ('USA',5,'*')functi<strong>on</strong>of the string returns USA**LPADSOUNDEXSUBSTRPad characters<strong>to</strong> the left sideof the stringSOUNDEXfuncti<strong>on</strong> letsyou <strong>to</strong> comparewords that arespelleddifferently butsound alikeTo take <strong>on</strong>ly afew charactersLPAD('USA',5,'*')returns **USASOUNDEX('CHARLOTTE') is equal <strong>to</strong>SOUNDEX('CHARLOTE')SUBSTRING('Bikes', 1,4)No equivalentfuncti<strong>on</strong>SOUNDEXSUBSTRINGLOWER('TIM')returns timLTRIM(' TIM')returns 'TIM'REPLACE('TIM','i','o') returnsToMAn algorithmcan be written<str<strong>on</strong>g>for</str<strong>on</strong>g> equivalentfuncti<strong>on</strong>alityAn algorithmcan be written<str<strong>on</strong>g>for</str<strong>on</strong>g> equivalentfuncti<strong>on</strong>alitySOUNDEX('CHARLOTTE') is equal <strong>to</strong>SOUNDEX('CHARLOTE')SUBSTRING('Bikes', 1,4)from a string returns Bike returns BikeTRANSLATE Translate a This functi<strong>on</strong> in No equivalent An algorithmcharacter <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> is used functi<strong>on</strong> can be writtenstring. Used <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>to</strong> c<strong>on</strong>vert a<str<strong>on</strong>g>for</str<strong>on</strong>g> equivalentencrypti<strong>on</strong> string in<strong>to</strong>another <str<strong>on</strong>g>for</str<strong>on</strong>g>m.functi<strong>on</strong>alityLow level ofencrypti<strong>on</strong> isd<strong>on</strong>e usingthis.TRIMUPPERASCIITo remove theleading andtrailing spacesof a stringReturns theuppercase ofthe stringReturns the ASCII ('A')ASCII value of returns 65TRIM (' THISIS TEST ')returns THIS ISLTRIM andRTRIM can becombinedRTRIM(LTRIM(' THIS IS TEST')) returns THISTESTIS TESTUPPER ('tim') UPPER UPPER('tim')returns TIMreturns TIMASCIIASCII('A')returns 65


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 187the characterINSTRLENGTHUsed <strong>to</strong> findthe locati<strong>on</strong> ofa sub string ora characterinside a stringReturns thelength of agiven stringINSTR('NORTHCAROLINA','OR', 1) returns 2LENGTH('TOM') returns3CHARINDEXLENCHARINDEX('OR','NORTHCAROLINA', 1)returns 2LEN ('TOM')returns 3Date Functi<strong>on</strong>sTable 11.15 details the differences in syntax and usage between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.These functi<strong>on</strong>s are all date-based.Table 11.15: Date Functi<strong>on</strong>s in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Descripti<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> <strong>SQL</strong> <strong>Server</strong>Functi<strong>on</strong>Example Functi<strong>on</strong> ExampleADD_MONTHSNEXT_DAYSYSDATETO_CHARTO_DATETo add numberof m<strong>on</strong>ths <str<strong>on</strong>g>for</str<strong>on</strong>g> agiven dateNEXT_DAYfuncti<strong>on</strong> returnsthe firstweekday laterthan thepassed dateReturns thecurrent dateTO_CHAR isused when anINTEGER orDATE valueneeds <strong>to</strong> bec<strong>on</strong>verted in<strong>to</strong>StringAny givenstring in a validdate <str<strong>on</strong>g>for</str<strong>on</strong>g>mat canbe c<strong>on</strong>vertedin<strong>to</strong> DATEDatatypeADD_MONTHS ('15-NOV-2004', 1)returns '15-DEC-2004'NEXT_DAY(SYSDATE,'FRIDAY')returns thedate of thecoming FridaySYSDATEreturns thecurrent dateTO_CHAR(sysdate,'MM/DD/YY')TO_DATE ('12-MAY-2003','DD-MON-YYYY')DATEADDNo equivalentfuncti<strong>on</strong>DATEADD(MM, 1,'15-NOV-2004' )returns '15-DEC-2004'An algorithmcan be written<str<strong>on</strong>g>for</str<strong>on</strong>g> equivalentfuncti<strong>on</strong>alityGETDATE () GETDATE ()returns thecurrent datewith time stampCAST orCONVERTCASTCONVERT(char, getdate(), 1) returnsdate inMM/DD/YY<str<strong>on</strong>g>for</str<strong>on</strong>g>mat.CAST ('12-MAY-200312:00:00' asDATETIME)The CONVERT functi<strong>on</strong> is used in <strong>SQL</strong> <strong>Server</strong> <strong>to</strong> change the date <str<strong>on</strong>g>for</str<strong>on</strong>g>mat. This isequivalent <strong>to</strong> the TO_CHAR functi<strong>on</strong> of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. CONVERThas three parameters. The


188 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>first parameter is datatype. The sec<strong>on</strong>d parameter is <str<strong>on</strong>g>for</str<strong>on</strong>g> the column <strong>to</strong> be <str<strong>on</strong>g>for</str<strong>on</strong>g>matted. Thethird parameter is the desired <str<strong>on</strong>g>for</str<strong>on</strong>g>mat. Please see the list of <str<strong>on</strong>g>for</str<strong>on</strong>g>mats and thecorresp<strong>on</strong>ding <str<strong>on</strong>g>for</str<strong>on</strong>g>mula in Table 11.16.Table 11.16: CONVERT Functi<strong>on</strong> Formats in <strong>SQL</strong> <strong>Server</strong>WITH CENTURY (YYYY)INPUT/OUTPUT0 OR 100 (*) MON DD YYYY HH:MIAM (OR PM)101 MM/DD/YY102 YY.MM.DD103 DD/MM/YY104 DD.MM.YY105 DD-MM-YY106DD MON YY107 MON DD, YY108 HH:MM:SS9 OR 109 (*)DEFAULT + MILLISECONDS110MON DD YYYY HH:MI:SS:MMMAM (ORPM)MM-DD-YY111 YY/MM/DD112 YYMMDD13 OR 113 (*) DD MON YYYY HH:MM:SS:MMM(24H)114 HH:MI:SS:MMM(24H)20 OR 120 (*) YYYY-MM-DD HH:MI:SS(24H)21 OR 121 (*) YYYY-MM-DD HH: MI: SS.MMM (24H)130* DD MON YYYY HH:MI:SS:MMMAM131* DD/MM/YY HH:MI:SS:MMMAMC<strong>on</strong>diti<strong>on</strong>al Functi<strong>on</strong>sC<strong>on</strong>diti<strong>on</strong>al functi<strong>on</strong>s are used <strong>to</strong> compare values or <strong>to</strong> evaluate a Boolean expressi<strong>on</strong>.Table 11.17 compares these functi<strong>on</strong>s between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Table 11.17: C<strong>on</strong>diti<strong>on</strong>al Functi<strong>on</strong>s in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Descripti<strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> <strong>SQL</strong> <strong>Server</strong>Functi<strong>on</strong> Example Functi<strong>on</strong> ExampleNVL To return a NVL (SALARY, ISNULL ISNULLdefault value if 0) returns 0 if(SALARY, 0)the expressi<strong>on</strong> the column returns 0 if theis nullvalue (SALARYcolumn) is nullcolumn value(SALARYcolumn) is nullNVL2 To return a NVL2 (Salary, CASECASE SALARYvalue if the Salary*2, 0) WHEN nullexpressi<strong>on</strong> isnull or nullreturns twotimes thesalary if not nulland 0 if nullTHEN 0ELSESALARY*2END


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 189NULLIFReturns a nullvalue if the twospecifiedexpressi<strong>on</strong>sare equivalentNULLIF(SYSDATE,SYSDATE)returns NULLNULLIFNULLIF(GETDATE (),GETDATE ())returns NULLDECODE Used <strong>to</strong> DECODE(DIS CASECASEevaluate the CONTINUED, DISCONTINUEvalues with "if- 0, 'No', 1, 'Yes',Delse" logic. 'NA')WHEN 0 THEN'No'WHEN 1 THEN'Yes'ELSE 'NA'ENDCASEUsed <strong>to</strong>evaluate thevalues with "if-CASEdisc<strong>on</strong>tinuedWHEN 0 THENCASECASEdisc<strong>on</strong>tinuedWHEN 0 THENelse" logic. 'No''No'WHEN 1 THEN'Yes'ELSE 'NA'ENDWHEN 1 THEN'Yes'ELSE 'NA'ENDQueriesThe SELECT statement is used <strong>to</strong> query the database and retrieve data. SELECT can becombined with some DDL and DML statements <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m relati<strong>on</strong>al operati<strong>on</strong>s. Thefollowing different clauses comm<strong>on</strong>ly used with SELECT in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> arediscussed in the remainder of this secti<strong>on</strong>.● Simple queries● Joins● Database links● Group by● Case● Set opera<strong>to</strong>rs● RownumOptimizer hints are not covered in this guidance. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use costthatcan be used <strong>to</strong> influence the optimizer. Thebased optimizers and offer hintsoptimizer hints used with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are not available in <strong>SQL</strong> <strong>Server</strong>. For the various types ofhints available in <strong>SQL</strong> <strong>Server</strong> refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/acdata/ac_8_qd_03_8upf.asp.Simple QueriesA simple query is defined as a SELECT statement that retrieves data from a single tablewith or without filter c<strong>on</strong>diti<strong>on</strong>. Becausethis is a standard command, there are nodifferences in syntax or usage between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. The following example isa valid statement <str<strong>on</strong>g>for</str<strong>on</strong>g> both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.


190 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>SELECT * FROM CUSTOMER;JoinsJoins play a major role when meaningful in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> needs <strong>to</strong> be retrieved from morethan <strong>on</strong>e table. Often, reports or intricate queries require data from two or more tables.The data from multiple tables must be logically related. <strong>SQL</strong> combines data from multipletables using joins in<strong>to</strong> a single result set.Joins can be of following types:● Inner join● Equi-join● N<strong>on</strong>-equi join●●Outer join● Left outer join● Right outer join● Full outer joinSelf-joinInner JoinInner join is the normal join that is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med am<strong>on</strong>g tables <strong>to</strong> fetch the matching data.Inner join can be either an equi-join or n<strong>on</strong>-equi join. Both equi and n<strong>on</strong>-equi join areexplained under the following headings.Equi-JoinAn equi-join equates fields from two or more tables <strong>to</strong> fetch matching data from the tablesselected. There is c<strong>on</strong>siderable difference in the syntax of an equi-join between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>and <strong>SQL</strong> <strong>Server</strong>.The standard <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> equi-join syntax is shown in the following example:SELECT TABLE1. FIELD1, TABLE2.FIELD1, TABLE2.FILED2FROM TABLE1, TABLE2WHERE TABLE1.FIELD3 = TABLE2.FIELD3AND TABLE1.FIELD4 = TABLE2.FIELD4<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i equi-joins are slightly different; the syntax is modified <strong>to</strong> comply with the ANSIstandard. The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i syntax is shown in the following example:SELECT TABLE1.FIELD1, TABLE2.FIELD1, TABLE2.FIELD2FROM (TABLE1 INNER JOIN TABLE2 ON TABLE1.FIELD3 = TABLE2.FIELD3AND TABLE1.FIELD4 = TABLE2.FIELD4)The <strong>SQL</strong> <strong>Server</strong> syntax is also slightly different, and it is shown in the following example:SELECT TABLE1.FIELD1, TABLE2.FIELD1, TABLE2.FIELD2FROM TABLE1 INNER JOIN TABLE2ON TABLE1.FIELD3_=_TABLE2.FIELD3AND TABLE1.FIELD4 = TABLE2.FIELD4For example, a company needs <strong>to</strong> create a report with the following in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>:● Product name● Price● Supplier’s company name● Category name


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 191For a product produced by the example company, the corresp<strong>on</strong>ding supplier’s companyname and the corresp<strong>on</strong>ding category name have <strong>to</strong> be displayed. The PRODUCT tablehas SUPPLIERID and CATEGORYID, but not their corresp<strong>on</strong>ding names. Procedures<str<strong>on</strong>g>for</str<strong>on</strong>g> using the PRODUCTNAME <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i, and <strong>SQL</strong> <strong>Server</strong> are shown in thefollowing examples.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the inner join will provide the needed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>:SELECT A.PRODUCTNAME, A.UNITPRICE, B.COMPANYNAME, C.CATEGORYNAMEFROM PRODUCT A, SUPPLIERS B, CATEGORY CWHERE A.SUPPLIERID = B.SUPPLIERIDAND A.CATEGORYID = C.CATEGORYIDThe following code produces the same inner join in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i:SELECT A.PRODUCTNAME, A.UNITPRICE, B.COMPANYNAME, C.CATEGORYNAMEFROM (PRODUCT A INNER JOIN SUPPLIERS BON A.SUPPLIERID = B.SUPPLIERID INNER JOIN CATEGORY CON A.CATEGORYID = C.CATEGORYID)The <strong>SQL</strong> <strong>Server</strong> syntax is the same as the preceding <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i syntax.Self JoinsSelf joins can be used when <strong>on</strong>e row in a table relates itself with other rows in the sametable. That is, the same table is used twice <str<strong>on</strong>g>for</str<strong>on</strong>g> comparis<strong>on</strong>. The same table must beexhibited as two different tables by using different aliases. This functi<strong>on</strong> is available in<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, though there are slight differences in syntax. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> self joins is provided here:SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A, TABLE1 BWHERE A.FIELD1 = B.FIELD1AND A.FIELD2 < B.FIELD2The <strong>SQL</strong> <strong>Server</strong> syntax is shown in the following example. Note the differences in thethird and fourth lines of the statement.SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A JOIN TABLE1 BON A.FIELD1 = B.FIELD1WHERE A.FIELD2 < B.FIELD2C<strong>on</strong> sider a case in which the result set must return a list of all companies in the same cityas the company “ABC Inc.”In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the statement would appear as:SELECT B.COMPANYNAMEFROM CUSTOMER A, CUSTOMER BWHERE A.CITY = B.CITYAND A.COMPANYNAME = 'ABC Inc'In <strong>SQL</strong> <strong>Server</strong>, the same result set can be returned using the following statement:SELECT B.COMPANYNAMEFROM CUSTOMER A JOIN CUSTOMER BON A.CITY = B.CITYWHERE A COMPANYNAME = 'ABC Inc'


192 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>N<strong>on</strong>-Equi JoinsN<strong>on</strong> -equi joins are used when there is not a direct link criteri<strong>on</strong> between the tables. It issimply a join where the joining criteria are anything other than “=.” The difference in thesyntax between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> in cases of n<strong>on</strong>-equi join is a minor difference inthe opera<strong>to</strong>rs used <strong>to</strong> notify the n<strong>on</strong>-equi join. The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> syntax is provided in thefollowing example:SELECT A.FIELD1, A.FIELD2, A.FIELD3, B.FIELD4FROM TABLE1 A, TABLE2 BWHERE A.FIELD1 = B.FIELD1AND A.FIELD2 B.FIELD2The <strong>SQL</strong> <strong>Server</strong> syntax is provided in the following example. Note the use of the innerjoin opera<strong>to</strong>r.SELECT A.FIELD1, A.FIELD2, A.FIELD3, B.FIELD4FROM TABLE1 A INNER JOIN TABLE2 BON A.FIELD1 = B.FIELD1WHERE A.FIELD2 B.FIELD2For example, imagine a case where there is a need <strong>to</strong> retrieve those products listedunder the same category but from different suppliers. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the statement can becreated as follows:SELECT A.PRODUCTID, A.PRODUCTNAME, A.UNITPRICEFROM PRODUCT A, PRODUCT BWHERE A.CATEGORYID = B.CATEGORYIDAND A.SUPPLIERID B.SUPPLIERIDThe same result can be accomplished in <strong>SQL</strong> <strong>Server</strong>, as shown in the following example:SELECT A.PRODUCTID, A.PRODUCTNAME, A.UNITPRICEFROM PRODUCT A INNER JOIN PRODUCT BON A.CATEGORYID = B.CATEGORYIDAND A.SUPPLIERID B.SUPPLIERIDOuter JoinsA join is termed as outer join when the result set c<strong>on</strong>tains all the rows from <strong>on</strong>e table and<strong>on</strong>ly the matching rows from the other table.An outer join can be a left outer join or a right outer join. Outer join syntax in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong> remained different until the release of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i. Thereafter, both follow ANSIstandards of using INNER JOIN or OUTER JOIN in words instead of opera<strong>to</strong>rs.All rows are retrieved from the left table referenced with a left outer join. Here, the outerjoin opera<strong>to</strong>r (+) is placed beside the table that is <strong>to</strong> the left of the "=" opera<strong>to</strong>r during thejoin.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> — left outer joinThe syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> left outer join is as follows:SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A, TABLE1 BWHERE A.FIELD1(+) = B.FIELD1Example <str<strong>on</strong>g>for</str<strong>on</strong>g> left outer join is:●SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B.CONTACTNAMEFROM PRODUCT A, SUPPLIERS BWHERE A.SUPPLIERID(+) = B.SUPPLIERID<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i — left outer join


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 193The ANSI syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> left outer join is as follows:SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A LEFT OUTER JOIN TABLE2 BON A.FIELD1 = B.FIELD1Example <str<strong>on</strong>g>for</str<strong>on</strong>g> ANSI compliant left outer join is:●SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B.CONTACTNAMEFROM PRODUCT A LEFT OUTER JOIN SUPPLIERS BON A.SUPPLIERID = B.SUPPLIERID<strong>SQL</strong> <strong>Server</strong> — left outer joinThe syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> left outer join is as follows:SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A LEFT OUTER JOIN TABLE2 BON A.FIELD1 = B.FIELD1Example <str<strong>on</strong>g>for</str<strong>on</strong>g> left outer join is:SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B.CONTACTNAMEFROM PRODUCT A LEFT OUTER JOIN SUPPLIERS BON A.SUPPLIERID = B.SUPPLIERIDAll rows are retrieved from the right table referenced in a right outer join. A right outer joinis used <strong>to</strong> furnish null rows <strong>to</strong> the right side table used during the Join c<strong>on</strong>diti<strong>on</strong>.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> — right outer joinThe syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> right outer join is as follows:SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A, TABLE1 BWHERE A.FIELD1 = B.FIELD1(+)Example <str<strong>on</strong>g>for</str<strong>on</strong>g> right outer join is:●SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B.CONTACTNAMEFROM PRODUCT A, SUPPLIERS BWHERE A.SUPPLIERID = B.SUPPLIERID(+)<strong>SQL</strong> <strong>Server</strong> — right outer joinThe syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> right outer join is asfollows:SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A RIGHT OUTER JOIN TABLE2 BON A.FIELD1 = B.FIELD1Example <str<strong>on</strong>g>for</str<strong>on</strong>g> right outer join is:SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B.CONTACTNAMEFROM PRODUCT A RIGHT OUTER JOIN SUPPLIERS BON A.SUPPLIERID = B.SUPPLIERIDAll row s from both tables are returned in a full outer join.• <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> — full outer join<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does not have a separate outer join syntax. The following shows anexample <str<strong>on</strong>g>for</str<strong>on</strong>g> full outer join:SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B.CONTACTNAMEFROM PRODUCT A, SUPPLIERS BWHERE A.SUPPLIERID = B.SUPPLIERID(+)UNION


194 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B.CONTACTNAMEFROM PRODUCT A, SUPPLIERS BWHERE A.SUPPLIERID(+) = B.SUPPLIERID• <strong>SQL</strong> Service — full outer joinThe syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> full outer join is as follows:SELECT A.FIELD1, A.FIELD2, B.FIELD1, B.FIELD2FROM TABLE1 A FULL OUTER JOIN TABLE2 BON A.FIELD1 = B.FIELD1Example <str<strong>on</strong>g>for</str<strong>on</strong>g> full outer join is:SELECT A.PRODUCTNAME, A.CATEGORYID, B.COMPANYNAME, B. CONTACTNAMEFROM PRODUCT A FULL OUTER JOIN SUPPLIERS BON A.SUPPLIERID = B.SUPPLIERIDSubqueriesA subquery is a normal query that is nested inside another query using parentheses.Subqueries are used <strong>to</strong> retrieve data from tables that depend <strong>on</strong> the values <strong>on</strong> the sametable or a different table. A statement c<strong>on</strong>taining a subquery is called a parent statement.A subquery can be comm<strong>on</strong>ly found in the FROM and WHERE clauses of a SELECTstatement. A subquery in the FROM clause is also called an inline view. Inline views in<strong>SQL</strong> <strong>Server</strong> are similar <strong>to</strong> those in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. In <strong>SQL</strong> <strong>Server</strong>, inline views have <strong>to</strong> be aliasedin all cases.Subqueries found in the WHERE clauses are called nested queries. Subqueries may benested in other subqueries. T-<strong>SQL</strong> queries can use a maximum of 256 tables, includingall subqueries, and a maximum of 32 levels of nesting. In c<strong>on</strong>trast, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> allows 255levels of nesting. It is uncomm<strong>on</strong> <strong>to</strong> use more than two or three levels of nesting inqueries. <strong>SQL</strong> <strong>Server</strong> supports most implementati<strong>on</strong>s of the nested query in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.Examples of nested queries are found throughout this chapter. <strong>SQL</strong> <strong>Server</strong>, however,does not support the ordered set as shown in the following example:SELECT productid, revisedpriceFROM OrderPriceWHERE (orderid, productid) IN (SELECT orderid, productidFROM OrderDetails)In such cases, the query can be c<strong>on</strong>verted in<strong>to</strong> <strong>on</strong>e using joins instead of the nestedquery.SELECT OP.productid, OP.revisedpriceFROM OrderPrice OP INNER JOIN OrderDetails ODON OP.orderid = OD.orderidAND OP.productid = OD.productidA nested query in which the nested query references columns in the parent table is calleda correlated subquery. A correlated subquery is executed <strong>on</strong>ce <str<strong>on</strong>g>for</str<strong>on</strong>g> each row in the parentstatement. Because <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> syntax and <strong>SQL</strong> <strong>Server</strong> syntax are similar, examples are notprovided here.Grouping Result Set<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> provide a method of grouping the result set using the GROUP BYclause. The GROUP BY clause summarizes the result set in<strong>to</strong> the groups defined in thequery using aggregate functi<strong>on</strong>ssuch as AVG or SUM. Using the HAVING clause can


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 195further filter the result set by comparing it with the aggregate functi<strong>on</strong>'s result. TheHAVING clause without a GROUP BY clause behaves like a simple WHERE c<strong>on</strong>diti<strong>on</strong>.HAV ING clauses are used with aggregati<strong>on</strong> functi<strong>on</strong>s and cannot be used with single rowfuncti<strong>on</strong>s.The GROUP BY clause treats the HAVING clause in the same way as SELECT treatsWHERE.A SELECT statement with a GROUP BY clause cannot have a COLUMN_NAME otherthan the columns available in the GROUP BY list. When GROUP BY is specified, eithereach column in any n<strong>on</strong>-aggregate expressi<strong>on</strong> in the select list should be included in theGROUP BY list, or the GROUP BY expressi<strong>on</strong> must match exactly the select listexpressi<strong>on</strong>.A GROUP BY clause can include an expressi<strong>on</strong> as l<strong>on</strong>g as it does not include anyagg regate functi<strong>on</strong>, and it cannot c<strong>on</strong>tain any sub query, either. In <strong>SQL</strong> <strong>Server</strong>, GROUPBY “ALL” can be used, but it is opti<strong>on</strong>al. When ALL is specified, null values are returned<str<strong>on</strong>g>for</str<strong>on</strong>g> the summary columns of groups that do not meet the search c<strong>on</strong>diti<strong>on</strong>.Because <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> <strong>SQL</strong> are similar, examples are not provided here.Database LinkWhen tables are <strong>to</strong> be joined across databases that are in different servers, the databaselink functi<strong>on</strong>ality can be used. In the examples provided in this secti<strong>on</strong>, the databases aredistributed in two geographical locati<strong>on</strong>s. One database is in New York, and another is inBos t<strong>on</strong>. A business user wants <strong>to</strong> know the <strong>to</strong>tal number of orders <str<strong>on</strong>g>for</str<strong>on</strong>g> the m<strong>on</strong>th of May,2004.● In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, databases are linked using the command CREATE DATABASE LINK.The TNSNAMES.ORA entry <str<strong>on</strong>g>for</str<strong>on</strong>g> the database is required.SELECT COUNT(*)FROM(SELECT ORDERID FROM ORDERMASTERWHERE orderdate > sysdate - 30UNIONSELECT ORDERID FROM ORDERMASTER@BOSTONWHERE ORDERDATE > sysdate - 30);● In <strong>SQL</strong> <strong>Server</strong>, some c<strong>on</strong>figurati<strong>on</strong> is needed be<str<strong>on</strong>g>for</str<strong>on</strong>g>e accessing remote databases.Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e querying tables from different databases <strong>on</strong> different servers, log in<strong>to</strong> thefirst database, go <strong>to</strong> Query Analyzer, and execute the following code.USE MASTERGOEXEC SP_ADDLINKEDSERVER@SERVER= 'BOSTON',@SRVPRODUCT= '',@PROVIDER='<strong>SQL</strong>OLEDB',@DATASRC='BOSTON\NWIND'GOEXEC SP_ADDLINKEDSRVLOGIN@RMTSRVNAME ='BOSTON',@USESELF='FALSE',@LOCALLOGIN=NULL,


196 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>CASE@RMTUSER ='ABC',@RMTPASSWORD ='ABC'GOExecuting these procedures establishes the link between the servers. Next,execute the following query <strong>to</strong> retrieve the data from two databases.SELECT COUNT(ORDERID)FROM(SELECT ORDERID FROM ORDERMASTERWHERE ORDERDATE > getdate() - 30UNIONSELECT ORDERID FROM [BOSTON].NWIND.DBO.ORDERMASTERWHERE ORDERDATE > getdate() - 30)CASE is used when there is a need <strong>to</strong> have "if-else" in this secti<strong>on</strong>, a s<strong>to</strong>re manager wants <strong>to</strong> see cus<strong>to</strong>mer names and segregatelogic. In the example code thatappearsthe orders in<strong>to</strong> the three following categories:● An order value less than $5,000 is small● An order value between $5,000 and $10,000 is medium● An order value greater than $10,000 is largeIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, this task would be accomplished using CASE as shown in the following codeexample:SELECT ORDERID,CASEWHEN SUM(UNITPRICE)


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 197●<strong>SQL</strong> <strong>Server</strong>SELECT COMPANYNAMEFROM [NEWYORK].NWIND.DBO.SUPPLIERSUNIONSELECT COMPANYNAMEFROM [BOSTON].NWIND.DBO.SUPPLIERSSet Opera<strong>to</strong>rs: IntersectThe intersect opera<strong>to</strong>r will <strong>on</strong>ly retrieve the comm<strong>on</strong> values from more than <strong>on</strong>e table. Inthe following example code, intersect is used <strong>to</strong> retrieve the supplier names comm<strong>on</strong> <strong>to</strong>both NEWYORK and BOSTON s<strong>to</strong>res.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●SELECT COMPANYNAME FROM SUPPLIERS@BOSTONINTERSECTSELECT COMPANYNAME FROM SUPPLIERS@NEWYORKclause can be written <str<strong>on</strong>g>for</str<strong>on</strong>g> the sameSet Opera<strong>to</strong>rs: MinusA minus opera<strong>to</strong>r is used when the difference of values from more than <strong>on</strong>e table needs<strong>to</strong> be fetched. In the following example code, this opera<strong>to</strong>r is used <strong>to</strong> list the suppliernames that are <strong>on</strong>ly in the BOSTON database and that are not in NEWYORK database.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●<strong>SQL</strong> <strong>Server</strong>In <strong>SQL</strong> <strong>Server</strong>, a subquery with an EXISTSpurpose.SELECT COMPANYNAME FROM [NEWYORK].NWIND.DBO.SUPPLIERS AWHERE EXISTS(SELECT 'X'FROM [BOSTON].NWIND.DBO.SUPPLIERS BWHERE A.COMPANYNAME = B.COMPANYNAME);SELECT COMPANYNAME FROM SUPPLIERS@BOSTONMINUSSELECT COMPANYNAME FROM SUPPLIERS@NEWYORK;<strong>SQL</strong> <strong>Server</strong>Because MINUS is not available in <strong>SQL</strong> <strong>Server</strong>, NOT EXISTS can be used. Thefollowing example shows how <strong>to</strong> use the NOT EXISTS opera<strong>to</strong>r.SELECT COMPANYNAME FROM SUPPLIERS AWHERE NOT EXISTS(SELECT 'X'FROM [BOSTON].NWIND.DBO.SUPPLIERS BWHERE A.COMPANYNAME = B.COMPANYNAME) ;


198 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>ROWNUMROWNUM is a special keyword in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Using ROWNUM can limit the number of rowsretrieved without any c<strong>on</strong>diti<strong>on</strong>. In the following example, ROWNUM is used <strong>to</strong> displaythe <strong>to</strong>p 10 orders from the ORDERDETAILS table.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●SELECT *FROM(SELECT ORDERID, SUM(UNITPRICE)FROM ORDERDETAILSGROUP BY ORDERIDORDER BY SUM(UNITPRICE) DESC)WHERE ROWNUM < 11;<strong>SQL</strong> <strong>Server</strong>SELECT TOP 10 ORDERID, SUM(UNITPRICE)FROM ORDERDETAILSGROUP BY ORDERIDORDER BY SUM(UNITPRICE) DESCData Manipulati<strong>on</strong> Language (DML)DML includes INSERT, UPDATE, and DELETE. The MERGE statement has also beendiscussed. The following secti<strong>on</strong>s describe how each command is used in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> andhow the command can be c<strong>on</strong>verted in<strong>to</strong> <strong>SQL</strong> <strong>Server</strong>-specific syntax.InsertThe INSERT command is used <strong>to</strong> add <strong>on</strong>e or more rows <strong>to</strong> a table. The column valuesare separated by commas. Insert can be used in several different ways within <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. Allof the different <str<strong>on</strong>g>for</str<strong>on</strong>g>ms are explained under the following headings.Inse rting a row in<strong>to</strong> a table is identical in <strong>SQL</strong> <strong>Server</strong> and in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The syntax is shownhere:INSERT INTO TABLE1 VALUES (FIELD1, FIELD2 …);Insert SequencesCompatibility between the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tables and the new <strong>SQL</strong> <strong>Server</strong> tables should bechecked. If a table in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> uses SEQUENCES, then <strong>SQL</strong> <strong>Server</strong> tables should useIDENTITY.IDENTITY will au<strong>to</strong>matically increment a column value so that no two rows will havesame value <str<strong>on</strong>g>for</str<strong>on</strong>g> the column. To enable this facility, a column can be included in the tablewhich will have its unique value and au<strong>to</strong>-incrementing defined. This is achieved throughSEQUENCES in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and IDENTITY in <strong>SQL</strong> <strong>Server</strong>. This column can also be used asprimary key <str<strong>on</strong>g>for</str<strong>on</strong>g> tables that do not have a natural key.A sequence is a database object that can generate unique, sequential integer values. Itcan be used <strong>to</strong> au<strong>to</strong>matically generate primary key or unique key values. A sequence canbe either in ascending or descending order. The syntax is explained in the followingexamples.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>INSERT INTO SUPPLIERS VALUES


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 199●(SUPPLIER_SEQUENCE.NEXTVAL,' Abc Inc.', 'Lingerfelt, Steve', 'Mr.', 'Apt # 104Andrew''s Drive', 'Charlotte', 28262,'USA',7049654371,7049652300);<strong>SQL</strong> <strong>Server</strong><strong>SQL</strong> <strong>Server</strong> has a unique way of handling running serial numbers: the IDENTITYproperty. This property provides a unique incremental value <str<strong>on</strong>g>for</str<strong>on</strong>g> the column. Its usein an insert command is explained later in this secti<strong>on</strong>. This is equivalent <strong>to</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s Sequence. When a column is declared as IDENTITY, a value does nothave <strong>to</strong> be specified <str<strong>on</strong>g>for</str<strong>on</strong>g> the column. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the value has <strong>to</strong> be explicitlyretrieved from a sequence during an insert.The current value of an IDENTITY can be found using the following code:SELECT IDENT_CURRENT ('SUPPLIERS')INSERT INTO SUPPLIERS VALUES(' A bc Inc.', 'Lingerfelt, Steve', 'Mr.', 'Apt # 104 Andrew''s Drive' ,'Charlotte', 28262,'USA','7049654371','7049652300');Using Date Values in Insert Operati<strong>on</strong>sDuring an insert or update, the date <str<strong>on</strong>g>for</str<strong>on</strong>g>mat can be the same as <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> (DD-MON-YYYY).However, while retrieving, the <str<strong>on</strong>g>for</str<strong>on</strong>g>mat will be different. A c<strong>on</strong>versi<strong>on</strong> functi<strong>on</strong> that wasdiscussed in the "Functi<strong>on</strong>s"secti<strong>on</strong> will have <strong>to</strong> be used. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, <strong>to</strong> insert the date with time, a c<strong>on</strong>versi<strong>on</strong> of thedate with date time is needed. This is d<strong>on</strong>e with the help of the TO_CHAR functi<strong>on</strong>. Thisis not required in <strong>SQL</strong> <strong>Server</strong> because it already s<strong>to</strong>res the date with time stamp.The following example illustrates how <strong>to</strong> insert the current date in an insert operati<strong>on</strong> of<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●INSERT INTO OrderMaster VALUES(1,1076,121,SYSDATE,'19-AUG-2004', NULL,'Federal Shipping', 40,'Ernst Handel','2817 Milt<strong>on</strong> Dr.','Dallas','TX','87110')INSERT INTO OrderMaster VALUES(1,1076,121, GETDATE(),'19-AUG-2004', NULL,'Federal Shipping', 40, 'Ernst Handel','2817 Milt<strong>on</strong>Dr.','Dallas','TX','87110')The following example shows how the time part of a date is handled in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and howthis can be c<strong>on</strong>verted <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> database.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●<strong>SQL</strong> <strong>Server</strong>INSERT INTO OrderMaster VALUES(1,1076,121,TO_DATE('01-MAR-2004 13:45:33', 'DD-MON-YYYYHH24:MI:SS'),'19-AUG-2004', NULL, 'Federal Shipping', 40, 'Ernst Handel','2817Milt<strong>on</strong> Dr.',' Dallas','TX','87110')<strong>SQL</strong> <strong>Server</strong>INSERT INTO OrderMaster VALUES(1,1076,121, '01-MAR-2004 13:45:33','19-AUG-2004', NULL, 'Federal Shipping', 40, 'Ernst Handel','2817 Milt<strong>on</strong>Dr.','Dallas','TX' ,'87110')Insert with SubqueryIn many applicati<strong>on</strong>s, a subquery is used <strong>to</strong> return a specific subset of rows whichare then inserted in<strong>to</strong> the table. The subquery can refer <strong>to</strong> any table, view, or


200 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>even the target table itself. If the subquery returns no rows, then no rows areinserted in<strong>to</strong> the table.UpdateUpdate is an imperative DML statement that facilitates the changes <strong>to</strong> values of fields inthe tables. In an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or <strong>SQL</strong> <strong>Server</strong> database, an UPDATE is comm<strong>on</strong>ly used <strong>to</strong>incorporate modificati<strong>on</strong>s <strong>to</strong> an already inserted value. All of the key c<strong>on</strong>straints arehandled by the databases prior <strong>to</strong> affecting the UPDATE permanently. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong> have followed the c<strong>on</strong>venti<strong>on</strong>al ANSI way of using the UPDATE statement.The UPDATE statement can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in three different ways:● Simple update. This is a straight<str<strong>on</strong>g>for</str<strong>on</strong>g>ward change <strong>to</strong> the values of <strong>on</strong>e or morefields of a table, with or without a c<strong>on</strong>diti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> updating.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use the same syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> UPDATE statement.● Update with joins. Updates with joins are frequently used when a change isrequired in the field value of <strong>on</strong>ly the rows matching specific c<strong>on</strong>diti<strong>on</strong>s betweentwo or more tables.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use the same syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> UPDATE statement.● Update with subqueries. Requirements will sometimes demand a change <strong>to</strong> afield value with data from another table. Update with subqueries is useful insituati<strong>on</strong>s where data from <strong>on</strong>e table is set <strong>to</strong> a field from another table.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use the same syntax c<strong>on</strong>venti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> UPDATE withsubqueries. An excepti<strong>on</strong> is updates involving correlated subqueries.UPDATE OrderDetails oSET o.unitprice = (SELECT unitpriceFROM Product pWHERE p.productid = o.productid)The preceding <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> update statement can be rewritten using a syntax that isunique <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> as follows:MergeUPDATE oSET o.unitprice = p.unitpriceFROM OrderDetails o JOIN Product pON p.productid = o.productidThis is a new feature in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 9i. The MERGE statement is used <strong>to</strong> update and insertrows in a table. In the following examples, an ORDERPRICE table exists that s<strong>to</strong>res therevised price of a product in a particular order. The price can be revised any number oftimes. If a record already exists, then the price needs <strong>to</strong> be updated and the datechanged. If a row <str<strong>on</strong>g>for</str<strong>on</strong>g> that order and product does not exist, then you need <strong>to</strong> insert a newrow with the revised price of the product in that particular order.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>MERGE INTO ORDERPRICE AUSING (SELECT ORDERID, PRODUCTID FROM ORDERDETAILS WHERE ORDERID=1AND PRODUCTID =1) BON (A.ORDERID = B.ORDERID AND A.PRODUCTID = B.PRODUCTID)WHEN MATCHED THENUPDATE SET REVISEDPRICE = 120, REVISEDON = SYSDATEWHEN NOT MATCHED THENINSERT INTOORDERPRICE VALUES


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 201●(B.ORDERID, B.PRODUCTID, 100, SYSDATE);<strong>SQL</strong> <strong>Server</strong>To achieve this functi<strong>on</strong>ality in <strong>SQL</strong> <strong>Server</strong>, use a s<strong>to</strong>red procedure with thefollowing logic. More in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about writing s<strong>to</strong>red procedures is included laterin this chap ter in the "Subprograms C<strong>on</strong>versi<strong>on</strong>" secti<strong>on</strong>.declare @orderid char(10)declare @productid char(10)declare @count integerSELECT @count = COUNT(*) FROM ORDERPRICEWHERE ORDERID= @ORDERID AND PRODUCTID = @PRODUCTIDIF @count > 0UPDATE ORDERPRICE SET REVISEDPRICE =120, REVISEDON = GETDATE()WHERE ORDERID = @ORDERID AND PRODUCTID = @PRODUCTIDELSEINSERT INTO ORDERPRICE VALUES(@ORDERID, @PRODUCTID, 100, GETDATE())DeleteAs tables are used, unneeded rows can be removed. DELETE is a DML operati<strong>on</strong> that isused <strong>to</strong> eliminate all or certain rows from a table, keeping the table structure intact. Eventhough all the rows are deleted, the structure of the table remains and can be populatedwith additi<strong>on</strong>al rows using INSERT. By using c<strong>on</strong>diti<strong>on</strong>al deleti<strong>on</strong>, <strong>on</strong>ly selected rows areeliminated from the table. C<strong>on</strong>diti<strong>on</strong>al deleti<strong>on</strong> is accomplished by using the c<strong>on</strong>venti<strong>on</strong>alWHERE clause. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> both allow <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>diti<strong>on</strong>al deleti<strong>on</strong>. The ANSIway of writing the DELETE statement is used in both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.The following types of delete exist:● Simple delete. A general way of deleting all or selected rows from a table. Asimple delete operati<strong>on</strong> is similar <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.● Delete all rows. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer the TRUNCATE TABLEstatement.● Delete with subqueries. Using subqueries in c<strong>on</strong>juncti<strong>on</strong> with the DELETEoperati<strong>on</strong> allows <str<strong>on</strong>g>for</str<strong>on</strong>g> more specificity. The subquery enables the value <str<strong>on</strong>g>for</str<strong>on</strong>g> theWHERE c<strong>on</strong>diti<strong>on</strong> <strong>to</strong> be fetched from a different table.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use the same methodology <strong>to</strong> delete the rows in a table.● Delete duplicate records. It is possible <strong>to</strong> have exact copies of rows in a tablethat does not en<str<strong>on</strong>g>for</str<strong>on</strong>g>ce a strict key structure. These situati<strong>on</strong>s demand the deleti<strong>on</strong>of all the duplicate records from the table. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> have differentways <strong>to</strong> do this:●<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>DELETE FROM TABLE1 WHERE TABLE1.ROWID >(SELECT MIN (TABLE2.ROWID) FROM TABLE2WHERE TABLE1.FIELD1 = TABLE2.FIELD1)● <strong>SQL</strong> <strong>Server</strong>For an example of how <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m this in <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong>http://support.microsoft.com/default.aspx?scid=kb;en-us;139444• TruncateBoth <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer the TRUNCATE command <str<strong>on</strong>g>for</str<strong>on</strong>g> deleting all rowsof a table with minimal logging.


202 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>Step 2: Transacti<strong>on</strong> ManagementAfter identifying all instances of <strong>SQL</strong>, transacti<strong>on</strong>s need <strong>to</strong> be carefully modified as part ofthe data migrati<strong>on</strong> process. This secti<strong>on</strong> discusses how <strong>to</strong> handle the transacti<strong>on</strong>s in<strong>SQL</strong> <strong>Server</strong>.To begin, identify all of the transacti<strong>on</strong> commands currently used with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> andimplement them <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, all commands inside two transacti<strong>on</strong> c<strong>on</strong>trollanguage statements are c<strong>on</strong>sidered as a batch. If a set of statements needs <strong>to</strong> bec<strong>on</strong>sidered as a batch, then all the statements must be inside BEGIN TRANSACTIONand COMMIT TRANSACTION commands. A discussi<strong>on</strong> of these architecture <strong>to</strong>pics isprovided in Appendix A: <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Professi<strong>on</strong>als.Transacti<strong>on</strong> C<strong>on</strong>trol Language (TCL)A tr ansacti<strong>on</strong> can be defined as a group of statements that must either succeed or fail asa group. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, transacti<strong>on</strong>s are normally implicit in nature and can be explicitlyspecified by use of BEGIN and END clauses. In <strong>SQL</strong> <strong>Server</strong>, BEGIN TRAN and ENDTRAN have <strong>to</strong> be explicitly used <strong>to</strong> demarcate a transacti<strong>on</strong>.Transacti<strong>on</strong> is c<strong>on</strong>trolled by any <strong>on</strong>e of these commands:● COMMIT● ROLLBACK● SAVEPOINTThese commands are discussed in detail under the following headings.COMMITThe COMMIT command is used <strong>to</strong> end a transacti<strong>on</strong>. Changes are made permanent inthe database with the COMMIT command. This erases all the savepoints inside thetran sacti<strong>on</strong> and also releases the locks.After a transacti<strong>on</strong> is committed, the change is permanent and cannot be reverted. Ofcourse, you can always delete the inserted row. There is no way <strong>to</strong> undo a committedtransacti<strong>on</strong>.The syntax is as follows:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●COMMIT;<strong>SQL</strong> <strong>Server</strong>COMMIT TRANSACTION ;The COMMIT WORK command functi<strong>on</strong>s in the same way as COMMIT TRANSACTION,except COMMIT TRANSACTION accepts a user-defined transacti<strong>on</strong> name. ThisCOMMIT syntax, with or without specifying the opti<strong>on</strong>al keyword WORK, is compatiblewith <strong>SQL</strong>-92. This command is available in <strong>SQL</strong> <strong>Server</strong> using the following command:COMMIT WORK;SAVEPOINTA savepoint is a marker that divides a very lengthy transacti<strong>on</strong> in<strong>to</strong> several smaller <strong>on</strong>es.SAVEPOINT is used <strong>to</strong> identify a rollback point in the transacti<strong>on</strong>. Thus, SAVEPOINT isused in c<strong>on</strong>juncti<strong>on</strong> with ROLLBACK <strong>to</strong> revert a porti<strong>on</strong> of current transacti<strong>on</strong>. The syntaxin <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> differs:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 203●SAVEPOINT ;<strong>SQL</strong> <strong>Server</strong>SAVE TRANSACTION ;ROLLBACKThe ROLLBACK command is used <strong>to</strong> undo a porti<strong>on</strong> of the current transacti<strong>on</strong>. It ispossible <strong>to</strong> roll back the entire transacti<strong>on</strong> so that all changes made by <strong>SQL</strong> statementsare und<strong>on</strong>e, or <strong>to</strong> roll back a transacti<strong>on</strong> <strong>to</strong> a save point so that the <strong>SQL</strong> statements afterthe save point are rolled back. The syntax in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> differs:●●<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>ROLLBACK;ROLLBACK TO ;<strong>SQL</strong> <strong>Server</strong>ROLLBACK TRANSACTION ROLLBACK TRANSACTION In additi<strong>on</strong>, the ROLLBACK WORK statement functi<strong>on</strong> is similar <strong>to</strong> the ROLLBACK. The<strong>on</strong>ly difference is that ROLLBACK TRANSACTION accepts a user-defined transacti<strong>on</strong>name. With or without specifying the opti<strong>on</strong>al WORK keyword, this ROLLBACK syntax is<strong>SQL</strong>-92-compatible and is available in <strong>SQL</strong> <strong>Server</strong> using the following syntax:ROLLBACK WORKSte p 3: Fetch StrategyCursors are effective <str<strong>on</strong>g>for</str<strong>on</strong>g> row processing and batch processing. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>-based applicati<strong>on</strong>scan use many c ursors <str<strong>on</strong>g>for</str<strong>on</strong>g> row processing. Analyze the code <strong>to</strong> determine if it can bec<strong>on</strong>verted without using cursors. Cursor operati<strong>on</strong>s are always costly when compared <strong>to</strong>SET operati<strong>on</strong>s because they use temporary memory area and processes. If the cursorsare not handled properly, it may result in dead processes and locks.In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, a cursor is defined as a work area <strong>to</strong> execute the <strong>SQL</strong> statements and <strong>to</strong> s<strong>to</strong>reprocessing in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> creates a work area <strong>to</strong> process all the <strong>SQL</strong> statements.That work area is called an implicit cursor. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> also allows you <strong>to</strong> define an explicitcursor <strong>to</strong> process and apply business logic.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has implemented the following types of cursors:● Implicit cursors● Explicit cursorsImplicit cursors are opened au<strong>to</strong>matically whenever queries or DML are issued in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.<strong>SQL</strong> <strong>Server</strong> calls this a default result set.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> allows defining a cursor with the help of keyword "cursor." Such explicitly declaredcurs ors have a SELECT statement. The output of the select is s<strong>to</strong>red in separate memoryareas and it can be used in a PL/<strong>SQL</strong> program. Explicit cursors can be parameterized.Transact <strong>SQL</strong> Cursors, in <strong>SQL</strong> <strong>Server</strong>, are based <strong>on</strong> the DECLARE CURSOR syntax andare used mainly in Transact-<strong>SQL</strong> scripts, s<strong>to</strong>red procedures, and triggers. Transact-<strong>SQL</strong>cursors are implemented <strong>on</strong> the server and are managed by Transact-<strong>SQL</strong> statementssent from the client <strong>to</strong> the server.Using Transact-<strong>SQL</strong> CursorsHigh-level steps <str<strong>on</strong>g>for</str<strong>on</strong>g> using Transact-<strong>SQL</strong> cursors inside the code include:


204 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>1. Declare Transact-<strong>SQL</strong> variables <strong>to</strong> c<strong>on</strong>tain the data returned by the cursor. Declare<strong>on</strong>e variable <str<strong>on</strong>g>for</str<strong>on</strong>g> each result set column. Declare the variables <strong>to</strong> be large enough<strong>to</strong> hold the values returned by the column.2. Associate a Transact-<strong>SQL</strong> cursor with a SELECT statement using the DECLARECURSOR statement. The DECLARE CURSOR statement also defines thecharacteristics of the cursor, such as the cursor name and whether the cursor isread-<strong>on</strong>ly or <str<strong>on</strong>g>for</str<strong>on</strong>g>ward-<strong>on</strong>ly.3. Use the OPEN statement <strong>to</strong> execute the SELECT statement and populate thecursor.4. Use the FETCH INTO statement <strong>to</strong> fetch individual rows and have the data <str<strong>on</strong>g>for</str<strong>on</strong>g>each column moved in<strong>to</strong> a specified variable. Other Transact-<strong>SQL</strong> statements canthen reference those variables <strong>to</strong> access the fetched data values. Transact-<strong>SQL</strong>cursors do not support fetching blocks of rows.5. When you are finished with the cursor, use the CLOSE statement. Closing a cursorfrees some resources, such as the cursor's result set and its locks <strong>on</strong> the currentrow, but the cursor structure is still available <str<strong>on</strong>g>for</str<strong>on</strong>g> processing if you reissue an OPENstatement. Because the cursor is still present, you cannot reuse the cursor name atthis point. The DEALLOCATE statement completely frees all resources allocated <strong>to</strong>the cursor, including the cursor name. After a cursor is de-allocated, you mustissue a DECLARE statement <strong>to</strong> rebuild the cursor.Th e cursor syntax differs between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●DECLARECURSOR IS < SELECT STATEMENT>BEGINFOR IN CURSOR_NAMELOOP-- Business LogicEND LOOP;END;<strong>SQL</strong> <strong>Server</strong>DECLARE DECLARE CURSOR FOR BEGINOPEN FETCH NEXT FROM INTO WHILE @@FETCH_STATUS = 0BEGIN-- business logic goes hereFETCH NEXT FROM INTO ENDCLOSE DEALLOCATE END<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> allows the entire cursor record <strong>to</strong> be transferred in<strong>to</strong> a user-defined data structuredefined using ROWTYPE. In <strong>SQL</strong> <strong>Server</strong>, the record values need <strong>to</strong> be assigned in<strong>to</strong> anindividual variable. The following example uses ROWTYPE <strong>to</strong> process the SHIPPERStable record byrecord.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 205●●<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>DECLARECURSOR SHIPPER_CURSOR IS SELECT * FROM SHIPPERS;SHIPPER_REC SHIPPERS%ROWTYPE;BEGINOPEN SHIPPER_CURSOR;LOOPFETCH SHIPPER_CURSOR INTO SHIPPER_REC;EXIT WHEN SHIPPER_CURSOR%NOTFOUND;DBMS_OUTPUT.PUT_LINE('SHIPPER NAME IS '||SHIPPER_REC.COMPANYNAME);DBMS_OUTPUT.PUT_LINE('SHIPPER PHONE IS '||SHIPPER_REC. PHONE);END LOOP;CLOSE SHIPPER_CURSOR;END;<strong>SQL</strong> <strong>Server</strong>DECLARE @SHIPPER_NAME VARCHAR(50),@PHONE VARCHAR(50)DECLARE SHIPPER_CURSOR CURSOR FOR SELECT COMPANYNAME,PHONE FROM SHIPPERS;BEGINOPEN SHIPPER_CURSOR;FETCH NEXT FROM SHIPPER_CURSOR INTO @SHIPPER_NAME, @PHONEWHILE @@FETCH_STATUS = 0BEGINPRINT 'SHIPPER NAME IS ' + @SHIPPERNAMEPRINT 'SHIPPER PHONE IS ' + @PHONEFETCH NEXT FROM SHIPPER_CURSOR INTO @SHIPPER_NAME, @PHONEENDCLOSE SHIPPER_CURSORDEALLOCATE SHIPPER_ CURSORENDTransact <strong>SQL</strong> Extensi<strong>on</strong>s<strong>SQL</strong> <strong>Server</strong> extends the following functi<strong>on</strong>ality with cursors. Some of the key featuresinclude:●●●●●●FETCH FIRSTFetches the first row in the cursor.FETCH NEXTFetches the row after the last row fetched.FETCH PRIORFetches the row be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the last row fetched.FETCH LASTFetches the last row in the cursor.FETCH ABSOLUTE nFetches the nth row from the first row in the cursor if n is a positive integer. If n is anegative integer, the row n rows be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the end of the cursor is fetched. If n is 0, norows are fetched.FETCH RELATIVE nFetches the nth row from the current positi<strong>on</strong> of the cursor. If n is positive, the nthrow afterthe last row fetched is fetched. If n is negative, the nth row be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the last


206 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>row fetched is fetched. If n is 0, the same row is fetched again. It also allowsretrieving <strong>on</strong>e row or block of rows from the current positi<strong>on</strong> in the result set.It supports data modificati<strong>on</strong>s <strong>to</strong> the rows at the current positi<strong>on</strong> in the result set.Step 4: Subprograms C<strong>on</strong>versi<strong>on</strong>The next step is <strong>to</strong> migrate the procedures, functi<strong>on</strong>s, and triggers. This secti<strong>on</strong>discusses how each comp<strong>on</strong>ent can be c<strong>on</strong>verted <str<strong>on</strong>g>for</str<strong>on</strong>g> use with <strong>SQL</strong> <strong>Server</strong>.<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> ProceduresA s<strong>to</strong>red procedure is a precompiled object. This means that a procedure is compiledbe<str<strong>on</strong>g>for</str<strong>on</strong>g>ehand and is readily available <str<strong>on</strong>g>for</str<strong>on</strong>g> the various applicati<strong>on</strong>s <strong>to</strong> execute. As a result,time is not wasted parsing and compiling the procedure again. However, the procedurewill be compiled every time if it c<strong>on</strong>tains dynamic <strong>SQL</strong>. S<strong>to</strong>red procedures in <strong>SQL</strong> <strong>Server</strong>are very similar <strong>to</strong> procedures in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> PL/<strong>SQL</strong>. Some similarities include:● Both can accept parameters and return multiple values in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m of outputparameters (OUT parameter) <strong>to</strong> the calling procedure.● Both c<strong>on</strong>tain programming statements that per<str<strong>on</strong>g>for</str<strong>on</strong>g>m operati<strong>on</strong>s in the database,including calling other procedures.● Both can overwrite existing procedures. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> uses the keyword REPLACE, while<strong>SQL</strong> <strong>Server</strong> uses ALTER.The syntax between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> procedures differs. The differences areshown in the following examples:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●CREATE OR REPLACE PROCEDURE (PARAMETER1 DATATYPE [IN OUT],PARAMETER2 DATATYPE [IN OUT],)ISVARIABLE1 DATATYPE;VARIABLE2 DATATYPE;BEGINEXECUTABLE STATEMENTS;EXCEPTIONEXECUTABLE STATEMENTS;END;<strong>SQL</strong> <strong>Server</strong>CREATE PROCEDURE [ ; number ][ { @PARAMETER DATATYPE }[ VARYING ] [ = default ] [ OUTPUT ]] [ ,...n ] ASEXECUTABLE STATEMENTSIn the following example, a s<strong>to</strong>red procedure calculates the number of m<strong>on</strong>ths remaininguntil retirement <str<strong>on</strong>g>for</str<strong>on</strong>g> each employee. Retirement age is passed as a parameter <strong>to</strong> theprocedure. The output needs <strong>to</strong> be written in<strong>to</strong> a table named RETIRE. The RETIREtable has two columns. The columns are EMPLOYEEID and MONTHS_REMAINING.The number of m<strong>on</strong>ths remaining is calculated and inserted in<strong>to</strong> this table. Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e startingthe operati<strong>on</strong>, the table needs <strong>to</strong> be flushed.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 207CREATE OR REPLACE PROCEDURE CALCULATE_RETIRE_MONTHS(RETIRE_AGE NUMBER) ISCURRENT_AGE NUMBER;MONTHS_REMAINING NUMBER;CURSOR EMP_CURSOR IS SELECT EMPLOYEEID, BIRTHDATE FROM EMPLOYEE;BEGINEXECUTE IMMEDIATE 'TRUNCATE TABLE RETIRE';FOR CUR_VAL IN EMP_CURSORLOOPCURRENT_AGE := ROUND(ROUND(SYSDATE - CUR_VAL.BIRTHDATE)/30)MONTHS_REMAINING := (RETIRE_AGE * 12) - CURRENT_AGE;INSERT INTO RETIRE VALUES(CUR_VAL.EMPLOYEE_ID,MONTHS_REMAINING);END LOOP;COMMIT;END;● <strong>SQL</strong> S erverIF EXISTS (SELECT NAME FROM SYSOBJECTSWHERE NAME = 'CALCULATE_RETIRE_YRS' AND TYPE = 'P')DROP PROCEDURE CALCULATE_RETIRE_YRSGOCREATE PROCEDURE CALCULATE_RETIRE_YRS @RETIRE_AGE INTEGER ASDECLARE @CUR_AGE INTEGER,@MONTHS_REMAINING INTEGERDECLARE @V_DOB DATETIME,@V_EMPLOYEEID VARCHAR(30)DECLARE EMP_CURSOR CURSOR FORSELECT EMPLOYEEID,BIRTHDATE FROM EMPLOYEEBEGINTRUNCATE TABLE RETIRE;OPEN EMP_CURSORFETCH NEXT FROM EMP_CURSOR INTO @V_EMPLOYEEID,@V_DOBIF @@FETCH_STATUS 0BEGINPRINT 'NO EMP'ENDELSEBEGINWHILE (@@FETCH_STATUS = 0)BEGINSET @CUR_AGE = ( SELECT DATEDIFF(MONTH,@V_DOB,GETDATE()) )SET @MONTHS_REMAINING = (SELECT (@RETIRE_AGE * 12) -@CUR_AGE)INSERT INTO RETIRE VALUES(@V_EMPLOYEEID,@MONTHS_REMAINING)FETCH NEXT FROM EMP_CURSOR INTO @V_EMPLOYEEID,@V_DOBENDENDCLOSE EMP_CURSORDEALLOCATE EMP_CURSOREND


208 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>Functi<strong>on</strong>sWhile si milar <strong>to</strong> procedures, functi<strong>on</strong>s return a value. There may be some mathematicalcalculati<strong>on</strong> needed <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong> that is readily available in the database server. Ifyou need the result of a complex algorithm as part of a <strong>SQL</strong> statement, you need <strong>to</strong> writea functio n that per<str<strong>on</strong>g>for</str<strong>on</strong>g>ms the required calculati<strong>on</strong> and returns a value.The syntax between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> functi<strong>on</strong>s differs, as shown in the followingexamples:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●CREATE OR REPLACE FUNCTION (PARAMETER DATATYPE,PARAMETER DATATYPE ETC ..) RETURN DATATYPEISBEGINRETURN EXCEPTION;END;<strong>SQL</strong> <strong>Server</strong>CREATE FUNCTION @PARAMETER DATATYPE,@PARAMETER DATATYPE ETC ..RETURNS ASBEGINRETURN ENDThe difference between built-in functi<strong>on</strong>s in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> are discussed here.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> also has a functi<strong>on</strong> called NEXT_DAY that returns the date of the first weekdaynamed by char that is later than the current date. The char argument must be a day ofthe week in the date language of the sessi<strong>on</strong>, either the full name or the abbreviati<strong>on</strong>.The minimum number of letters required is the number of letters in the abbreviatedversi<strong>on</strong>. Any characters immediately following the valid abbreviati<strong>on</strong> are ignored and thereturn value has the same hours, minutes, and sec<strong>on</strong>ds comp<strong>on</strong>ent as the argumentdate.By default, this functi<strong>on</strong> is not available in <strong>SQL</strong> <strong>Server</strong>. But the following example shows<strong>on</strong>e way <strong>to</strong> provide this functi<strong>on</strong> in <strong>SQL</strong> <strong>Server</strong>, and it can be expanded <strong>to</strong> meet yourneeds:CREATE FUNCTION NEXT_DAY(@D DATETIME,@DAY VARCHAR(10)) RETURNS DATETIME ASBEGINDECLARE @DAY_NUMBER INTEGERDECLARE @NEWDATE DATETIMEIF UPPER(@DAY)='SUNDAY'BEGINIF ( 1 - DATEPART(DW,@D))=0SET @NEWDATE = @D + 7ELSE IF ( 1 - DATEPART(DW,@D)) < 0SET @NEWDATE = @D + 1 + ( 7 - DATEPART(DW,@D))ELSE


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 209ENDSET @NEWDATE = @ D + 1 - DATEPART(DW,@D)ELSE IF UPPER(@DAY)='MONDAY' OR UPPER(@DAY)= ‘MON’BEGINIF ( 2 - DATEPART(DW,@D)) = 0SET @NEWDATE = @D + 7ELSE IF ( 2 - DATEPART(DW,@D))< 0SET @NEWDATE = @D + 2 + ( 7 - DATEPART(DW,@D))ELSESET @NEWDATE = @D + 2 - DATEPART(DW,@D)ENDELSE IF UPPER(@DAY)='TUESDAY' OR UPPER(@DAY)= ‘TUE’BEGINIF ( 3 - DATEPART(DW,@D)) = 0SET @NEWDATE = @D + 7ELSE IF ( 3 - DATEPART(DW,@D))< 0SET @NEWDATE = @D + 3 + ( 7 - DATEPART(DW,@D))ELSESET @NEWDATE = @D + 3 - DATEPART(DW,@D)ENDELSE IF UPPER(@DAY)='WEDNESDAY' OR UPPER(@DAY)= ‘WED’BEGINIF ( 4 - DATEPART(DW,@D)) = 0SET @NEWDATE = @D + 7ELSE IF ( 4 - DATEPART(DW,@D))< 0SET @NEWDATE = @D + 4 + ( 7 - DATEPART(DW,@D))ELSESET @NEWDATE = @D + 4 - DATEPART(DW,@D)ENDELSE IF UPPER(@DAY)='THURSDAY' OR UPPER(@DAY)= ‘THU’BEGINIF ( 5 - DATEPART(DW,@D)) = 0SET @NEWDATE = @D + 7ELSE IF ( 5 - DATEPART(DW, @D))< 0SET @NEWDATE = @D + 5 + ( 7 - DATEPART(DW,@D))ELSESET @NEWDATE = @D + 5 - DATEPART(DW,@D)ENDELSE IF UPPER(@DAY)='FRIDAY' OR UPPER(@DAY)= ‘FRI’BEGINIF ( 6 - DATEPART(DW,@D)) = 0SET @NEWDATE = @D + 7ELSE IF ( 6 - DATEPART(DW,@D))< 0SET @NEWDATE = @D + 6 + ( 7 - DATEPART(DW,@D))ELSESET @NEWDATE = @D + 6 - DATEPART(DW,@D)ENDELSE IF UPPER(@DAY)='SATURDAY' OR UPPER(@DAY)= ‘SAT’BEGINIF ( 7 - DATEPART(DW,@D)) = 0


210 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>SET @NEWDATE = @D + 7ELSE IF ( 7 - DATEPART(DW,@D))< 0SET @NEWDATE = @D + 7 + ( 7 - DATEPART(DW,@D))ELSESET @NEWDATE = @D + 7 - DATEPART(DW,@D)ENDELSESET @NEWDATE = NULLRETURN @NEWDATEENDTriggers<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> provide two primary mechanisms <str<strong>on</strong>g>for</str<strong>on</strong>g> en<str<strong>on</strong>g>for</str<strong>on</strong>g>cing business rulesand data integrity through c<strong>on</strong>straints and triggers. A trigger is a special type of s<strong>to</strong>redprocedure that au<strong>to</strong>matically takes effect when an event occurs. The event can beINSERT, UPDATE, or DELETE. The trigger and the statement that triggers are treated asa single transacti<strong>on</strong>, which can be rolled back from within the trigger. If an error isdetected, the entire transacti<strong>on</strong> is au<strong>to</strong>matically rolled back.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> uses two types of triggers <strong>on</strong> tables: table-level triggers and row-level triggers. Ifthe key word FOR EACH ROW is specified, then it is a row-level trigger. Row-leveltriggers are fired <str<strong>on</strong>g>for</str<strong>on</strong>g> each row when it is affected. For example, if an update statementchanges 5 rows, then the trigger will be fired 5 times. Table-level triggers are <strong>on</strong>ly fired<strong>on</strong>ce. In a table-level trigger, individual values cannot be captured. Row-level triggerscapture the individual rows with the help of the keywords :NEW and :OLD. Unlike <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>,<strong>SQL</strong> <strong>Server</strong> does not have two types of triggers. The individual values can be capturedfrom a special table called INSERTED. Old values can be fetched from the DELETEDtable and the new changed values can be retrieved from the INSERTED table.The deleted values can be referred with the special variable :OLD in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. <strong>SQL</strong> <strong>Server</strong>has a special table called DELETED. The DELETED table s<strong>to</strong>res copies of the affectedrows during DELETE and UPDATE statements. During the executi<strong>on</strong> of a DELETE orUPDATE statement, rows are deleted from the trigger table and transferred <strong>to</strong> theDELETED table. The DELETED and INSERTED tables in <strong>SQL</strong> <strong>Server</strong> are <strong>on</strong>lyc<strong>on</strong>ceptual; they do not physically exist.A mapping of the functi<strong>on</strong>ality of triggers in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> as well as acomparis<strong>on</strong> of the syntax is available under the <strong>to</strong>pic "Triggers" in Chapter 6:"Developing: Databases — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Schemas."The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> the triggers differs as follows:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> triggersSeparate syntax is used <str<strong>on</strong>g>for</str<strong>on</strong>g> each trigger command:● INSERT trigger syntaxCREATE OR REPLACE TRIGGER [ BEFORE | AFTER ] INSERT ON [ FOR EACH ROW ]DECLAREBEGINEXCEPTIONEND;


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 211●UPDATE trigger syntaxCREATE OR REPLACE TRIGGER [ BEFORE | AFTER ] UPDATE OF ON [ FOR EACH ROW ]DECLAREBEGINEXCEPTION●END;DELETE trigger syntaxCREATE OR REPLACE TRIGGER [ BEFORE | AFTER ] DELETE ON [ FOR EACH ROW ]DECLAREBEGINEXCEPTIONEND;●<strong>SQL</strong> <strong>Server</strong>Unlike <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, <strong>on</strong>ly <strong>on</strong>e syntax is needed <str<strong>on</strong>g>for</str<strong>on</strong>g> trigger functi<strong>on</strong>s in <strong>SQL</strong> <strong>Server</strong>:CREATE TRIGGER ON {FOR|AFTER|INSTEAD OF}{[INSERT][,][UPDATE][,][DELETE]}AS[{IF UPDATE(column)[{AND|OR}UPDATE(column)]}]EXECUTABLE STATEMENTSThe following example further illustrates the use of trigger functi<strong>on</strong>s. In this example, thePRODUCT tables need <strong>to</strong> be updated when an order is issued against any product. Thefollowing code uses an INSERT trigger <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m this task.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●CREATE TRIGGER UPDATE_STOCKAFTER INSERT ON ORDERDETAILSFOR EACH ROWBEGINUPDATE PRODUCT SET UNITINSTOCK = UNITINSTOCK - :NEW.QUANTITYWHERE PRODUCTID = :NEW.PRODUCTID;EXCEPTIONWHEN OTHERS THENNULL;END;<strong>SQL</strong> <strong>Server</strong>CREATE TRIGGER UPDATE_STOCK ON ORDERDETAILSAFTER INSERT ASBEGINUPDATE PRODUCT SET UNITINSTOCK = UNITINSTOCK – QUANTITY


212 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>FROM INSERTED WHERE PRODUCT.PRODUCTID = INSERTED.PRODUCTIDENDINSTEAD OF TriggersIn gene ral, complex views are not updateable. Complex views are defined as normalviews that include more than <strong>on</strong>e table or have GROUP BY expressi<strong>on</strong>s. Complex viewscan b e updated using INSTEAD OF triggers. Both <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> have theopti<strong>on</strong> of INSTEAD OF triggers. The INSTEAD OF trigger is generally defined <strong>on</strong> theview instead of <strong>on</strong> a table. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, INSTEAD OF triggers can be applied <strong>on</strong>ly <strong>to</strong> theview and not <strong>to</strong> tables. In <strong>SQL</strong> <strong>Server</strong>, INSTEAD OF triggers can be applied <strong>to</strong> views andtables. When an insert, update or delete statement is executed against the table, theINSTEAD OF trigger is executed in place of the triggering statement.Also, INSTEAD OF triggers are executed instead of the triggering acti<strong>on</strong>. These triggersare executed after the inserted and deleted tables are created, but be<str<strong>on</strong>g>for</str<strong>on</strong>g>e any otheracti<strong>on</strong>s are taken. They are executed be<str<strong>on</strong>g>for</str<strong>on</strong>g>e any c<strong>on</strong>straints, so they can per<str<strong>on</strong>g>for</str<strong>on</strong>g>mpreprocessing that supplements the c<strong>on</strong>straint acti<strong>on</strong>.The triggering mechanism <strong>on</strong> INSTEAD OF triggers is implemented such that the triggeris not called recursively. The statement is processed as if there is no INSTEAD OFtrigger defined <str<strong>on</strong>g>for</str<strong>on</strong>g> the table.If an UPDATE statement is executed <strong>on</strong> a view that has an INSTEAD OF trigger, thetrigger will be called, but it is not executed recursively. The UPDATE statement isresolved against the base tables underlying the view. In this case, the view definiti<strong>on</strong>must meet all of the restricti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> an updateable view. The UPDATE executed by thetrigger is processed against the view as if the view did not have an INSTEAD OF trigger.The columns changed by the UPDATE must be resolved <strong>to</strong> a single base table. Eachmodificati<strong>on</strong> <strong>to</strong> underlying base tables starts the chain of applying c<strong>on</strong>straints and firingAFTER triggers defined <str<strong>on</strong>g>for</str<strong>on</strong>g> the table.<strong>SQL</strong> <strong>Server</strong> provides most of the functi<strong>on</strong>ality present in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> with respect <strong>to</strong> triggerswith very little differences in their implementati<strong>on</strong>. <strong>SQL</strong> <strong>Server</strong>, however, does not havethe BEFORE triggers and can be programmed using the INSTEAD OF triggers <strong>on</strong> tables.In <strong>SQL</strong> <strong>Server</strong> triggers <strong>on</strong> views have the same kind of features as seen <strong>on</strong> triggers <strong>on</strong>tables as shown by the following syntax:CREATE TRIGGER ON {FOR|AFTER|INSTEAD OF}{[INSERT][,][UPDATE][,][DELETE]}ASBEGIN[{IF UPDATE(column)[{AND|OR}UPDATE(column)]EXECUTABLE STATEMENTSENDAn example of the use of INSTEAD OF triggers <strong>on</strong> view is given in:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vdbt7/html/dvc<strong>on</strong>usinginsteadoftriggers<strong>on</strong>views.asp.Error HandlingRun-time errors in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s PL/<strong>SQL</strong> programs are d<strong>on</strong>e through excepti<strong>on</strong>s andexcepti<strong>on</strong> handlers. Excepti<strong>on</strong>s are raised when errors occur. Although there are predefinedsystem errors, users can also define their own errors in the declarati<strong>on</strong> secti<strong>on</strong>using the syntax:excepti<strong>on</strong>_nameEXCEPTION;


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 213The user-defined excepti<strong>on</strong>s can be triggered using the syntax:RAISE excepti<strong>on</strong>_name;Each BEGIN … END block has an associatedend whose syntax is as follows.EXCEPTION WHEN excepti<strong>on</strong>_name THEN… statements …END;excepti<strong>on</strong> handler secti<strong>on</strong> defined at theAlthough these excepti<strong>on</strong> handler secti<strong>on</strong>s are absent in <strong>SQL</strong> <strong>Server</strong> at the block level,error handling is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med through the use of the global variable @@Error, which ispassed <strong>to</strong> the calling program and can be handled there. <strong>SQL</strong> <strong>Server</strong> sets the value ofthe @@Error variable after each T<strong>SQL</strong> statement. For example:,INSERT ….IF @@Error 0BEGINENDSELECT 'Unexpected error occurred: Insert failed', @@ErrorReturn @@Error<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has many predefined excepti<strong>on</strong>s, such as NO_DATA_FOUND,TOO_MANY_ROWS, ZERO_DIVIDE, INVALID_CURSOR, etc. The predefined excepti<strong>on</strong>OTHERS is of special interest because it can be used as a catch-all excepti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> anyexcepti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> which there is no definiti<strong>on</strong> in the excepti<strong>on</strong> secti<strong>on</strong>.<strong>SQL</strong> <strong>Server</strong> error messages can be viewed by selecting sysmessages system table.Each <strong>SQL</strong> <strong>Server</strong> internal error is qualified in<strong>to</strong> various severity levels. The severity oferrors ranges from 1 <strong>to</strong> 25. Errors with severity 19 and above are c<strong>on</strong>sidered critical andmay result in complete aborti<strong>on</strong> of the batch. In such cases, @@ Error may not capturetheerror raised.Similar in functi<strong>on</strong>ality <strong>to</strong> user-defined excepti<strong>on</strong>s and theRAISE_APPLICATON_ERROR functi<strong>on</strong> in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, <strong>SQL</strong> <strong>Server</strong> provides ways <strong>to</strong> createcus<strong>to</strong>mized error messages that can be raised within T<strong>SQL</strong> code. These are called user-defined errors and can be raised using RAISERROR statement. If you are referencing anerror number in the RAISERROR functi<strong>on</strong> in T<strong>SQL</strong>, you must create the user-definedmessage. You can also dynamically specify a text message in the RAISERROR functi<strong>on</strong>.This is d<strong>on</strong>e by using sp_addmessage system s<strong>to</strong>red procedure. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong><strong>on</strong> how<strong>to</strong> create and raise user-defined errors, seehttp:/ /msdn.microsoft.com/library/defa ult.asp?url= /library/enus/acdata/ac_8_c<strong>on</strong>_05_3f76.asp.Step 5: Job Scheduling<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> uses applicati<strong>on</strong> code and OS utilities <strong>to</strong> schedule a job. <strong>SQL</strong> <strong>Server</strong> uses<strong>SQL</strong> <strong>Server</strong> agent <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m these jobs. The in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in this secti<strong>on</strong> describescreating a job and scheduling it in <strong>SQL</strong> <strong>Server</strong>.Scheduling Functi<strong>on</strong>s and JobsSome frequently used scheduling functi<strong>on</strong>s that are packaged with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> are discussedin this secti<strong>on</strong>. They include:● DBMS_JOB. This is an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> supplied package <str<strong>on</strong>g>for</str<strong>on</strong>g> scheduling jobs. Severaldifferent procedures are packed inside this package.Included are:


214 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>●●●●DBMS_JOB.INSTANCE. This procedure is used <strong>to</strong> assign a particular instance<strong>to</strong> execute a jobDBMS_JOB.CHANGE. This is used <strong>to</strong> alter the schedule of a job.DBMS_JOB.SUBMIT. After the creati<strong>on</strong> of job, this procedure submits a job <strong>to</strong>the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> instance.DBMS_JOB.RUN. Jobs can be executed <strong>on</strong> demand using this procedure.●cr<strong>on</strong>: cr<strong>on</strong> is a daem<strong>on</strong>, which means that it <strong>on</strong>ly needs <strong>to</strong> be started <strong>on</strong>ce, andwill lay dormant until it is required. Generally, a <strong>SQL</strong> file is written that calls aparticular procedure. This <strong>SQL</strong> file is called from a shell script and this script isscheduled using cr<strong>on</strong>. This is how a job is scheduled in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> running <strong>on</strong> <strong>UNIX</strong>.In <strong>SQL</strong> <strong>Server</strong>, jobs can be executed in the following ways:● Using the Enterprise Manager● Using the s<strong>to</strong>red procedures SP_ADD_JOB and SP_ADD_JOBSCHEDULEUsing <strong>SQL</strong> <strong>Server</strong> Enterprise Manager A job can be scheduled by using the following steps.To execute a job in the background <strong>on</strong> scheduled basis, <strong>SQL</strong> <strong>Server</strong> agent must be running.1. Log in <strong>to</strong> Enterprise Manager.2. Expand the server group and then expand the server. Expand Management.Expand <strong>SQL</strong> <strong>Server</strong> Agent and select the Jobs node.3. Create a new job by right-clicking Jobs.4. Enter a name <str<strong>on</strong>g>for</str<strong>on</strong>g> the job in the Name field.5. Check the Enabled check box <strong>to</strong> make the job available <str<strong>on</strong>g>for</str<strong>on</strong>g> executi<strong>on</strong> eitherimmediately or by scheduling it. A disabled job runs <strong>on</strong>ly if a user explicitlyexecutes it..6. In the Owner list, select a user <strong>to</strong> be the owner of the job.7. Write the descripti<strong>on</strong> about the job in Descripti<strong>on</strong> text area.8. Select the Steps tab. A job step is an acti<strong>on</strong> that the job takes <strong>on</strong> a database or aserver. Every job must have at least <strong>on</strong>e job step. Job steps can be operatingsystem commands, Transact-<strong>SQL</strong> statements, or ActiveX Scripts.9. Click New <strong>to</strong> get the job step dialog box. Enter a job step name in the Job stepname box. Select the type in the Type list, For example, you can click Operatingsystem command (CmdExec).10. Enter a value from 0 <strong>to</strong> 999999 in the Process exit code dialog box.11. Enter the operating system command or executable program in the command box.If you select Transact-<strong>SQL</strong> statements or ActiveX scripts, you need <strong>to</strong> specify thecommands as per the selecti<strong>on</strong>.12. In the Schedules tab, the schedule can be specified. Jobs can be scheduled <strong>to</strong> runweekly, daily, or recursive.13. In the Notificati<strong>on</strong>s tab, you can specify an e-mail address <strong>to</strong> send a notificati<strong>on</strong> ifa job fails or succeeds. Messages can also be sent <strong>to</strong> a pager.Using SP_ADD_JOBJobs in <strong>SQL</strong> <strong>Server</strong> can also be scheduled using the s<strong>to</strong>red procedure SP_ADD_JOB.This simply adds a job in <strong>SQL</strong> Agent service. Job steps and scheduling can be d<strong>on</strong>e <strong>on</strong>lywith other procedures. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> use and descripti<strong>on</strong>s are provided in the followingexample:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 215SP_ADD_JOB [ @JOB_NAME = ] 'JOB_NAME'[ , [ @ENABLED = ] ENABLED ][ , [ @DESCRIPTION = ] 'DESCRIPTION' ][ , [ @OWNER_LOGIN_NAME = ] 'LOGIN' ][ , [ @NOTIFY_LEVEL_EVENTLOG = ] EVENTLOG_LEVEL ][ , [ @NOTIFY_LEVEL_EMAIL = ] EMAIL_LEVEL ][ , [ @NOTIFY_LEVEL_NETSEND = ] NETSEND_LEVEL ][ , [ @NOTIFY_LEVEL_PAGE = ] PAGE_LEVEL ][ , [ @NOTIFY_EMAIL_OPERATOR_NAME = ] 'EMAIL_NAME' ][ , [ @NOTIFY_NETSEND_ OPERATOR_NAME = ] 'NETSEND_NAME' ][ , [ @NOTIFY_PAGE_OPERATOR_NAME = ] 'PAGE_NAME' ][ , [ @DELETE_LEVEL = ] DELETE_LEVEL ][ @JOB_NAME = ] 'JOB_NAME'@JOB_ NAME is the name of the job. The name must be unique and cannot c<strong>on</strong>tain thepercent (%) character. The comm<strong>on</strong>ly used parameters include:● [ @ENABLED = ] ENABLED@ENABLED indicates the status of the added job. ENABLED has a default of 1(enabled). If 0, the job is not enabled and does not run according <strong>to</strong> its schedule,but it can be run manually.● [ @DESCRIPTION = ] 'DESCRIPTION'@DESCRI PTION is the descripti<strong>on</strong> of the job. This descripti<strong>on</strong> can be a maximumof 512 characters.● [ @OWNER_LOGIN_NAME = ] 'LOGIN'@OWNER_LOGIN_NAME is the name of the login that owns the job.● [ @ NOTIFY_LEVEL_EVENTLOG = ] EVENTLOG_LEVEL@NOTIFY_LEVEL_EVENTLOG is a value indicating when <strong>to</strong> place an entry in theWindows® applicati<strong>on</strong> log (Event viewer) <str<strong>on</strong>g>for</str<strong>on</strong>g> this job. The value can c<strong>on</strong>tain <strong>on</strong>e ofthe values described in Table 11.18:Table 11.18: Values <str<strong>on</strong>g>for</str<strong>on</strong>g> EVENTLOG_LEVEL <str<strong>on</strong>g>for</str<strong>on</strong>g> SP_ADD_JOBValueDescripti<strong>on</strong>0 Never1 On success2 (default) On failure3 Always●●●●[ @NOTIFY_LEVEL_EMAIL = ] EMAIL_LEVELThe value indicates when <strong>to</strong> send e-mail up<strong>on</strong> the completi<strong>on</strong> of this job. This usesthe same values as listed in Table 11.18.[ @NOTIFY_LEVEL_NETSEND = ] NETSEND_LEVELThe value indicates when <strong>to</strong> send a network message up<strong>on</strong> the completi<strong>on</strong> of thisjob. This uses the same values as listed in Table 11.18.[ @NOTIFY_LEVEL_PAGE = ] PAGE_LEVELThe value indicates when <strong>to</strong> send a page up<strong>on</strong> the completi<strong>on</strong> of this job. Thisuses the same values as listed in Table 11.18.[ @NOTIFY_EMAIL_OPERATOR_NAME = ] 'EMAIL_NAME'


216 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>●●●This is the e-mail address of the pers<strong>on</strong> <strong>to</strong> send e-mail <strong>to</strong> when EMAIL_LEVEL isreached.[ @NOTIFY_NETSEND_OPERATOR_NAME = ] 'NETSEND_NAME'Name of the opera<strong>to</strong>r <strong>to</strong> whom the network message is sent up<strong>on</strong> completi<strong>on</strong> ofthis job.[ @NOTIFY_PAGE_OPERATOR_NAME = ] 'PAGE_NAME'Name of the pers<strong>on</strong> <strong>to</strong> page up<strong>on</strong> completi<strong>on</strong> of this job.[ @DELETE_LEVEL = ] DELETE_LEVELThis value indicates when <strong>to</strong> delete the job. This uses the same values as listed inTable 11.18.The following example shows how <strong>to</strong> create a job from the s<strong>to</strong>red procedure. This createsa job named FILE2. The job is enabled with the notificati<strong>on</strong> level of zero. No notificati<strong>on</strong>swill be created up<strong>on</strong> success or failure. Opera<strong>to</strong>r DBO is assigned as owner <str<strong>on</strong>g>for</str<strong>on</strong>g> this job.USE MSDBEXEC SP_ADD_JOB @JOB_NAME = 'FILE2',@ENABLED = 1,@DESCRIPTION = 'FILE DUMP JOB',@OWNER_LOGIN_NAME = 'DBO',@NOTIFY_LEVEL_EVENTLOG = 0,@NOTIFY_LEVEL_EMAIL = 0,@NOTIFY_LEVEL_NETSEND = 0,@NOTIFY_LEVEL_PAGE = 0,@DELETE_LEVEL = 0After the job is created, it must have some steps <strong>to</strong> execute. The steps define thefuncti<strong>on</strong> of the job. The following example runs a Data Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> package by usingthe DTSRUN utility. SUBSYSTEM should be CMDEXEC <strong>to</strong> run any utility from a job.USE MSDBEXEC SP_ADD_JOBSTEP @JOB_NAME = 'FILE2',@STEP_NAME = 'STEP1 IN FILE2',@SUBSYSTEM = 'CMDEXEC',@COMMAND = 'DTSRUN /S "(LOCAL)" /N "FILETRANSFER" /U "SA" /P "SA" ',@RETRY_ATTEMPTS = 5,@RETRY_INTERVAL = 5@SUBSYSTEM is used by the <strong>SQL</strong> <strong>Server</strong> agent service. The available values aredescribed in Table 11.19.Table 11.19: Values <str<strong>on</strong>g>for</str<strong>on</strong>g> @SUBSYSTEM <str<strong>on</strong>g>for</str<strong>on</strong>g> SP_ADD_JOBSubsystem TypeACTIVESCRIPTINGCMDEXECDISTRIBUTIONSNAPSHOTLOGREADERMERGE'T<strong>SQL</strong>' (default)Descripti<strong>on</strong>Active ScriptOperating-system command or executable programReplicati<strong>on</strong> Distributi<strong>on</strong> Agent jobReplicati<strong>on</strong> Snapshot Agent jobReplicati<strong>on</strong> Log Reader Agent jobReplicati<strong>on</strong> Merge Agent jobTransact-<strong>SQL</strong> statement@COMMANDis the actual command <strong>to</strong> execute. In the following example, the DTSRUNutility is used. Any executable can be called using @COMMAND.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 217Any number of steps can be added <strong>to</strong> a single job. The sequence of the steps isdetermined by the parameter @STEP_ID in this procedure.After the steps have been created, the job can be either executed manually or scheduled.If it needs <strong>to</strong> be scheduled, then SP_ADD_JOBSCHEDULE is used with a set ofparameters.This example highlights how <strong>to</strong> schedule a job FILE2 <strong>to</strong> occur everyday at 1:00 A.M. in<strong>SQL</strong> <strong>Server</strong>.USE MSDBEXEC SP_ADD_JOBSCHEDULE @JOB_NAME = 'FILE2',@NAME = 'DAILY LOAD',@FREQ_TYPE = 4, -- DAILY@FREQ_INTERVAL = 1,@ACTIVE_START_TIME = 10000@FREQ_TYPE is the frequency type. It can accept any <strong>on</strong>e of the values listed in Table11.20:Table 11.20: Values <str<strong>on</strong>g>for</str<strong>on</strong>g> @FREQ_TYPE <str<strong>on</strong>g>for</str<strong>on</strong>g> SP_ADD_JOBValue Descripti<strong>on</strong>1 Once4 Daily8 Weekly16 M<strong>on</strong>thly32 M<strong>on</strong>thly, relative <strong>to</strong> freq interval64 Run when <strong>SQL</strong> <strong>Server</strong> Agent service starts128 Run when the computer is idle@FREQ_INTERVAL acts depend up<strong>on</strong> the value of @FREQ_TYPE. For example, if@ FREQ_TYPE is set as <strong>on</strong>ce, then @ FREQ_INTERVAL has no impact. If@FREQ_INTERVAL is set <strong>to</strong> run weekly, then @FREQ_INTERVAL is used <strong>to</strong> indicate<strong>on</strong> which day the job should run.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> this <strong>to</strong>pic, refer <strong>to</strong> the MSDN library at http://www.msdn.com.Step 6: Interface File C<strong>on</strong>versi<strong>on</strong>Any applicati<strong>on</strong> will have inbound and outbound interface files. During applicati<strong>on</strong>migrati<strong>on</strong>, it is the applicati<strong>on</strong> developer's resp<strong>on</strong>sibility <strong>to</strong> c<strong>on</strong>sider all inbound as well asoutbound files. External applicati<strong>on</strong>s will use specified <str<strong>on</strong>g>for</str<strong>on</strong>g>mats. Even after the c<strong>on</strong>versi<strong>on</strong>from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the external applicati<strong>on</strong> will still need the interface file in the same <str<strong>on</strong>g>for</str<strong>on</strong>g>mat.Similarly, the external applicati<strong>on</strong> might send some interface files <strong>to</strong> the database.C<strong>on</strong>sidering that the <str<strong>on</strong>g>for</str<strong>on</strong>g>mat might remain the same, applicati<strong>on</strong> code must be c<strong>on</strong>vertedin such a way that the applicati<strong>on</strong> will handle the file, even though it is not in a<strong>SQL</strong> <strong>Server</strong>-specific <str<strong>on</strong>g>for</str<strong>on</strong>g>mat.Step 7: Workflow Au<strong>to</strong>mati<strong>on</strong>When per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the applicati<strong>on</strong> migrati<strong>on</strong>, workflow must also be examined. Thissecti<strong>on</strong> discusses how <strong>to</strong> sendmail from the <strong>SQL</strong> <strong>Server</strong> database.


218 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>Sending MailSending mail from an applicati<strong>on</strong> is a very comm<strong>on</strong> requirement. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> includes apackage named UTL_SMTP <strong>to</strong> provide e-mail functi<strong>on</strong>s. Using UTL_SMTP, applicati<strong>on</strong>developers write their code <strong>to</strong> send notificati<strong>on</strong> mails from PL/<strong>SQL</strong> programs. Somesetup is needed in the server side be<str<strong>on</strong>g>for</str<strong>on</strong>g>e UTL_SMTP can be used.<strong>SQL</strong> <strong>Server</strong> has several opti<strong>on</strong>s <strong>to</strong> send e-mail. Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e using these opti<strong>on</strong>s, the mailaccounts and mail service in the server where <strong>SQL</strong> <strong>Server</strong> resides needs <strong>to</strong> be set upand c<strong>on</strong>figured. After this is set up, the XP_SENDMAIL s<strong>to</strong>red procedure can be used <strong>to</strong>send notificati<strong>on</strong> mails. XP_SENDMAIL has all the opti<strong>on</strong>s of mail services, includingattachments. For example, the error log file can be sent <strong>to</strong> the administra<strong>to</strong>r in case ofserver side errors. Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e using mail opti<strong>on</strong>s, set up <strong>SQL</strong> Mail in <strong>SQL</strong> <strong>Server</strong> Enterprise Managerusing the following steps:1. Expand the server group and then expand the server.2. Expand Support Services, right-click <strong>SQL</strong> Mail, and then click Properties.3. In the Profile list, select the profile that you created earlier.4. Click Test if you want <strong>to</strong> test the <strong>SQL</strong> mail. After <strong>SQL</strong> mail is set up, jobs can be c<strong>on</strong>figured <strong>to</strong> send mail alerts <strong>on</strong> jobcompleti<strong>on</strong> <strong>to</strong> indicate whether the job succeeded or failed. To c<strong>on</strong>figure thejobs, follow these steps:1. Go <strong>to</strong> Jobs, select a particular job, and then click Properties.2. On the Notificati<strong>on</strong> tab, you can enable the mailing opti<strong>on</strong> up<strong>on</strong> success or failure.3. To send mail from Jobs, the Mail comp<strong>on</strong>ent needs <strong>to</strong> be started. This can bestarted au<strong>to</strong>matically whenever <strong>SQL</strong> <strong>Server</strong> agent starts. Alternatively,XP_STARTMAIL can be used <strong>to</strong> start the mail agent of <strong>SQL</strong> <strong>Server</strong>.In additi<strong>on</strong>, XP_SENDMAIL can be used <strong>to</strong> send mail from T-<strong>SQL</strong> batches, triggers, orprocedures. The syntax is shown in the following example:XP_SENDMAIL {[@RECIPIENTS =] 'RECIPIENTS [;...N]'}[,[@MESSAGE =] 'MESSAGE'][,[@QUERY =] 'QUERY'][,[@ATTACHMENTS =] 'ATTACHMENTS [;...N]'][,[@COPY_RECIPIENTS =] 'COPY_RECIPIENTS [;...N]'[,[@BLIND_COPY_RECIPIENTS =] 'BLIND_COPY_RECIPIENTS [;...N]'[,[@SUBJECT =] 'SUBJECT']The following example sends a mail <strong>to</strong> the mail ID <strong>SQL</strong>DBA@ABC.COM and a copy <strong>to</strong>another mail ID <strong>SQL</strong>DBA1@ABC.COM. This also sends an attachment with the name"error.log" that is in the direc<strong>to</strong>ry C:\.XP_SENDMAIL @RECIPIENTS='<strong>SQL</strong>DBA@ABC.COM', @MESSAGE='Test mail from <strong>SQL</strong> Mail',@ATTACHMENTS='C:\ERROR_LOG', @COPY_RECIPIENTS='@<strong>SQL</strong>DBA1@ABC.COM', @SUBJECT='TestSubject'Step 8: Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance TuningAfter the code changes have been incorporated, the next step is <strong>to</strong> review and tune theper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. Make sure proper joins are in place and all possible indexed columns areused while executing the query.General techniques and guidelines are discussed in thissecti<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 219After following these optimizati<strong>on</strong> techniques, test the applicati<strong>on</strong> with a test database. Ifpossible, use a copy of producti<strong>on</strong> data while testing so that the real resp<strong>on</strong>se times canbe recorded and more time can be spent tuning the applicati<strong>on</strong>.The goal of per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance tuning is <strong>to</strong> minimize the resp<strong>on</strong>se time <str<strong>on</strong>g>for</str<strong>on</strong>g> each query and <strong>to</strong>maximize the throughput of the entire database server by reducing network traffic, diskI/O, and CPU time. This goal is achieved through understanding applicati<strong>on</strong>requirements, the logical and physical structure of the data, and tradeoffs betweenc<strong>on</strong>flicting uses of the database. Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance strategies vary in their effectiveness, andsystems with different purposes, such as operati<strong>on</strong>al systems and decisi<strong>on</strong> supportsystems, require different per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance skills.System per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is designed and built in<strong>to</strong> a system. It does not just happen.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance issues should be c<strong>on</strong>sidered throughout the development cycle, not just atthe end when the system is implemented. Many per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance issues that result insignificant improvements are achieved by careful design from the outset.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance problems are usually the result of competiti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>, or exhausti<strong>on</strong> of, systemresources.When a system resource is exhausted, the system is unable <strong>to</strong> scale <strong>to</strong> higherlevels of per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. Although other system-level per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance issues, such as memoryor hardware, are certainly candidates <str<strong>on</strong>g>for</str<strong>on</strong>g> study, experience shows that the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancegains from tuning a query are <strong>on</strong>ly incremental when there are fundamental problems inits design.This secti<strong>on</strong> describes how <strong>SQL</strong> <strong>Server</strong> queries can be optimized when migrating from<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> applicati<strong>on</strong>s.For example, in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, there are several areas where a DBA c<strong>on</strong>centrates <strong>on</strong> tuning thedatabase and queries, such as:● Memory tuning● I/O tuning● <strong>SQL</strong> tuning● Managing data and transacti<strong>on</strong>s<strong>SQL</strong> <strong>Server</strong> au<strong>to</strong>matically manages available hardware resources, reducing the need <str<strong>on</strong>g>for</str<strong>on</strong>g>extensive system-level manual tuning. Apart from this au<strong>to</strong>matic management,<strong>SQL</strong> <strong>Server</strong> provides several ways <strong>to</strong> optimize per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance during the development andafter the system is released in<strong>to</strong> producti<strong>on</strong>. These methods are discussed under thefollowing headings.Query TuningIt may be tempting <strong>to</strong> address a per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance problem solely by system-level serverper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance tuning; <str<strong>on</strong>g>for</str<strong>on</strong>g> example, by altering memory size, type of file system, andnumber and type of processors. Generally, most per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance problems cannot beresolved this way. They must be addressed by analyzing the applicati<strong>on</strong>, queries, andupdates that the applicati<strong>on</strong> is submitting <strong>to</strong> the database, and how these queries andupdates interact with the database schema.Unexpected l<strong>on</strong>g-lasting queries and updates can be caused by:● Slow network communicati<strong>on</strong>● Inadequate memory in the server computer● Lack of useful statistics● Out-of-date statistics● Lack of useful indexes


220 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>●●Lack of useful data stripingImproper database designThese issues can be resolved <strong>on</strong>ly by looking at the query and its path of executi<strong>on</strong>.<strong>SQL</strong> <strong>Server</strong> has several ways <strong>to</strong> identify all of these issues. Two of the comm<strong>on</strong>ly usedmethods, <strong>SQL</strong> Profiler and the SET SHOWPLAN statement, are discussed here. Refer <strong>to</strong>Appendix B <str<strong>on</strong>g>for</str<strong>on</strong>g> a list of references about improving per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.<strong>SQL</strong> ProfilerThis graphical <strong>to</strong>ol allows system administra<strong>to</strong>rs <strong>to</strong> m<strong>on</strong>i<strong>to</strong>r events in an instance of<strong>SQL</strong> <strong>Server</strong>. Each event can be captured <strong>to</strong> a file or another table. Using this data, thequery can be analyzed. A s<strong>to</strong>red procedure that hampers the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance can also bem<strong>on</strong>i<strong>to</strong>red.Only use the <strong>SQL</strong> Profiler <str<strong>on</strong>g>for</str<strong>on</strong>g> suspicious events. As <strong>SQL</strong> Profiler is used, it can slowdown the server and increase the trace file size. Specific events can be filtered so <strong>on</strong>ly asubset of data can be m<strong>on</strong>i<strong>to</strong>red.After you have traced the events, <strong>SQL</strong> Profiler allows captured event data <strong>to</strong> be replayedagainst an instance of <strong>SQL</strong> <strong>Server</strong>, effectively re-executing the saved events as theyoccurred originally.<strong>SQL</strong> Profiler can be used <strong>to</strong>:● M<strong>on</strong>i<strong>to</strong>r the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of an instance of <strong>SQL</strong> <strong>Server</strong>.● Debug Transact-<strong>SQL</strong> statements and s<strong>to</strong>red procedures.● Identify slow-executing queries.● Test <strong>SQL</strong> statements and s<strong>to</strong>red procedures in the Developing Phase of a projectby going through statements <strong>to</strong> c<strong>on</strong>firm that the code works as expected.● Troubleshoot problems in <strong>SQL</strong> <strong>Server</strong> by capturing events <strong>on</strong> a producti<strong>on</strong> systemand replaying them <strong>on</strong> a test system. This is useful <str<strong>on</strong>g>for</str<strong>on</strong>g> testing or debuggingpurposes and allows users <strong>to</strong> c<strong>on</strong>tinue using the producti<strong>on</strong> system withoutinterference.● Audit and review activity that occurred <strong>on</strong> an instance of <strong>SQL</strong> <strong>Server</strong>. This allows asecurity administra<strong>to</strong>r <strong>to</strong> review any of the auditing events, including the successand failure of a login attempt and the success and failure of permissi<strong>on</strong>s inaccessing statements and objects.• Provide input <strong>to</strong> the Index Tuning Wizard <strong>to</strong> determine index usage suggesti<strong>on</strong>s.Using SET SHOWPLAN in <strong>SQL</strong> <strong>Server</strong>SET SHOWLAN is similar <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> EXPAIN PLAN command, and it is used <strong>to</strong>display detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about a query. SET SHOWPLAN_ALL causes <strong>SQL</strong> <strong>Server</strong>not <strong>to</strong> execute Transact-<strong>SQL</strong> statements. Instead, <strong>SQL</strong> <strong>Server</strong> returns detailedin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about how the statements are executed and provides estimates of theresource requirements <str<strong>on</strong>g>for</str<strong>on</strong>g> the statements. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> this command is:SET SHOWPLAN_ALL {ON | OFF}When SET SHOWPLAN_ALL is ON, <strong>SQL</strong> <strong>Server</strong> returns executi<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> eachstatement without executing it, and Transact-<strong>SQL</strong> statements are not executed. After thisopti<strong>on</strong> is set ON, in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about all subsequent Transact-<strong>SQL</strong> statements is returneduntil the opti<strong>on</strong> is set OFF.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 221For example, if a CREATE TABLE statement is executed while SET SHOWPLAN_ALL isON, <strong>SQL</strong> <strong>Server</strong> returns an error message. When SET SHOWPLAN_ALL is OFF,<strong>SQL</strong> <strong>Server</strong> executes the statements without generating a report.Use SET SHOWPLAN_TEXT <strong>to</strong> return readable output <str<strong>on</strong>g>for</str<strong>on</strong>g> Microsoft MS-DOSapplicati<strong>on</strong>s, such as the osql utility.SET SHOWPLAN_TEXT and SET SHOWPLAN_ALL cannot be specified inside a s<strong>to</strong>redprocedure; they must be the <strong>on</strong>ly statements in a batch.SET SHOWPLAN_ALL returns in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> as a set of rows that <str<strong>on</strong>g>for</str<strong>on</strong>g>m a hierarchical treerepresenting the steps taken by the <strong>SQL</strong> <strong>Server</strong> query processor as it executes eachstatement. Each statement reflected in the output c<strong>on</strong>tains a single row with the text ofthe statement, followed by several rows with the details of the executi<strong>on</strong> steps.For a more detailed view of the output obtained by turning <strong>on</strong> SET SHOWPLAN_ALL,refer <strong>to</strong> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_365o.asp.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 22312Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PerlIntroducti<strong>on</strong> and GoalsThis chapter c<strong>on</strong>tains a detailed discussi<strong>on</strong> of changes that must be made <strong>to</strong> Perlapplicati<strong>on</strong>s <strong>to</strong> work with Microsoft® <strong>SQL</strong> <strong>Server</strong>. At the c<strong>on</strong>clusi<strong>on</strong> of this chapter, thePerl applicati<strong>on</strong> should be capable of successfully c<strong>on</strong>necting <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong>database that was migrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and the soluti<strong>on</strong> can be tested.As discussed in the "Define the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> C<strong>on</strong>cept" secti<strong>on</strong> of Chapter 2, "Envisi<strong>on</strong>ingPhase", there are four different strategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> transiti<strong>on</strong>ing applicati<strong>on</strong>s in an<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> project. The strategies are:● Interoperate the applicati<strong>on</strong> with <strong>UNIX</strong>.● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft Win32® plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.● Quick port using the Windows® Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.Perl is an interpreted scripting language that runs <strong>on</strong> both <strong>UNIX</strong> and Windows. Becauseof the cross-plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m capabilities of Perl, some of these strategies are more logical thanothers.For example, because Perl can be ported <strong>to</strong> Windows, there is no need <strong>to</strong> rewrite theapplicati<strong>on</strong> in the .NET framework or <str<strong>on</strong>g>for</str<strong>on</strong>g> the Win32® envir<strong>on</strong>ment. Also, because theapplicati<strong>on</strong> can run within the Windows envir<strong>on</strong>ment, a quick port usingWindows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> is not necessary and would <strong>on</strong>ly prevent the applicati<strong>on</strong> fromtightly integrating with Windows.Based <strong>on</strong> available migrati<strong>on</strong> strategies, two scenarios can be developed <strong>to</strong> migrate Perlapplicati<strong>on</strong>s. The soluti<strong>on</strong> scenarios are:● Scenario 1: Interoperati<strong>on</strong> of Perl <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong>If the business requirements do not include eliminating the <strong>UNIX</strong> envir<strong>on</strong>ment, aninteroperati<strong>on</strong> strategy can be implemented quickly. Few changes need <strong>to</strong> bemade <strong>to</strong> the source code, and installing a new driver allows the Perl applicati<strong>on</strong> <strong>to</strong>c<strong>on</strong>nect <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database. Interoperati<strong>on</strong> can also be used as an interimstep if the migrati<strong>on</strong> is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in phases.● Scenario 2: Port the Perl Applicati<strong>on</strong> <strong>to</strong> Win32


224 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PerlPerl applicati<strong>on</strong>s can also be ported <strong>to</strong> run natively <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Aswith interoperati<strong>on</strong>, few changes need <strong>to</strong> be made <strong>to</strong> the source code.Note If your Perl applicati<strong>on</strong>s use <strong>UNIX</strong> system calls extensively (such as frequent useof syscall and exec), porting them <strong>to</strong> Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>/Interix may be asuitable opti<strong>on</strong> because Interix has more support <str<strong>on</strong>g>for</str<strong>on</strong>g> the desired system calls. Chapter2, "Envisi<strong>on</strong>ing Phase," provides a more detailed discussi<strong>on</strong> of when choosingServices <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> would be more appropriate when moving <strong>to</strong> a Windows-basedplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.You will need the following <strong>to</strong> implement this opti<strong>on</strong> (porting Perl applicati<strong>on</strong>s <strong>to</strong> Services<str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>/<strong>SQL</strong> <strong>Server</strong>):● A port of Perl <str<strong>on</strong>g>for</str<strong>on</strong>g> Interix (downloadable from Interop Systems athttp://www.interopsystems.com/<strong>to</strong>ols/warehouse.htm), which ships with thenecessary DBI, DBD::ODBC and DBD::Sybase modules.● A c<strong>on</strong>nectivity driver <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. This is provided by the port ofFreeTDS <strong>on</strong> Interix and is downloadable from Interop Systems athttp://www.interopsystems.com/<strong>to</strong>ols/db.htm. FreeTDS provides two c<strong>on</strong>nectivityopti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> the Perl applicati<strong>on</strong> <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. One is alibrary called CTlib, which can be accessed through the DBD::Sybase module. Theother is an odbc driver, which can be accessed though the DBD::ODBC module.● If you use the ODBC driver, you will also need an ODBC driver manager. Twodifferent ODBC driver managers iODBC and unixODBC are available <str<strong>on</strong>g>for</str<strong>on</strong>g> WindowsServices <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> from http://www.inte ropsystems.com/<strong>to</strong>ols/warehouse.htm.This technology opti<strong>on</strong>, however, has not been fully tested as a part of development ofthis soluti<strong>on</strong> and there<str<strong>on</strong>g>for</str<strong>on</strong>g>e has not been detailed further.Introducti<strong>on</strong> <strong>to</strong> the Perl DBI ArchitectureThere are several different modulesavailable <str<strong>on</strong>g>for</str<strong>on</strong>g> use with Perl that extend the capabilitiesof the language. One of these modules, the Database Independent Interface (DBI),


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 225provides a comm<strong>on</strong> programming interface <str<strong>on</strong>g>for</str<strong>on</strong>g> several different proprietary databases,including <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. DBI offers a single set of functi<strong>on</strong>s or methods that caninteract with the databases. These functi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g>m an abstracti<strong>on</strong> layer that allows theprogrammer <strong>to</strong> write code using generic DBI calls without needing specific APIknowledge <str<strong>on</strong>g>for</str<strong>on</strong>g> the particular database. This layer makes the Perl code portable acrossdatabases.These generic DBI calls are then interpreted in<strong>to</strong> RDBMS-specific functi<strong>on</strong>s usingspecialized Database Driver (DBD) modules. A DBD is a database-specific driver thattranslates DBI calls <strong>to</strong> the target database. The DBI API <str<strong>on</strong>g>for</str<strong>on</strong>g>wards the call <strong>to</strong> theappropriate database driver module, which then provides support, such as the dynamicload ing of drivers, error-checking, and management. Figure 12.1 provides a visualrepresentati<strong>on</strong> of path from a Perl script <strong>to</strong> the backend database using DBI-DBD.Figure 12.1Perl communicati<strong>on</strong> with databases using DBI API and DBD driversDBI also supports the Open Database C<strong>on</strong>nectivity (ODBC) interface. While DBI itself isan abstracti<strong>on</strong> layer, ODBC <str<strong>on</strong>g>for</str<strong>on</strong>g>ms another additi<strong>on</strong>al abstracti<strong>on</strong> layer. This layer,c<strong>on</strong>sisting of an ODBC driver and ODBC driver manager mirrors the functi<strong>on</strong>s of the DBIand DBD within Perl. If the current soluti<strong>on</strong> utilizes ODBC, then a port using ODBC mayprovide the most direct soluti<strong>on</strong>. In other instances, ODBC may simply duplicate otherlaye rs and add additi<strong>on</strong>al processing overhead. In these situati<strong>on</strong>s, ODBC is notrecommended. Figure 12.2 shows the path from Perl script <strong>to</strong> backend databaseinvolving ODBC drivers.Figure 12.2ODBC adds additi<strong>on</strong>al layers of c<strong>on</strong>nectivity between the applicati<strong>on</strong> and databaseScenario 1: Interoperati<strong>on</strong> of Perl <strong>on</strong> <strong>UNIX</strong> with<strong>SQL</strong> <strong>Server</strong>Interoperati<strong>on</strong> between a <strong>UNIX</strong>-based Perl applicati<strong>on</strong> and a <strong>SQL</strong> <strong>Server</strong> database ispossible because of the availability of a driver that interfaces between thesetechnologies. Because of the DBI API, this type of migrati<strong>on</strong> is usually a relatively simpleprocess. Only minimal changes may need <strong>to</strong> be made <strong>to</strong> the Perl applicati<strong>on</strong>'s source


226 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Perlcode.The cases described in this secti<strong>on</strong> discuss opti<strong>on</strong>s available <str<strong>on</strong>g>for</str<strong>on</strong>g> Perl applicati<strong>on</strong>susing ODBC or <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> drivers. The following cases assume that the Perl applicati<strong>on</strong>currently uses either the ODBC DBD or the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBD within the existing soluti<strong>on</strong>.Case 1: Interoperating an ODBC DBD Applicati<strong>on</strong>If the original applicati<strong>on</strong> was written using ODBC DBD, then the best migrati<strong>on</strong> opti<strong>on</strong> is<strong>to</strong> c<strong>on</strong>tinu e <strong>to</strong> use this driver. Because ODBC is not database-specific, no changesshould need <strong>to</strong> be made <strong>to</strong> the applicati<strong>on</strong>'s source code. The <strong>on</strong>ly changes that need <strong>to</strong>be made c<strong>on</strong>cern c<strong>on</strong>nectivity with the <strong>SQL</strong> <strong>Server</strong> database. T o interoperate the Perl applicati<strong>on</strong> using ODBC, follow these comm<strong>on</strong> steps:1. Install the ODBC driver.The DBD::ODBC module requires a driver manager and a driver <strong>to</strong> interact with<strong>SQL</strong> <strong>Server</strong>. DBD::ODBC is packaged with the Independent ODBC (iODBC) drivermanager from OpenLink Software (http://www.openlinksw.com/). For morein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about this driver, refer <strong>to</strong>http ://www.freetds.org/userguide/perl.htm#DBD.ODBC. Another driver manager,unixODBC, that could be used in an interoperati<strong>on</strong> scenario is available fromhttp://www.freetds.org/user guide/prepodbc.htm.FreeTDS is a popular ODBC driver used <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> from a <strong>UNIX</strong>-source implementati<strong>on</strong> of Tabular Databased applicati<strong>on</strong>. FreeTDS is an openStream (TDS) pro<strong>to</strong>col that allows the applicati<strong>on</strong> native access <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.OpenLink also offers drivers <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> that use the FreeTDS implementati<strong>on</strong>of TDS. Detailed instructi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> building and c<strong>on</strong>figuring this driver are available athttp://www.freetds.org/userguide/perl.htm.For detailed steps <strong>on</strong> installing the unixODBC or FreeTDS drivers, see AppendixD: "Installing Comm<strong>on</strong> Drivers and Applicati<strong>on</strong>s." Even though the discussi<strong>on</strong> isrelated <strong>to</strong> installing FreeTDS in a Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> envir<strong>on</strong>ment, itapplies equally <strong>to</strong> <strong>UNIX</strong> as well.2. Create a <strong>SQL</strong> <strong>Server</strong> data source.To functi<strong>on</strong>, ODBC needs a data source <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the database. The DataSource Name (DSN) is generally defined in an odbc.ini file that is used by thedriver manager. The DSN is used by the driver manager <strong>to</strong> load the ODBC driver.iODBC offers a graphical user interface <strong>to</strong> set up the DSN. Complete instructi<strong>on</strong>sare available from http://www.iodbc.org/index.php?page=docs/odbcs<strong>to</strong>ry.The DSN can also be c<strong>on</strong>figured by manually modifying the odbc.ini file. Thefollowing example file uses an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DSN.[ODBC Data Sources]ORA_HR_DB=Sample <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>8 dsn[ORA_HR_DB]Driver=/opt/odbc/lib/ivor8x01.soDescripti<strong>on</strong>=<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>8<strong>Server</strong>Name=uxdbp1Log<strong>on</strong>ID=davebPassword=cougarThis c<strong>on</strong>figurati<strong>on</strong> file can be modified <strong>to</strong> use the <strong>SQL</strong> <strong>Server</strong> DSN, as shown inthe following example. Note that the [ORA_HR_DB] secti<strong>on</strong> is replaced with[SS_HR_DB]. Though most of the keys remain, the values are modified <strong>to</strong> allow <str<strong>on</strong>g>for</str<strong>on</strong>g>the <strong>SQL</strong> <strong>Server</strong> data source.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 227[ODBC Data Sources]SS_HR_DB=Sample MS <strong>SQL</strong><strong>Server</strong>[SS_HR_DB]Driver=/usr/local/freetds/lib/libtdsodbc.soDescripti<strong>on</strong>=<strong>SQL</strong> <strong>Server</strong> 2000Database=hrappUID=davebPWD=cougarAddress=win2kdbp1,1433Note The isql command line utility can be used <strong>to</strong> check the validity of the DSNentry when using unixODBC. This allows you <strong>to</strong> ensure that the entries in theodbc.ini are correct. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> use is:isql -v DSN username password3.Test the c<strong>on</strong>nectivity.iODBC c<strong>on</strong>tains a utility named odbctest which can be used <strong>to</strong> test the DSNentries and interact with the database by c<strong>on</strong>necting and issuing queries directlywithout any code. The syntax <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming this test is:odbctest "DSN=SS_HR_DB;UID=daveb;PWD=cougar"4. Change the existing applicati<strong>on</strong> <strong>to</strong> use <strong>SQL</strong> <strong>Server</strong> as data source.The following sample source Perl program from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> envir<strong>on</strong>ment c<strong>on</strong>tainsfuncti<strong>on</strong>s <strong>to</strong> c<strong>on</strong>nect, prepare, execute, bind, and disc<strong>on</strong>nect. Compare thesefuncti<strong>on</strong>s with the Perl code in the following example. Minor adjustments are made<strong>to</strong> allow <str<strong>on</strong>g>for</str<strong>on</strong>g> the data source change.#Load the DBI moduleuse DBI;my $c<strong>on</strong>nectstring_oracle = 'ora_hr_db';my $username = 'daveb';my $password = 'cougar';my $tablename = 'Employee_Info';#C<strong>on</strong>necting <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DB using ODBCmy $dbh = DBI->c<strong>on</strong>nect(" dbi:ODBC:$c<strong>on</strong>nectstring_oracle", "$username","$password");#Preparing the <strong>SQL</strong> statement$sth = $dbh->prepare("insert in<strong>to</strong> $tablename (last_name) values (?)");#Binding the value <strong>to</strong> the parameter at run time.$sth->bind_param( 1,"LName);#Executing the query$sth->execute() or warn $sth->errstr(); # check <str<strong>on</strong>g>for</str<strong>on</strong>g> error$sth->finish();


228 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Perl#Disc<strong>on</strong>nect from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database$dbh->disc<strong>on</strong>nect or warn "Can't disc<strong>on</strong>nect from the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>$c<strong>on</strong>nectstring_oracle database: $DBI::errstr\n";The same functi<strong>on</strong>s are modified <strong>to</strong> use a <strong>SQL</strong> <strong>Server</strong> data source in the followingexample:my $c<strong>on</strong>nectstring_oracle = 'ora_hr_db';my $username = 'daveb';my $password = 'cougar';my $tablename = 'Employee_Info';#C<strong>on</strong>necting <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DB using ODBCmy $dbh = DBI->c<strong>on</strong>nect("dbi:ODBC:$c<strong>on</strong>nectstring_oracle", "$username","$password")<strong>to</strong>my $c<strong>on</strong>nectstring_ss = 'ss_hr_db';my $username = 'daveb';my $password = 'cougar';my $tablename = 'Employee_Info';#C<strong>on</strong>necting <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> DB using ODBCmy $dbh = DBI->c<strong>on</strong>nect("dbi:ODBC:$c<strong>on</strong>nectstring_ss", "$username", "$password")5. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.This is a step comm<strong>on</strong> <strong>to</strong> all migrati<strong>on</strong>s. Refer <strong>to</strong> Chapter 11, "Developing:Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> a detailed discussi<strong>on</strong> <strong>on</strong> modifying<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.Case 2: Interoperating an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBD Applicati<strong>on</strong>If the original applicati<strong>on</strong> was written using the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBD, there are two possibleopti<strong>on</strong>s that can be evaluated. The recommended opti<strong>on</strong> is <strong>to</strong> replace the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBDwith a Sybase DBD. The sec<strong>on</strong>d opti<strong>on</strong> is <strong>to</strong> migrate <strong>to</strong> an ODBC framework similar <strong>to</strong>the <strong>on</strong>e seen in "Case 1: Interoperating an ODBC DBD Applicati<strong>on</strong>." Sybase DBD offersbetter per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance than ODBC.Migrate <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> Using Sybase DBDBecau se <strong>SQL</strong> <strong>Server</strong> was originally based <strong>on</strong> the Sybase data structure, it is possible <strong>to</strong>use the Sybase DBD <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> using a <strong>SQL</strong> <strong>Server</strong> driver. To use the Sybase DBD <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> using a <strong>SQL</strong> <strong>Server</strong> driver,follow these steps:1. Install <strong>SQL</strong> <strong>Server</strong> library support.The FreeTDS driver is needed <str<strong>on</strong>g>for</str<strong>on</strong>g> this method. Instructi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> installing andc<strong>on</strong>figuring the driver are located in Appendix D, "Installing Comm<strong>on</strong> Drivers andApplicati<strong>on</strong>s." Even though the discussi<strong>on</strong> is related <strong>to</strong> installing FreeTDS in aWindows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> envir<strong>on</strong>ment, it applies equally <strong>to</strong> <strong>UNIX</strong> as well.Because the driver is not being used with ODBC, the -disable-odbc switch can beused with the c<strong>on</strong>figure command while installing FreeTDS. Details <strong>on</strong> the use ofthis command are availa ble at http://www.freetds.org/userguide/c<strong>on</strong>fig.htm.2. C<strong>on</strong>figure the data source.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 229After FreeTDS is installed, the freetds.c<strong>on</strong>f file should be modified <strong>to</strong> include the<strong>SQL</strong> <strong>Server</strong> database in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. A sample entry is shown in the followingexample:[SS_HR_DB]host = win2kdbp1 # or IP addressport = 1433tds versi<strong>on</strong> = 8.03. Install the Sybase DBD module.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> installing this Perl module, refer <strong>to</strong>http://search.cpan.org/~mewp/DBD-Sybase/Sybase.pm.In additi<strong>on</strong>, the SYBASE envir<strong>on</strong>ment variable should be set <strong>to</strong> the locati<strong>on</strong> of theFreeTDS installati<strong>on</strong>. If using bash or ksh, the following commands can be used:4.export SYBASE=/usr/local/freetdsModify the applicati<strong>on</strong>'s source code.Minor changes will need <strong>to</strong> be made <strong>to</strong> the source code <strong>to</strong> allow <str<strong>on</strong>g>for</str<strong>on</strong>g> the datasource change. The following sample code shows some different implementati<strong>on</strong>opti<strong>on</strong>s of the Perl language that may appear in your existing source code.Compare these <strong>to</strong> the sec<strong>on</strong>d code sample that has been modified <strong>to</strong> use theSybase DBD.# load the DBI moduleuse DBI;# C<strong>on</strong>nect <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Databasemy $dbh = DBI->c<strong>on</strong>nect("dbi:<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>: ora_hr_db ",'userName','password',{RaiseError = > 1,Au<strong>to</strong>Commit => 0}) || die "Database c<strong>on</strong>necti<strong>on</strong> not made: $DBI::errstr";#Prepare a <strong>SQL</strong> statementmy $sql = qq{ SELECT id, name, title,my $sth = $dbh->prepare( $sql );ph<strong>on</strong>e FROM employees };#Execute the statement$sth->execute();my( $id, $name, $title, $ph<strong>on</strong>e );# Bind the results <strong>to</strong> the local variables$sth->bind_columns( undef, \$id, \$name, \$title, \$ph<strong>on</strong>e );#Retrieve values from the result setwhile( $sth->fetch() ) {print "$name, $title, $ph<strong>on</strong>e\n";}


230 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Perl#Close the c<strong>on</strong>necti<strong>on</strong>$sth->finish();$dbh->disc<strong>on</strong>nect();5. Change the c<strong>on</strong>necti<strong>on</strong> <strong>to</strong> the Sybase DBI and <strong>SQL</strong> <strong>Server</strong> DSN.The script in Step 4 has been rewritten <strong>to</strong> use DBD::Sybase. Note that the changeshave been made in the header <str<strong>on</strong>g>for</str<strong>on</strong>g> the DBD and in the c<strong>on</strong>necti<strong>on</strong> string <str<strong>on</strong>g>for</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong>. The rest of the Perl code is un<strong>to</strong>uched by this change. This modifiedcode is shown in the following example.# load the DBI moduleuse DBI;use DBD::Sybase;BEGIN{$ENV{SYBASE} = "/usr/local";}# C<strong>on</strong>nect <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> Databasemy $dbh = DBI->c<strong>on</strong>nect( “dbi:Sybase:server=ss_hr_db;database=hrapp”,'userName','password',{RaiseError => 1,Au<strong>to</strong>Commit = > 0}) || die "Database c<strong>on</strong>necti<strong>on</strong> not made: $DBI::errstr";#Prepare a <strong>SQL</strong> statementmy $sql = qq{ SELECT id, name, title, ph<strong>on</strong>e FROM employees };my $sth = $dbh->prepare( $sql );#Execute the statement$sth->execute();my( $id, $name, $title, $ph<strong>on</strong>e );# Bind the results <strong>to</strong> the local variables$sth->bind_columns( undef, \$id, \$name, \$title, \$ph<strong>on</strong>e );#Retrieve values from the result setwhile( $sth->fetch() ) {print "$name, $title, $ph<strong>on</strong>e\n";}#Close the c<strong>on</strong>necti<strong>on</strong>$sth->finish();$dbh->disc<strong>on</strong>nect();


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 2316.Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.Refer <strong>to</strong> Chapter 11, "Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> adetailed discussi<strong>on</strong> <strong>on</strong> modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.Migrate <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> Using ODBC To migrate an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBD c<strong>on</strong>necti<strong>on</strong> <strong>to</strong> ODBC, follow these steps:1. Install the ODBC driver.FreeTDS should be installed. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> see Appendix D, "InstallingComm<strong>on</strong> Drivers and Applicati<strong>on</strong>s." Even though the discussi<strong>on</strong> is related <strong>to</strong>installing FreeTDS in a Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> envir<strong>on</strong>ment, it applies equally<strong>to</strong> <strong>UNIX</strong> as well.2. C<strong>on</strong>figure the DSN settings.The steps <str<strong>on</strong>g>for</str<strong>on</strong>g> creating an ODBC DSN have been shown in "Case 1: Interoperatingan ODBC DBD Applicati<strong>on</strong>."3. Install the ODBC DBD module.Installati<strong>on</strong> instructi<strong>on</strong>s are available at http://search.cpan.org/dis t/perl/INSTALLand http://www.easysoft.com/products/2002/perl_dbi_dbd_odbc.phtml#3_0In additi<strong>on</strong>, the following envir<strong>on</strong>ment variables need <strong>to</strong> be set:● ODBCHOME. The direc<strong>to</strong>ry where ODBC driver manager is installed.● DBI_DSN. The dbi data source.● DBI_USER. The username <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the database.● DBI_PASS. The password <str<strong>on</strong>g>for</str<strong>on</strong>g> the database username.4. Modify the source code.The original script written <str<strong>on</strong>g>for</str<strong>on</strong>g> use with DBD::<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> has <strong>to</strong> be changed <strong>to</strong> c<strong>on</strong>nect<strong>to</strong> <strong>SQL</strong> <strong>Server</strong> through the ODBC DSN. Changes are limited <strong>to</strong> the c<strong>on</strong>nect()method as shown in the following code.# load the DBI moduleuse DBI;# C<strong>on</strong>nect <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Databasemy $dbh = DBI->c<strong>on</strong>nect("dbi:ODBC:ss_hr_db",'userName','password',{RaiseError => 1,Au<strong>to</strong>Commit => 0}) || die "Database c<strong>on</strong>necti<strong>on</strong> not made: $DBI::errstr";#Prepare a <strong>SQL</strong> statementmy $sql = qq{ SELECT id, name, title, ph<strong>on</strong>e FROM employees };my $sth = $dbh->prepare( $sql );#Execute the statement$sth->execute();my( $id, $name, $title, $ph<strong>on</strong>e );


232 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Perl# Bind the results <strong>to</strong> the local variables$sth->bind_columns( undef, \$id, \$name, \$title, \$ph<strong>on</strong>e );#Retrieve values from the result setwhile( $sth->fetch() ) {print "$name, $title, $ph<strong>on</strong>e\n";}#Close the c<strong>on</strong>necti<strong>on</strong>$sth->finish();$dbh->disc<strong>on</strong>nect();Note ODBC c<strong>on</strong>necti<strong>on</strong>s can also be made without using DSN sources. Thedifference from a DSN is that the required c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is embeddedin the Perl code instead of residing in a separate initializati<strong>on</strong> file. The followingexample shows a n<strong>on</strong>-DSN c<strong>on</strong>necti<strong>on</strong>:my $dsn = 'DBI:ODBC:Driver={<strong>SQL</strong> <strong>Server</strong>}';my $host = 'hostname';my $database = 'dbname';my $user = 'username';my $auth = 'password';my($dbh) = DBI->c<strong>on</strong>nect("$dsn;$host;$database",$user,$auth,{ RaiseError => 1, Au<strong>to</strong>Commit => 1});5. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.Refer <strong>to</strong> chapter 11, "Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> adetailed discussi<strong>on</strong> <strong>on</strong> modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.Scenario 2: Porting the Perl Applicati<strong>on</strong> <strong>to</strong> WindowsThe migrati<strong>on</strong> of Perl applicati<strong>on</strong>s in a <strong>UNIX</strong> envir<strong>on</strong>ment <strong>to</strong> Windows and moving thebackend <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database is not much more ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t than that needed under theinteroperati<strong>on</strong> scenario. It is possible <strong>to</strong> port the Perl applicati<strong>on</strong> <strong>to</strong> both the .NET and theWin32 envir<strong>on</strong>ment. The port <strong>to</strong> .NET is made possible by the availability of the utilityPerlNET, which can wrap Perl programs in<strong>to</strong> a .NET comp<strong>on</strong>ent. However, theapp licati<strong>on</strong> has <strong>to</strong> be ported from the <strong>UNIX</strong> envir<strong>on</strong>ment <strong>to</strong> Windows envir<strong>on</strong>ment be<str<strong>on</strong>g>for</str<strong>on</strong>g>ethe c<strong>on</strong>versi<strong>on</strong> <strong>to</strong> .NET can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med. Details about PerlNET are available athttp://aspn.activestate.com/ASPN/docs/PDK/6.0/PerlNET.html#perlnet_<strong>to</strong>p.There are a few additi<strong>on</strong>al steps that should be followed <strong>to</strong> successfully move the Perlapplicati<strong>on</strong> <strong>to</strong> Win32. These steps are discussed in the following two cases.Case 1: Porting a Perl Applicati<strong>on</strong> using ODBC DBD To port the Perl applicati<strong>on</strong> <strong>to</strong> the Windows envir<strong>on</strong>ment, follow these steps:1. Install Perl in the target Windows envir<strong>on</strong>ment.ActiveState Perl is available from http://www.activestate.com. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong><strong>on</strong> installing ActivePerl, see Appendix D, "Installing Comm<strong>on</strong> Drivers andApplicati<strong>on</strong>s."2. Install DBI and DBD::ODBC.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 233The DBI and DBD::ODBC modules can be installed using Perl Package Manager(PPM), which is installed with ActivePerl. PPM is an interactive command line utilitywhich can be launched from the command line by typing ppm.Download the DBI and DBD::ODBC files <strong>to</strong> a local direc<strong>to</strong>ry—<str<strong>on</strong>g>for</str<strong>on</strong>g> example,c:\perlppd. These files can be downloaded fromhttp://ppm.activestate.co m/PPMPackages/zips/ .The modules can be installed by typing the following commands:PPM> rep add new c:\perlppdPPM> install DBIPPM> install DBD-ODBCPPM> quit3. Install the ODBC driver.There are several available opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> acquiring and installing an ODBC driver <str<strong>on</strong>g>for</str<strong>on</strong>g><strong>SQL</strong> <strong>Server</strong>. These opti<strong>on</strong>s include:● An ODBC driver <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> is included as part of the <strong>SQL</strong> <strong>Server</strong>distributi<strong>on</strong> CD and is installed as part of the <strong>SQL</strong> <strong>Server</strong> client install. Refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/how<strong>to</strong>sql/ht_install_029l.asp <str<strong>on</strong>g>for</str<strong>on</strong>g> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> installing the <strong>SQL</strong> <strong>Server</strong>client.● OpenLink software offers an ODBC soluti<strong>on</strong> that eliminates the need <strong>to</strong> install<strong>SQL</strong> <strong>Server</strong> client software <strong>on</strong> the server <strong>on</strong> which the Perl applicati<strong>on</strong> will run.Details <strong>on</strong> this driver are available at http://uda.openlinksw.com/odbc/st/odbc-sqlserver-st/.● DataDirect offers C<strong>on</strong>nect <str<strong>on</strong>g>for</str<strong>on</strong>g> ODBC drivers that also provide clientless access<strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. Details are available athttp://www.datadirect.com/products/odbc/index.ssp.4.C<strong>on</strong>figure the ODBC data source.An ODBC data source can be c<strong>on</strong>figured by modifying odbc.ini as shown in the"Case 1: Interoperating an ODBC DBD Applicati<strong>on</strong>" secti<strong>on</strong> of Scenario 1. Thedata source can also be c<strong>on</strong>figured using the ODBC Data Source Administra<strong>to</strong>rutility that is bundled with Windows. This utility can be accessed by accessing fromthe C<strong>on</strong>trol Panel by choosing Administrative Tools, then Data Sources(ODBC). Somedatabase vendors also provide utilities <strong>to</strong> c<strong>on</strong>figure DSNs.


234 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PerlFigure 12.3C<strong>on</strong>figuring the ODBC System DSNNote In Windows, DSNs should be created as a System DSN and not as a UserDSN because of permissi<strong>on</strong>s restricti<strong>on</strong>s associated with the latter.Further steps <str<strong>on</strong>g>for</str<strong>on</strong>g> creating a data source are available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/how<strong>to</strong>sql/ht_6_odbcht_1oqc.asp.5. Change the applicati<strong>on</strong> <strong>to</strong> use <strong>SQL</strong> <strong>Server</strong> as the data source.The move <strong>to</strong> Windows does not add any overhead in terms of modificati<strong>on</strong>s <strong>to</strong> theapplicati<strong>on</strong>. The changes are driven by the change in DSN and are similar <strong>to</strong>changes discussed in the "Case 1: Interoperating an ODBC DBD Applicati<strong>on</strong>"secti<strong>on</strong> of Scenario 1.6. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.This is a step comm<strong>on</strong> <strong>to</strong> all migrati<strong>on</strong>s. Refer <strong>to</strong> Chapter 11, "Developing:Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> a detailed discussi<strong>on</strong> <strong>on</strong> modifying<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.Case 2: Porting a Perl Applicati<strong>on</strong> Using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBDWhen migrating from a <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m <strong>to</strong> a Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, there are two opti<strong>on</strong>s <strong>to</strong>replace the DBD::<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> module. One opti<strong>on</strong> is <strong>to</strong> use the DBD::ODBC module. Theother is <strong>to</strong> use ActiveX Data Objects (ADO) through the DBD::ADO module.Using DBD::ODBC is recommended in most instances and is discussed in greater detailin the "Case 1: Interoperating an ODBC DBD Applicati<strong>on</strong>" secti<strong>on</strong> of Scenario 1.DBD::ADO is a DBI driver that acts as an interface <strong>to</strong> other lower-level database drivers


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 235within Windows. DBD::ADO requires the DBD::ODBC module <strong>to</strong> functi<strong>on</strong>. UsingDBD::ADO will add an additi<strong>on</strong>al c<strong>on</strong>nectivity layer <strong>to</strong> the soluti<strong>on</strong> and should <strong>on</strong>ly beimplemented if the applicati<strong>on</strong> needs <strong>to</strong> take advantage of the OLE DB APIs. This drivercan then be used <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> and access data from any ADO data source.Migrate <strong>to</strong> DBD::ADO To migrate <strong>to</strong> DBD::ADO, follow these steps:1. Install ActivePerl.ActivePerl is a Windows-based Perl engine available fromhttp://www.a ctivestate.com. For detailed installati<strong>on</strong> instructi<strong>on</strong>s, see Appendix D,"Installing Comm<strong>on</strong> Drivers and Applicati<strong>on</strong>s."2. Install DBI.The DBI module can be installed using Perl Package Manager (PPM), which isinstalled with ActivePerl.3. Install DBD::ODBC using PPM.4. Install the ODBC driver.5. C<strong>on</strong>figure the ODBC data source.6. Install ADO.The DBD::ADO module requires Microsoft ADO versi<strong>on</strong> 2.1 or later <strong>to</strong> workreliably. ADO drivers are available from Microsoft as part of the Microsoft DataAccess Comp<strong>on</strong>ent (MDAC) available athttp://msdn.microsoft.com/data/technologyinfo/mdac.Download the DBD::ADO module files <strong>to</strong> a local direc<strong>to</strong>ry—<str<strong>on</strong>g>for</str<strong>on</strong>g> example, c:\perlppd.The ADO module can be downloaded fromhttp://ppm.activestate.com/PPMPackages/zips/.This module can be installed from Perl Package Manager (PPM).Type ppm at the command line <strong>to</strong> start the package manager, and then type thefollowing commands:PPM. Rep add new c:\perlppdPPM> install DBIPPM> install DBD-ADOPPM> quit7. Modify the c<strong>on</strong>necti<strong>on</strong> string <strong>to</strong> use ADO. No other changes should need <strong>to</strong> bemade <strong>to</strong> the source code. A sample ADO c<strong>on</strong>necti<strong>on</strong> string is shown in thefollowing example:use DBI;my $dsn ="Provider=sqloledb;Trusted_C<strong>on</strong>necti<strong>on</strong>=Yes;<strong>Server</strong>=win2kdbp1;Database=hrapps";$dbh = DBI->c<strong>on</strong>nect("dbi:ADO:$dsn", $user, $passwd);Calling s<strong>to</strong>red procedures is supported by DBD::ADO using the ODBC style callprocedure_name(). An example <str<strong>on</strong>g>for</str<strong>on</strong>g> calling a procedure ismy $sth = $dbh->prepare("{call procedure name (?)}");Parameters can be either input or output parameters. Parameters are bound asseen in earlier examples.8. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.This is a step comm<strong>on</strong> <strong>to</strong> all migrati<strong>on</strong>s. Refer <strong>to</strong> Chapter 11, "Developing:Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> a detailed discussi<strong>on</strong> <strong>on</strong> modifying<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 23713Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHPIntroducti<strong>on</strong> and GoalsThis chapter explores the opti<strong>on</strong>s available <strong>to</strong> maintain c<strong>on</strong>nectivity of PHP: HypertextPreprocessor (PHP) applicati<strong>on</strong>s as part of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> Microsoft® <strong>SQL</strong> <strong>Server</strong>migrati<strong>on</strong> project. In PHP, the logic <strong>to</strong> interact with databases is provided by database-functi<strong>on</strong>s <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mspecific modules (or drivers). These modules have specializeddatabase-related tasks and can be replaced <strong>to</strong> accommodate a <strong>SQL</strong> <strong>Server</strong> backend withrelative ease.PHP is an open source, server-side, cross-plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m scripting language used <strong>to</strong> createdynamic Web pages. Like any other Comm<strong>on</strong> Gateway Interface (CGI), PHP can providedynamic, data-driven characteristics <strong>to</strong> static HTML <str<strong>on</strong>g>for</str<strong>on</strong>g>ms or pages.As discussed in Chapter 2, "Envisi<strong>on</strong>ing Phase," there are four different strategiesavailable <str<strong>on</strong>g>for</str<strong>on</strong>g> transiti<strong>on</strong>ing applicati<strong>on</strong>s in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> project. Thestrategies are:● Interoperate the applicati<strong>on</strong> with the <strong>UNIX</strong> envir<strong>on</strong>ment.● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft Win32® plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.● Quick port using the Microsoft Windows® Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.Because of the unique characteristics of PHP, some ofthan others.these strategies are more feasibleFor example, because PHP can be ported <strong>to</strong> Windows, there is no need <strong>to</strong> rewrite theapplicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> .NET or Win32 unless the existing soluti<strong>on</strong>'s source code is not available.Because the available drivers <str<strong>on</strong>g>for</str<strong>on</strong>g> .NET are still in beta, the porting has <strong>to</strong> be d<strong>on</strong>e <strong>to</strong> aWin32 envir<strong>on</strong>ment, Also, because the applicati<strong>on</strong> can run within the Windowsenvir<strong>on</strong>ment, a quick port using Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> is not necessary in mostcases.Bas ed <strong>on</strong> the available migrati<strong>on</strong> strategies, two scenarios can be developed <strong>to</strong> migratePHP applicati<strong>on</strong>s. These scenarios include:● Scenario 1: Interoperating PHP <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong>If the business requirementsdo not include eliminating the <strong>UNIX</strong> envir<strong>on</strong>ment, aninteroperati<strong>on</strong> strategy can be implemented quickly. Few changes need <strong>to</strong> be


238 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHP●made <strong>to</strong> the source code and installing a new driver allows the PHP applicati<strong>on</strong> <strong>to</strong>c<strong>on</strong>nect <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database. If the migrati<strong>on</strong> is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in phases,interoperati<strong>on</strong> can be used as an interim step.Scenario 2: Porting the Applicati<strong>on</strong> <strong>to</strong> Win32PHP applicati<strong>on</strong>s can also be ported <strong>to</strong> run natively <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Aswith interoperati<strong>on</strong>, few changes need <strong>to</strong> be made <strong>to</strong> the source code.Available opti<strong>on</strong>s are discussed <str<strong>on</strong>g>for</str<strong>on</strong>g> each scenario in separate cases. Each case listssteps required <strong>to</strong> c<strong>on</strong>nect the PHP applicati<strong>on</strong> <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> data source. Alsoincluded are discussi<strong>on</strong>s <strong>on</strong> the differences between the various <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>functi<strong>on</strong>s. When applicable, sample source code is provided <strong>to</strong> illustrate changes thatneed <strong>to</strong> be made.Note If your PHP scripts use <strong>UNIX</strong> system calls extensively (such as frequent use ofexec, passthru, popen, or the backtick (`)), porting them <strong>to</strong> Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g><strong>UNIX</strong>/Interix may be a suitable opti<strong>on</strong> because Interix has more support <str<strong>on</strong>g>for</str<strong>on</strong>g> the desiredsystem calls. Chapter 2, "Envisi<strong>on</strong>ing Phase," provides a more detailed discussi<strong>on</strong> ofwhen choosing Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> would be more appropriate when moving<strong>to</strong> a Windows-based plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.You will need the following <strong>to</strong> implement this opti<strong>on</strong> (porting PHP applicati<strong>on</strong>s <strong>to</strong>Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>/<strong>SQL</strong> <strong>Server</strong>):● A port of PHP <str<strong>on</strong>g>for</str<strong>on</strong>g> Interix downloadable from Interop Systems athttp://www.interopsystems.com/<strong>to</strong>ols/warehouse.htm, which includes the capabilityof using DBLib, CTLib and ODBC. The PHP distributi<strong>on</strong> will have <strong>to</strong> be compiled<str<strong>on</strong>g>for</str<strong>on</strong>g> using a specific database c<strong>on</strong>nectivity library.● A c<strong>on</strong>nectivity driver <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. This is provided by the port ofFreeTDS <strong>on</strong> Interix and is downloadable from Interop Systems athttp://www.interopsystems.com/<strong>to</strong>ols/db.htm. FreeTDS provides three c<strong>on</strong>nectivityopti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> the PHP applicati<strong>on</strong> <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. Twoopti<strong>on</strong>s go through the libraries DBLib and CTLib, which provide c<strong>on</strong>nectivity <strong>to</strong>both Sybase and <strong>SQL</strong> <strong>Server</strong>. The third is the ODBC driver, which can be used <strong>to</strong>access any ODBC database (including <strong>SQL</strong> <strong>Server</strong>).This technology opti<strong>on</strong>, however, has not been fully tested as a part of development ofthis soluti<strong>on</strong> and there<str<strong>on</strong>g>for</str<strong>on</strong>g>e has not been detailed further.PHP ModulesPHP c<strong>on</strong>tains a rich set of opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> interfacing with comm<strong>on</strong> proprietary databases,including <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. These interfaces are available through PHP as internalfuncti<strong>on</strong>s or extensi<strong>on</strong>s. The database-related functi<strong>on</strong>s are grouped in<strong>to</strong> modules which


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 239must be compiled in<strong>to</strong> the PHP installati<strong>on</strong> be<str<strong>on</strong>g>for</str<strong>on</strong>g>e use. These modules are enabled byspecifying them in the c<strong>on</strong>figurati<strong>on</strong> file (php.ini).Figure 13.1PHP modules (functi<strong>on</strong>s) that can access <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Figure 13.2PHP modules (functi<strong>on</strong>s) that can access <strong>SQL</strong> <strong>Server</strong>The following modules are comm<strong>on</strong>ly used with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases. Each is discussed indetail in this chapter:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>(ORA) functi<strong>on</strong>sORA is a set of functi<strong>on</strong>s used <strong>to</strong> access <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases.The php_oracle value in the php.ini file (extensi<strong>on</strong>=php_oracle.dll) is used <strong>to</strong>enable functi<strong>on</strong>s. The functi<strong>on</strong>s in this module can be identified by the ora_ prefix,such as ora_log<strong>on</strong>().● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> 8 (OCI8) functi<strong>on</strong>s


240 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHP●OCI8 is a set of functi<strong>on</strong>s based <strong>on</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Call Interface (OCI) used <strong>to</strong> access<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases, including 8i and 9i releases. This module is more flexible thanthe standard <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> functi<strong>on</strong>s.The php_oci8 value in the php.ini file (extensi<strong>on</strong>=php_oci8.dll) is used <strong>to</strong> enablethe functi<strong>on</strong>s. The set of functi<strong>on</strong>s that are in this module can be identified by theoci_ prefix, such as oci_log<strong>on</strong>(). Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e PHP 5.0, every oci_ functi<strong>on</strong> was namedwith an oci prefix. Although the functi<strong>on</strong>s with the oci prefix are still available, theyare now deprecated.ODBC functi<strong>on</strong>sA modified versi<strong>on</strong> of ODBC that provides a unified driver <str<strong>on</strong>g>for</str<strong>on</strong>g> native support <str<strong>on</strong>g>for</str<strong>on</strong>g>several databases is available <str<strong>on</strong>g>for</str<strong>on</strong>g> PHP. ODBC support is integrated with PHP and,unlike the modules needed <str<strong>on</strong>g>for</str<strong>on</strong>g> ORA and OCI8, no extensi<strong>on</strong>s need <strong>to</strong> be specified.ODBC has the advantage of allowing applicati<strong>on</strong>s <strong>to</strong> be written which, theoretically,are independent from the RDBMS. If the RDBMS changes, <strong>on</strong>ly the driver willneed <strong>to</strong> be changed, not the code.ODBC functi<strong>on</strong> calls are handled by a driver manager that passes the calls <strong>to</strong> aspecific driver <str<strong>on</strong>g>for</str<strong>on</strong>g> the target database <str<strong>on</strong>g>for</str<strong>on</strong>g> executi<strong>on</strong>. The iODBC driver manager iscomm<strong>on</strong>ly used with PHP <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> databases <strong>on</strong> Windows. iODBC(h ttp://www.iodbc.org) is an open source ODBC driver manager and the SDK ismaintained by Open Link Software (http://www.openlinksw.com). iODBC calls usean odbc_ prefix. For example, odbc_c<strong>on</strong>nect() utilizes the ODBC driver manager.Another open source project, named after the unixODBC project, has developed adriver manager called unixOD BC (http://www.unixodbc.org). The unixODBC callsuse the three-letter <strong>SQL</strong> prefix. For example, <strong>SQL</strong>c<strong>on</strong>nect() uses the unixODBCdriver manager.Note The functi<strong>on</strong> phpinfo() can be called <strong>to</strong> reveal the extensi<strong>on</strong>s that have beenloaded in<strong>to</strong> PHP. A simple script c<strong>on</strong>taining the following line is sufficient <strong>to</strong> implementthis call:Scenario 1: Interoperating PHP <strong>on</strong> <strong>UNIX</strong> with<strong>SQL</strong> <strong>Server</strong>It is possible <strong>to</strong> interoperate between PHP applicati<strong>on</strong>s in a <strong>UNIX</strong> envir<strong>on</strong>ment and<strong>SQL</strong> <strong>Server</strong> databases using Microsoft® <strong>SQL</strong> <strong>Server</strong> functi<strong>on</strong>s or through an ODBCinterface. Each API has its own functi<strong>on</strong> calls <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the database and executestatements. These APIs vary in support <str<strong>on</strong>g>for</str<strong>on</strong>g> comm<strong>on</strong> functi<strong>on</strong>s such as those related <strong>to</strong>cursors and statements.Case 1: Interoperating a PHP Applicati<strong>on</strong> Using ORAFuncti<strong>on</strong>sIf the existing PHP soluti<strong>on</strong> uses ORA functi<strong>on</strong>s, then the best alternative is <strong>to</strong> replacethem with Microsoft <strong>SQL</strong> <strong>Server</strong> (MS<strong>SQL</strong>) functi<strong>on</strong>s. This modificati<strong>on</strong> will requirereplacing the current driver with <strong>on</strong>e that supports the MS<strong>SQL</strong> functi<strong>on</strong>s. One of thedrivers that can be used is FreeTDS (http://www.freetds.org).FreeTDS is a set of libraries <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> and Linux that allows programs <strong>to</strong> interact withMicrosoft <strong>SQL</strong> <strong>Server</strong>. Using the FreeTDS libraries, PHP's mssql_xxx() functi<strong>on</strong>s can beused <strong>to</strong> directly access a <strong>SQL</strong> <strong>Server</strong> databasefrom a <strong>UNIX</strong> or Linux computer. FreeTDS


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 241is an open source implementati<strong>on</strong> of the Tabular Data Stream pro<strong>to</strong>col used by<strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> its clients. The FreeTDS C libraries are freely available under the terms ofthe GNU GPL license.The pro<strong>to</strong>col versi<strong>on</strong> also affects how database servers interpret commands. Microsoft<strong>SQL</strong> <strong>Server</strong> 2000 is known <strong>to</strong> behave differently with versi<strong>on</strong>s 4.2 and 8.0 of FreeTDS.versi<strong>on</strong> 8.0 is recommended <str<strong>on</strong>g>for</str<strong>on</strong>g> compatibility with <strong>SQL</strong> <strong>Server</strong> <strong>to</strong>ols. To interoperate a PHP applicati<strong>on</strong> using ORA functi<strong>on</strong>ality, follow thesecomm<strong>on</strong> steps:1. Install the FreeTDS <strong>SQL</strong> <strong>Server</strong> libraries.D ownload the source code from http://www.freetds.org/software.html. Theinstallati<strong>on</strong> process is very similar <strong>to</strong> that detailed in Appendix D, "InstallingComm<strong>on</strong> Drivers and Applicati<strong>on</strong>s," except that the installati<strong>on</strong> is occurring in <strong>UNIX</strong>instead of Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>.Note FreeTDS should be compiled with the --enable-msdblib opti<strong>on</strong>.2. Recompile PHP <strong>to</strong> use MS<strong>SQL</strong> functi<strong>on</strong>s.Refer <strong>to</strong> http://www.free tds.org/userguide/php.htm <str<strong>on</strong>g>for</str<strong>on</strong>g> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong>compiling PHP.Note PHP should be c<strong>on</strong>figured with the --with-mssql[=DIR] switch, where DIR isthe locati<strong>on</strong> of the FreeTDS libraries. For example, from the PHP source direc<strong>to</strong>ry,type:./c<strong>on</strong>figure --with-mssql=/usr/local/freetds3. Enable MS<strong>SQL</strong> functi<strong>on</strong>s.Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e MS<strong>SQL</strong> functi<strong>on</strong>s can be used, they must be enabled and initialized <str<strong>on</strong>g>for</str<strong>on</strong>g> useby uncommenting or adding the following line in the initializati<strong>on</strong> file php.ini.extensi<strong>on</strong>=php_mssql.dll4. Verify the installati<strong>on</strong>.Verify that the module i s installed by executing the phpinfo() functi<strong>on</strong>. MS<strong>SQL</strong>should appear in the list of modules.5. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.Refer <strong>to</strong> chapter 11, "Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> adetailed discussi<strong>on</strong> <strong>on</strong> modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.6. Modify the PHP applicati<strong>on</strong> code.The following sample sour ce code is used <strong>to</strong> illustrate the changes required whenmigrating PHP code from ORA functi<strong>on</strong>s <strong>to</strong> MS<strong>SQL</strong> functi<strong>on</strong>s. Pay specialattenti<strong>on</strong> <strong>to</strong> the differences between these code secti<strong>on</strong>s.Note MS<strong>SQL</strong> does not have functi<strong>on</strong>s <strong>to</strong> create and drop cursors. Implicitcursorsare used <strong>to</strong> handle results returned.


242 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHPThe following example is sample ORA-based PHP code that executes a simplequery and retrieves results using a cursor operati<strong>on</strong>:The following example is the same code modified <strong>to</strong> MS<strong>SQL</strong>-based PHP code:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 243$mycursor = mssql_query($sql);// Display in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>while ($row = mssql_fetch_array($mycursor)){echo "RESULT: " . $row['last_name'] . ", " . $row['salary'] . "\n";}// Close c<strong>on</strong>necti<strong>on</strong>mssql_close($c<strong>on</strong>n);?>Database server in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> can also be referenced from freetds.c<strong>on</strong>f, as shown inthe following c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>./* freetds.c<strong>on</strong>f[<strong>SQL</strong><strong>Server</strong>]host = win2kss1port = 1433tds versi<strong>on</strong> = 8. 0*/To use the freetds.c<strong>on</strong>f entry, the c<strong>on</strong>necti<strong>on</strong> code will change as follows:// specify path <strong>to</strong> fileputenv(FREETDSCONF=/usr/local/freetds.c<strong>on</strong>f’)$c<strong>on</strong>n=mssql_c<strong>on</strong>nect(‘<strong>SQL</strong><strong>Server</strong>’, $username, $password);The following table provides a mapping between key ORA functi<strong>on</strong>s and the respectiveMS<strong>SQL</strong> functi<strong>on</strong>s. ORA functi<strong>on</strong>s that do not have a matching MS<strong>SQL</strong> functi<strong>on</strong> aredenoted with a hyphen. A discussi<strong>on</strong> of handling these disparate functi<strong>on</strong>s appears in the"Comm<strong>on</strong> Functi<strong>on</strong> Translati<strong>on</strong> Issues" secti<strong>on</strong> later in this chapter.Table 13.1: Mapping Between ORA and MS<strong>SQL</strong> Functi<strong>on</strong>sOperati<strong>on</strong> Task ORA functi<strong>on</strong> MS<strong>SQL</strong> functi<strong>on</strong>C<strong>on</strong>necti<strong>on</strong> Open c<strong>on</strong>necti<strong>on</strong> ora_log<strong>on</strong>() mssql_c<strong>on</strong>nect()Close c<strong>on</strong>necti<strong>on</strong> ora_logoff() mssql_close()Persistent ora_plog<strong>on</strong>() mssql_pc<strong>on</strong>nect()c<strong>on</strong>necti<strong>on</strong>CursorOpen cursor ora_open() -Close cursor ora_close() -Pa rsing Parse statement ora_parse( ) -Binding Bind variable ora_bind() mssql_bind()Executi<strong>on</strong>Execute statement ora_exec() mssql_execute()mssql_query()Prepare and ora_do() mssql_execute()executemssql_query()Fet ching Fetch rowora_fetch()ora_fetch_in<strong>to</strong>mssql_fetch_row()mssql_fetch_array()Fetch column ora_getcolumn() mssql_fetch_fieldTransacti<strong>on</strong>Commi<strong>to</strong>ra_commit<strong>on</strong>() -Managemen<strong>to</strong>ra_commi<strong>to</strong>ff()


244 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHPOperati<strong>on</strong> Task ORA functi<strong>on</strong> MS<strong>SQL</strong> functi<strong>on</strong>ora_commit()Rollbackora_rollback() -Error Handling Error checking ora_error()-ora_errorcode()OthersName of result ora_columnname() mssql_field_name()columnSize of result ora_columnsize() mssql_field_length()columnDatatype of result ora_columntype() mssql_field_type()columnNumber of rowseffectedora_numrows() mssqp_num_rows()Number of columns ora_numcols() mssql_num_fields()returnedCase 2: Interoperating a PHP Applicati<strong>on</strong> Using OCI8Functi<strong>on</strong>s To interoperate using OCI8, follow these comm<strong>on</strong> steps:As with Case 1 "Interoperating a PHP Applicati<strong>on</strong> Using ORA Functi<strong>on</strong>s", the best alternative<str<strong>on</strong>g>for</str<strong>on</strong>g> OCI8 functi<strong>on</strong>s is <strong>to</strong> replace them with MS<strong>SQL</strong> calls. Most of the steps are the samebetween this procedure and the p rocedure in the "Case 1: Interoperating a PHP Applicati<strong>on</strong>Using ORA F uncti<strong>on</strong>s" secti<strong>on</strong> of this scenario. As a result, these steps are not described indetail here.1. Install the FreeTDS <strong>SQL</strong> <strong>Server</strong> libraries.2. Compile PHP <strong>to</strong> use MS<strong>SQL</strong>APIs.3. Enable MS<strong>SQL</strong> functi<strong>on</strong>s within php.ini.4. Verify the installati<strong>on</strong> using phpinfo().5 . Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.Refer <strong>to</strong> Chapter 11, "Developin g: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> adetailed discussi<strong>on</strong> <strong>on</strong> modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.6. Modify applicati<strong>on</strong> code <strong>to</strong> reflect the new drivers.The following sample source code is used <strong>to</strong> illustrate the changes required in PHPcode when replacing OCI8 functi<strong>on</strong>s with MS<strong>SQL</strong> functi<strong>on</strong>s.The following example is the original OCI8-based PHP code:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 245$sql1 = OCIParse($c<strong>on</strong>n, "INSERT INTO countries VALUES (‘US‘,‘United States ofAmerica’, 2)");OCIExecute($sql1);// Insert <strong>SQL</strong> statement with binding$var1 = ‘MX’;$var2 = ‘Mexico”;$var3 = 3;$sql2 = OCIParse($c<strong>on</strong>n, "INSERT INTO countries VALUES (:bind1, :bind2,:bind3); ");OCIBindByName($sql2, ":bind1", $var1);OCIBindByName($sql2, ":bind2", $var2);OCIBindByName($sql2, ":bind3", $var3);OCIExecute($sql2);echo OCIRowCount($sql2) . " rows inserted. ";// CommitOCICommit($c<strong>on</strong>n);// Close c<strong>on</strong>necti<strong>on</strong>OCILogoff($c<strong>on</strong>n);?>The following example is the same PHP source code modified <strong>to</strong> use the MS<strong>SQL</strong>drivers. Note the difference in the commit functi<strong>on</strong>.


246 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHP// Close c<strong>on</strong>necti<strong>on</strong>mssql_close($c<strong>on</strong>n);?>Table 13.2 maps the equivalent calls between OCI8 and MS<strong>SQL</strong> functi<strong>on</strong>s. A hyphen isused when a similar functi<strong>on</strong> does not exist in MS<strong>SQL</strong>. A discussi<strong>on</strong> <strong>on</strong> handling thesedisparate functi<strong>on</strong>s is available in the "Comm<strong>on</strong> Functi<strong>on</strong> Translati<strong>on</strong> Is sues" secti<strong>on</strong> laterin this chapter.Table 13.2: Mapping Between OCI8 and MS<strong>SQL</strong> Functi<strong>on</strong>sOperati<strong>on</strong> Task OCI8 Functi<strong>on</strong>s MS<strong>SQL</strong> Functi<strong>on</strong>sC<strong>on</strong>necti<strong>on</strong> Open c<strong>on</strong>necti<strong>on</strong> ociLog<strong>on</strong>() mssql_c<strong>on</strong>nect()Close c<strong>on</strong>necti<strong>on</strong> ociLogoff() mssql_close()Persistent ociPLog<strong>on</strong>() mssql_pc<strong>on</strong>nect()c<strong>on</strong>necti<strong>on</strong>Cursor Open cursor ociNewCursor() -Close cursor ociFreeCursor() -Statement Free statement oci_free_statement() mssql_free_statement()Parsing Parse statement ociParse() -Executi<strong>on</strong>ExecuteociExecute()mssql_execute()statementmssql_query()Fetching Fetch row ociFetch() mssql_fetch_row()Transacti<strong>on</strong>ManagementCommitRollbackociCommit()ociRollback()--Error Error checking ociError()-HandlingOthersName of result ociColumnName() mssql_field_name()columnSize of result ociColumnSize() mssql_field_length()columnDatatype of ociColumnType() mssql_field_type()result columnNumber of rows ociRowCount() mssql_num_rows()effectedNumber of ociNumCols() mssql_num_fields( )columns returnedCase 3: Interoperating a PHP Applicati<strong>on</strong> UsingODBC Functi<strong>on</strong>sWhile migrating from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, no cha nges will be needed <strong>to</strong> the ODBCcalls themselves; the availability of <strong>SQL</strong> <strong>Server</strong>-specific drivers <str<strong>on</strong>g>for</str<strong>on</strong>g> the <strong>UNIX</strong> envir<strong>on</strong>mentand the capabilities of the dr iver manager <strong>to</strong> work with these drivers definethe changesthat must be made. The best choice <str<strong>on</strong>g>for</str<strong>on</strong>g> interoperating with <strong>SQL</strong> <strong>Server</strong> is offered by the


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 247FreeTDS driver, which is supported by the iODBC driver manager of the sourceenvir<strong>on</strong>ment.Other opti<strong>on</strong>s available include Easysoft's ODBC-ODBC Bridge (OOB) and OpenLink'sUniversal Data Access drivers. To interoperate using ODBC functi<strong>on</strong>s, follow these comm<strong>on</strong> steps:The following steps are required <strong>to</strong> interoperate PHP applicati<strong>on</strong>s with <strong>SQL</strong> <strong>Server</strong>.1. If needed, install ODBC software.It is assumed that the iODBC driver manager is alre ady installed and is being used<strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. If this is not true, then either the iODBC or the unixODBCdriver manager must be installed.The iODBC driver manager can be downloade d fromhttp://www.openlinksw.com/iodbc/. Installati<strong>on</strong> instru cti<strong>on</strong>s are availableinAppendix D, "Installing Comm<strong>on</strong> Drivers and Applicati<strong>on</strong>s."The unixODBC driver manager can be downloaded from http://www.u nixodbc.org/ .Installati<strong>on</strong> instructi<strong>on</strong>s are also available in Appendix D, "Installing Comm<strong>on</strong>Drivers and Applicati<strong>on</strong>s."2. Install the <strong>SQL</strong> <strong>Server</strong> driver.The most popular ODBC driver <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> from a <strong>UNIX</strong> operatingsystem is FreeTDS. FreeTDS is an open source implementati<strong>on</strong> of TDS that allows<strong>UNIX</strong>-based programs native access <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. OpenLink also offers drivers<str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> that use the FreeTDS implementati<strong>on</strong> of TDS. Installati<strong>on</strong>instructi<strong>on</strong>s are located in Appendix D, "Installing Comm<strong>on</strong> Drivers andApplicati<strong>on</strong>s."An ODBC-ODBC bridge <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> is available from Easysoft. For detailedinstructi<strong>on</strong>s <strong>on</strong> enabling ODBC support under PHP, refer <strong>to</strong>http://www.easysoft.com/produ cts/2002/apache.phtml.OpenLink (http://www.openlinks w.com) also offers single-tier and multitierUniversal Data Access drivers.3. Recompile PHP <strong>to</strong> use ODBC functi<strong>on</strong>s.To be capable <strong>to</strong> use the <strong>SQL</strong> <strong>Server</strong> driver, PHP must be recompiled with ODBCfuncti<strong>on</strong>s. This procedure will vary based <strong>on</strong> the ODBC driver that is installed.Refer the following resources <str<strong>on</strong>g>for</str<strong>on</strong>g> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.● FreeTDS — http: //www.freetds.org/userguide/php.htm● Easysoft — http://www.easysoft.com/products/2002/apache.phtml● OpenLink — http://docs.openlinksw.com4. C<strong>on</strong>figure the Data Source Name (DSN).ODBC needs an ODBC data source <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the database. The DSN isgenerally defined in an odbc.ini file that the driver manager uses <strong>to</strong> load the ODBCdriver.When using FreeTDS, the DSN can also be c<strong>on</strong>figured by modifying the odbc.inifile. A <strong>SQL</strong> <strong>Server</strong> DSN should be similarly c<strong>on</strong>figured <strong>to</strong> the following example.[ODBC Data Sources]SS_HR_DB=Sample MS <strong>SQL</strong><strong>Server</strong>[SS_HR_DB]Driver=/usr/local/freetds/lib/libtdsodbc.soDescripti<strong>on</strong>=<strong>SQL</strong> <strong>Server</strong> 2000<strong>Server</strong>=win2kdbp1


248 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHPPort=1433Database=hrappLog<strong>on</strong>ID=davebPassword=cougar5. Check the c<strong>on</strong>necti<strong>on</strong>.In iODBC, the command line query program odbctest can be used <strong>to</strong> test the DSNc<strong>on</strong>nectivity. If using unixODBC, the isql utility can be used <strong>to</strong> do this.6. Modify the applicati<strong>on</strong> source code <strong>to</strong> reflect the new data source.Because ODBC is a generic interface <strong>to</strong> any database, no changes are required inthe applicati<strong>on</strong> code except <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. The properDSN has already been set up in an earlier step.The following PHP code snippet uses the ODBC module <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>data source, and it should be similar <strong>to</strong> code in the existing soluti<strong>on</strong>.When migrated <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the c<strong>on</strong>necti<strong>on</strong> string will reflect thechanges that follow.Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.Refer <strong>to</strong> Chapter 11, "Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> adetailed discussi<strong>on</strong> <strong>on</strong> modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.Table 13.3 is a listing of the ODBC functi<strong>on</strong> calls that are used in PHP code <strong>to</strong> work withdatabases.Table 13.3: ODBC Functi<strong>on</strong> Calls in PHPOperati<strong>on</strong> Task ODBC Functi<strong>on</strong>C<strong>on</strong>necti<strong>on</strong> Open c<strong>on</strong>necti<strong>on</strong> odbc_c<strong>on</strong>nect()Open persistent c<strong>on</strong>necti<strong>on</strong> odbc_pc<strong>on</strong>nect()Close c<strong>on</strong>necti<strong>on</strong>odbc_close()Get c<strong>on</strong>necti<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> odbc_data_source()Parsing Prepare statement odbc_prepare()Cursor Get cursor name odbc_cursor()Executi<strong>on</strong> Execute statement odbc_execute()Prepare and execute odbc_exec()odbc_do()


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 249Operati<strong>on</strong> Task ODBC Functi<strong>on</strong>Fetching Fetch row odbc_fetch_row()odbc_fetch_array()odbc_fetch_in<strong>to</strong>()odbc_fetch_object()Fetch column -Transacti<strong>on</strong> Management Commit odbc_commit()Rollbackodbc_rollback()Error Handling Error Checking odbc_error()Get last error odbc_errormsq()Others Name of result column odbc_field_name()Name of table column odbc_columns()Size of result column odbc_field_len()Datatype of result column odbc_field_type()Number of rows effected odbc_num_rows()Number of columns odbc_num_fields()returnedComm<strong>on</strong> Functi<strong>on</strong> Translati<strong>on</strong> IssuesThough <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> share a great deal of functi<strong>on</strong>ality, some databaseoperati<strong>on</strong>s differ. This secti<strong>on</strong> discusses some of the differences between coding withPHP extensi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Handling Transacti<strong>on</strong>sThe <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> PHP extensi<strong>on</strong> module supports transacti<strong>on</strong>s using the following functi<strong>on</strong>calls:● ora_commit()● ora_commi<strong>to</strong>ff()● ora_commit<strong>on</strong>()● ora_rollback()The OCI PHP extensi<strong>on</strong> module supports transacti<strong>on</strong>s using the following functi<strong>on</strong> calls.● OCICommit()● OCIRollBack()MS<strong>SQL</strong> API does not provide commit or rollback functi<strong>on</strong>s. These functi<strong>on</strong>s can beachieved using the following example code:// Here $db is a PHP variable <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>necti<strong>on</strong> object//To begin transacti<strong>on</strong>$sql = "begin tran";$result= mssql_query($sql,$db);//To commit transacti<strong>on</strong>$sql = "commit tran";$result = mssql_query($sql,$db);


250 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHP//To rollback transacti<strong>on</strong>$sql = "rollback tran";$result = mssql_query($sql,$db);<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Cursors$c<strong>on</strong>n=mssql_c<strong>on</strong>nect("myhost","user","pwd");mssql_select_db("hr",$c<strong>on</strong>n);// create the select statement$sqlquery="SELECT companyName FROM Cus<strong>to</strong>mers;";// activate the query and retrieve the result set$results= mssql_query($sqlquery);// Do a row fetch from the result set <str<strong>on</strong>g>for</str<strong>on</strong>g> displaywhile ($row=mssql_fetch_array($results)){echo $row['companyName']."\n";}<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> requires using cursors with SELECT statements, regardless of the number ofrows requested from the database. In <strong>SQL</strong> <strong>Server</strong>, a SELECT statement that is notdisclosed <strong>on</strong> a cursor returns rows <strong>to</strong> the client as a default result set. This is an efficientway <strong>to</strong> return data <strong>to</strong> a client applicati<strong>on</strong>.When porting a PL/<strong>SQL</strong> procedure from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, first determine whether cursors areneeded <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the same functi<strong>on</strong> in Transact-<strong>SQL</strong>. If the cursor is used <strong>on</strong>ly <strong>to</strong> returna set of rows <strong>to</strong> the client applicati<strong>on</strong>, use a n<strong>on</strong>-cursor SELECT statement in Transact-local procedure variables, use cursors in Transact-<strong>SQL</strong>.Unlike <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and OCI8 (which have methods <str<strong>on</strong>g>for</str<strong>on</strong>g> explicit use of cursors), MS<strong>SQL</strong> uses<strong>SQL</strong> <strong>to</strong> return a default result set. If the cursor is used <strong>to</strong> load data a row at a time in<strong>to</strong>implicit cursors. Functi<strong>on</strong>s such as mssql_query() and mssql_execute() associate ahandle <strong>to</strong> the returned result, which can be traversed similar <strong>to</strong> an explicit cursor. Thefollowing code shows the use of result set <strong>to</strong> achieve the same functi<strong>on</strong>ality as that of acursor.<strong>SQL</strong> <strong>Server</strong> cursors may also be used <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>on</strong>e of the following reas<strong>on</strong>s:● Updateable cursors● Scrollable, read-<strong>on</strong>ly cursorsNote ODBC Cursor Library cursors build <strong>on</strong> <strong>to</strong>p of default result sets. Be sure <strong>to</strong> fetch<strong>to</strong> the end of the result set quickly <strong>to</strong> free up locks.When you use server cursors, use <strong>SQL</strong>ExtendedFetch <strong>to</strong> fetch in blocks of rowsinstead of a single row at a time. This is the same thing as array-type fetching in<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. This saves <strong>on</strong> round-trip fetches <strong>to</strong> the server. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong><strong>SQL</strong>ExtendedFetch, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqlextendedfetch.asp.Use result sets when you think it will fetch all rows at <strong>on</strong>e time, but use server cursorswhenyou know a result set would not fetch all rows at <strong>on</strong>ce.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 251C<strong>on</strong>necti<strong>on</strong> PoolingWhile PHP does not offer c<strong>on</strong>necti<strong>on</strong> pooling, persistent <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> c<strong>on</strong>necti<strong>on</strong>s canopened with the following API functi<strong>on</strong> calls.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> API: ora_plog<strong>on</strong>()● OCI8 API: ociPLog<strong>on</strong>()To interoperate with <strong>SQL</strong> <strong>Server</strong>, these functi<strong>on</strong>s should be replaced by <strong>on</strong>e of thefollowing functi<strong>on</strong>s, depending up<strong>on</strong> the API used:● ODBC API: odbc_pc<strong>on</strong>nect()● MS<strong>SQL</strong> API: mssql_pc<strong>on</strong>nect()Unlike c<strong>on</strong>necti<strong>on</strong> pooling, a persistent c<strong>on</strong>necti<strong>on</strong> is local <strong>to</strong> a process and cannot beshared between different processes.S<strong>to</strong>red ProceduresS<strong>to</strong> red procedures can be handled by the MS<strong>SQL</strong> API as well as the ORA and OCI8APIs. The following example shows sample s<strong>to</strong>red procedures using MS<strong>SQL</strong> calls.// Create Query <str<strong>on</strong>g>for</str<strong>on</strong>g> S<strong>to</strong>red Procedure In Code// S<strong>to</strong>red procedure name: CustOrdersDetail from Northwind database$stmt = mssql_init("CustOrdersDetail",$c<strong>on</strong>n);bemssql_select_db("Northwind", $c<strong>on</strong>n);// Parameter values$orderid = 1;// Binding parameter value <strong>to</strong> s<strong>to</strong>red proceduremssql_bind($stmt, "@OrderID", $orderid, <strong>SQL</strong>INT4);// Execute <strong>SQL</strong> Statement & Capture Results$result = mssql_execute($stmt);// Fetch return data and place in<strong>to</strong> array <str<strong>on</strong>g>for</str<strong>on</strong>g> accesswhile($row = mssql_fetch_array($result)){// Assign Variables$unitprice = $row["UnitPrice"];echo "Unit Price" . $unitprice;$quantity = $row["Quantity"];echo "Quantity" . $quantity;$discount = $row["Discount"];echo "Discount" . $discount;$price = $row["ExtendedPrice"];echo "Price" . $price;}


252 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> PHPScenario 2: Porting the Applicati<strong>on</strong> <strong>to</strong> Win32Because PHP is a cross-plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m language, porting applicati<strong>on</strong>s from a <strong>UNIX</strong>envir<strong>on</strong>ment <strong>to</strong> Windows is not much more complex than the steps required <str<strong>on</strong>g>for</str<strong>on</strong>g>interoperati<strong>on</strong>. The strategy, steps, and actual changes required are very similar <strong>to</strong> thosediscussed <str<strong>on</strong>g>for</str<strong>on</strong>g> interoperati<strong>on</strong>. The <strong>on</strong>ly additi<strong>on</strong>al step is installing PHP and the applicati<strong>on</strong>code in the Windows envir<strong>on</strong>ment.Case 1: Porting a PHP Applicati<strong>on</strong> using ORA Functi<strong>on</strong>sMost of the following steps are covered in more detail in the "Case 1: Interoperating aPHP Applicati<strong>on</strong> Using ORA Functi<strong>on</strong>s" secti<strong>on</strong> of Scenario 1. To port the applicati<strong>on</strong> using ORA functi<strong>on</strong>s, follow these comm<strong>on</strong> steps:1. Install PHP <strong>on</strong> target Windows server.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> installing PHP, refer <strong>to</strong>http://uk2.php.net/manual/en/install.php.2. Install <strong>SQL</strong> <strong>Server</strong> libraries.Instead of the FreeTDS libraries, the Windows-based libraries offered by Microsoftin <strong>SQL</strong> Client Tools can be installed <strong>on</strong> the system where PHP is installed. TheClient Tools can be installed from the MS <strong>SQL</strong> <strong>Server</strong> CD or by copyingntwdblib.dll from \winnt\system32 <strong>on</strong> the server <strong>to</strong> \winnt\system32 <strong>on</strong> the targetWindows server. However, copying ntwdblib.dll will <strong>on</strong>ly provide access.C<strong>on</strong>figurati<strong>on</strong> of the client will require installati<strong>on</strong> of all the <strong>to</strong>ols.3. Compile PHP <strong>to</strong> use the MS<strong>SQL</strong> module.4. Enable MS<strong>SQL</strong> functi<strong>on</strong>s in php.ini.5. Verify the installati<strong>on</strong> using phpinfo().6. Transport source code <strong>to</strong> target server.7. Modify the applicati<strong>on</strong>'s source code <strong>to</strong> reflect the MS<strong>SQL</strong> API instead of ORAfuncti<strong>on</strong>s..Case 2: Porting a PHP Applicati<strong>on</strong> Using OCI8 Functi<strong>on</strong>sMost of the steps needed <strong>to</strong> migrate this applicati<strong>on</strong> are discussed in more detail in the"Case 2: Interoperating a PHP Applicati<strong>on</strong> Using OC18 Functi<strong>on</strong>s" secti<strong>on</strong> of Scenario 1.The following steps are required <strong>to</strong> migrate PHP applicati<strong>on</strong>s <strong>to</strong> Windows using OC18functi<strong>on</strong>s. To port the applicati<strong>on</strong> using OCI8 functi<strong>on</strong>s, follow these comm<strong>on</strong> steps:1. Install PHP <strong>on</strong> target Windows server.2. Install <strong>SQL</strong> <strong>Server</strong> libraries from <strong>SQL</strong> Client Tools.3. Compile PHP <strong>to</strong> use the MS<strong>SQL</strong> module.4. Enable MS<strong>SQL</strong> functi<strong>on</strong>s in php.ini.5. Verify the installati<strong>on</strong> using phpinfo().6. Transport the source code <strong>to</strong> the target Windows server.7. Modify the applicati<strong>on</strong> code <strong>to</strong> reflect the MS<strong>SQL</strong> API instead of OCI functi<strong>on</strong>s.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 253Case 3: Porting a PHP Applicati<strong>on</strong> Using ODBC Functi<strong>on</strong>sMost of the steps listed as follows are discussed in more detail in the "Case 3:Interoperating a PHP Applicati<strong>on</strong> Using ODBC Functi<strong>on</strong>s" secti<strong>on</strong> of scenario 1. Thefollowing steps are required <strong>to</strong> migrate PHP applicati<strong>on</strong>s <strong>to</strong> Windows using ODBCfuncti<strong>on</strong>s. To port the applicati<strong>on</strong> using ODBC functi<strong>on</strong>s, follow these comm<strong>on</strong> steps:1. Install PHP <strong>on</strong> target Windows server.2. Install ODBC software.For installati<strong>on</strong> instructi<strong>on</strong>s, refer <strong>to</strong>http://support.microsoft.com/default.aspx?scid=kb;en-us;313008.3. Install the <strong>SQL</strong> <strong>Server</strong> driver.In additi<strong>on</strong> <strong>to</strong> the drivers menti<strong>on</strong>ed <str<strong>on</strong>g>for</str<strong>on</strong>g> interoperati<strong>on</strong>, the Microsoft ODBC driver<str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> may also be used. This driver is available al<strong>on</strong>g with the<strong>SQL</strong> <strong>Server</strong> client CD. Installati<strong>on</strong> instructi<strong>on</strong>s are available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/how<strong>to</strong>sql/ht_install_029l.asp.4. Compile PHP <strong>to</strong> use ODBC in the php.ini file.5. C<strong>on</strong>figure the DSN <strong>to</strong> c<strong>on</strong>nect with the <strong>SQL</strong> <strong>Server</strong> database.6. Check the c<strong>on</strong>necti<strong>on</strong> using command line utilities.7. Transport the source code <strong>to</strong> the target Windows envir<strong>on</strong>ment.8. Modify the applicati<strong>on</strong> source code <strong>to</strong> reflect the MS<strong>SQL</strong> API.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 25514Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> JavaIntroducti<strong>on</strong> and GoalsThis chapter c<strong>on</strong>tains a detailed discussi<strong>on</strong> of changes that must be made <strong>to</strong> Javaapplicati<strong>on</strong>s when the database is migrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> Microsoft® <strong>SQL</strong> <strong>Server</strong>. Atthe c<strong>on</strong>clusi <strong>on</strong> of this chapter, the Java applicati<strong>on</strong> should be capable <strong>to</strong> successfullyc<strong>on</strong>nect <strong>to</strong> t he <strong>SQL</strong> <strong>Server</strong> database that was migrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The soluti<strong>on</strong> canthen be tested.Java is a po rtable language. The capability <str<strong>on</strong>g>for</str<strong>on</strong>g> the Java programming language <strong>to</strong>interact with an RDBMS such as <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> is provided by the JavaDatabase C<strong>on</strong>nectivity (JDBC) API. Applicati<strong>on</strong>s written in Java can execute <strong>SQL</strong>statements, retrieve results, and propagate changes back <strong>to</strong> the underlying data sourceusing the JDBC API.The combinati<strong>on</strong> of the Java plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m and JDBC API allows a program <strong>to</strong> operate <strong>on</strong> anumber of plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms, and with any number of <strong>SQL</strong>-supported databases, withoutmodifying the source code.When migrating from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ment, there will still be somealterati<strong>on</strong>s made <strong>to</strong> the applicati<strong>on</strong>. These basic changes will need <strong>to</strong> be made whetherthe Java applicati<strong>on</strong> interoperates with <strong>SQL</strong> <strong>Server</strong> from a <strong>UNIX</strong> envir<strong>on</strong>ment, or if theJava applicati<strong>on</strong> is ported <strong>to</strong> Windows®.As discussed in the "Define the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> C<strong>on</strong>cept" secti<strong>on</strong> of Chapter 2, "Envisi<strong>on</strong>ingPhase," there are four different strategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> transiti<strong>on</strong>ing applicati<strong>on</strong>s in an<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> project. The strategies are:● Interoperate the applicati<strong>on</strong> with <strong>UNIX</strong>● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft Win32® plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m● Quick p ort using the Microsoft Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mBecause of some of the unique characteristics of Java, some of these strategies aremore logical than others. For instance, because Java can be ported <strong>to</strong> Windows, there isno need <strong>to</strong> rewrite the applicati<strong>on</strong> in the .NET framework or <str<strong>on</strong>g>for</str<strong>on</strong>g> the Win32 envir<strong>on</strong>ment.


256 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> JavaBased <strong>on</strong> the available migrati<strong>on</strong> strategies, two scenarios can be developed <strong>to</strong> migratethe Java applicati<strong>on</strong>. These scenarios are:● Scenario 1: Interoperating Java <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong>If the business requirements do not include eliminating the <strong>UNIX</strong> envir<strong>on</strong>ment, aninteroperati<strong>on</strong> strategy can be implemented quickly. Few, if any, changes need <strong>to</strong>be made <strong>to</strong> the source code and it may be necessary <strong>to</strong> install a new driver <strong>to</strong>allo w the Java applicati<strong>on</strong> <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database. If the migrati<strong>on</strong> isper<str<strong>on</strong>g>for</str<strong>on</strong>g>med in phases or <str<strong>on</strong>g>for</str<strong>on</strong>g> multiple applicati<strong>on</strong>s, interoperati<strong>on</strong> can be used as aninterim step.● Scenario 2: Porting the Applicati<strong>on</strong> <strong>to</strong> Win32Java applicati<strong>on</strong>s can also be ported <strong>to</strong> run natively <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Aswith interoperati<strong>on</strong>, few changes need <strong>to</strong> be made <strong>to</strong> the source code.Scenario 1: Interoperating Java <strong>on</strong> <strong>UNIX</strong> with<strong>SQL</strong> <strong>Server</strong>Interoperati<strong>on</strong> between a <strong>UNIX</strong>-based Java applicati<strong>on</strong> and a <strong>SQL</strong> <strong>Server</strong> database ispossible because of the availability of a driver that interfaces between thesetechnologies. The JDBC driver provides the cross-RDBMS c<strong>on</strong>nectivity needed.Case 1: Interoperating a Java Applicati<strong>on</strong> Using the JDBCDriverBecause of the c<strong>on</strong>structi<strong>on</strong> of the JDBC API, which exposes a comm<strong>on</strong> set of methodsthat are not affected by the change of source database, this type of migrati<strong>on</strong> is usually asimple process. Most changes made relate <strong>to</strong> the c<strong>on</strong>nectivity. To interoperate a Java applicati<strong>on</strong> using the existing JDBC driver, followthese steps:1. Evaluate the current driver.Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e beginning the migrati<strong>on</strong> process, evaluate the existing JDBC driver that is inuse and its capability <strong>to</strong> operate with <strong>SQL</strong> <strong>Server</strong>. Some c<strong>on</strong>siderati<strong>on</strong>s include:● Will the current JDBC driver interoperate with <strong>SQL</strong> <strong>Server</strong>? If this in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> isnot known, check with the vendor. Sun Microsystems also maintains adatabase of <strong>SQL</strong> <strong>Server</strong> compliant JDBC drivers. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer<strong>to</strong> http://servlet.java.sun.com/products/jdbc/drivers.● If the current JDBC driver will interoperate with <strong>SQL</strong> <strong>Server</strong>, what are theper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance characteristics of the driver in the <strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ment?Try <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m pro<strong>to</strong>type tests of the driver <strong>to</strong> ensure that the level ofper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is acceptable.● What features of the driver are utilized by the Java applicati<strong>on</strong>, and arethese supported <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>? For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> specific Javaextensi<strong>on</strong>s used by your JDBC driver, refer <strong>to</strong> your vendor documentati<strong>on</strong>.● What type of JDBC driver is required (Type 1, 2, 3, 4)?If a new driver is needed, there are several different JDBC driverscommercially available. Each has slightly different features and characteristics.Some comm<strong>on</strong>ly used JDBC drivers include:● J<strong>SQL</strong>C<strong>on</strong>nect from J<strong>Net</strong>Direct, which is available athttp://www.jnetdirect.com/products.php?op=jsqlc<strong>on</strong>nect.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 257●<strong>SQL</strong> <strong>Server</strong> 2000 Driver <str<strong>on</strong>g>for</str<strong>on</strong>g> JDBC. Microsoft offers this native driver whichwill work <strong>on</strong> both <strong>UNIX</strong> and Windows. This driver is available athttp://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en.2. Determine how the applicati<strong>on</strong> c<strong>on</strong>nects <strong>to</strong> the data source. C<strong>on</strong>necti<strong>on</strong>s can beachieved using the DriverManager class or with a datasource implementati<strong>on</strong>.●If c<strong>on</strong>nectivity is obtained using the DriverManager class, two changes areneeded <strong>to</strong> c<strong>on</strong>nect with the <strong>SQL</strong> <strong>Server</strong> database. These changes are:● Loading the JDBC driver● Making the c<strong>on</strong>necti<strong>on</strong>The following example shows these changes:// Loading the driverClass.<str<strong>on</strong>g>for</str<strong>on</strong>g>Name("DriverClassName");// Making the C<strong>on</strong>necti<strong>on</strong>String url = "jdbc:odbc:DSN";String user = "sUser";String password = "sPwd";C<strong>on</strong>necti<strong>on</strong> c<strong>on</strong> = DriverManager.getC<strong>on</strong>necti<strong>on</strong>(url, user, password);//……………//…………// Closing the C<strong>on</strong>necti<strong>on</strong>c<strong>on</strong>.close();In this example code, the URL uses the syntaxjdbc::. Using the c<strong>on</strong>necti<strong>on</strong> object c<strong>on</strong>, you cancreate JDBC statements and pass them <strong>to</strong> the RDBMS.●If c<strong>on</strong>nectivity is obtained through a datasource, the applicati<strong>on</strong> server shouldbe appropriately c<strong>on</strong>figured.Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e using a datasource object, it must be deployed. The following listdescribes the deployment steps:1. Create an instance of the DataSource class.2. Set the datasource properties.3. Register the datasource with a naming service that uses the Java Namingand Direc<strong>to</strong>ry Interface (JNDI) API.Datasource deployment is usually per<str<strong>on</strong>g>for</str<strong>on</strong>g>med by the system administra<strong>to</strong>r.A JDBC driver that supports JDBC 2.0 API will provide different types ofdatasource implementati<strong>on</strong>s which can be used <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>necti<strong>on</strong> pooling anddistributed transacti<strong>on</strong>s.To obtain c<strong>on</strong>nectivity, the Java applicati<strong>on</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ms a lookup of thelogicalName. This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> can be retrieved by passing the user nameand password through the getC<strong>on</strong>necti<strong>on</strong>() method. An example of thismethod is presented as follows:C<strong>on</strong>text ctx = new InitialC<strong>on</strong>text();DataSource ds = (DataSource)ctx.lookup("jdbc/db<strong>Server</strong>");C<strong>on</strong>necti<strong>on</strong> c<strong>on</strong> = ds.getC<strong>on</strong>necti<strong>on</strong>("sUser", "sPwd");3. C<strong>on</strong>figure the applicati<strong>on</strong> server.If third-party JDBC drivers are used <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the drivers must beset in the CLASSPATH variable so the driver classes can be loaded. The JDBC


258 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Javadriver installed <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> will install a driver jar file, which c<strong>on</strong>tains driverclasses <str<strong>on</strong>g>for</str<strong>on</strong>g> the database interacti<strong>on</strong>. If the jar file is missing in the classpath, thenthe applicati<strong>on</strong> will flag a 'class not found' excepti<strong>on</strong>.Based <strong>on</strong> the applicati<strong>on</strong>'s architecture, the CLASSPATH must be set. The syntaxof this setting can vary between applicati<strong>on</strong>s, servlets, JSPs, EJBs, and applets.a. For applicati<strong>on</strong>s run directly from the operating system prompt, make sure thatthe driver can be found in the system's CLASSPATH. This can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>medby moving the file <strong>to</strong> its original locati<strong>on</strong>, which is already listed in theclasspath, or adding the driver's current locati<strong>on</strong> <strong>to</strong> the CLASSPATH.b. For applicati<strong>on</strong>s run within the IDE, the driver classpath has <strong>to</strong> be set in thevendor's IDE classpath. Refer <strong>to</strong> your vendor’s IDE documentati<strong>on</strong>.c. For servlets and JSPs run within a servlet/JSP engine such as Tomcat, theclasspath can be set in the vendor's classpath setup screens or by copying thedriver jar file in<strong>to</strong> the LIB folder of the engine’s installati<strong>on</strong>.d. For EJBs, the JDBC driver jar file should also be set in the EJB vendor'sclasspath.e. For applets that run within a Web browser, copy the JDBC driver jar <strong>to</strong> theWeb server root and specify the driver jar file in the applet’s HTML archive tab.The following HTML code example shows this opti<strong>on</strong> used <strong>on</strong> an applet tag.4. If the <strong>SQL</strong> statements passed <strong>to</strong> the JDBC methods use any <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>-specificsyntax, then these items will need <strong>to</strong> be updated <strong>to</strong> reflect T-<strong>SQL</strong> syntax. Migrati<strong>on</strong>of PL/<strong>SQL</strong> <strong>to</strong> T-<strong>SQL</strong> is covered in detail in Chapter 11, "Developing: Applicati<strong>on</strong>s— <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>."5. The metadata in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> returned by the metadata methods should refer <strong>to</strong><strong>SQL</strong> <strong>Server</strong> and the new JDBC Driver.To discover in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about a database, a DatabaseMetaData object must beobtained. ResultSetMetaData provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the ResultSet, such asnumber of columns returned, an individual column's suggested display size,column names, and column types. If any of these metadata are used in theapplicati<strong>on</strong>, they have <strong>to</strong> be validated <str<strong>on</strong>g>for</str<strong>on</strong>g> integrity of the return values.To discover in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about a database, a DatabaseMetaData object must beobtained. The getMetaData method <strong>on</strong> the C<strong>on</strong>necti<strong>on</strong> object returns aDatabaseMetaData object.DatabaseMetaData dbmd = c<strong>on</strong>.getMetaData();ResultSetMetaData provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the ResultSet. Use thegetMetaData method <strong>on</strong> the resultSet <strong>to</strong> get the ResultSetMetaData.ResultSetMetaData rsmd = rs.getMetaData();6. After the applicati<strong>on</strong> changes are complete, create a new release build and fullytest the applicati<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 259Scenario 2 —Porting the Applicati<strong>on</strong> <strong>to</strong> Win32Java is portable, so when the applicati<strong>on</strong> is migrated <strong>to</strong> Windows, the Java languagefeatures remain the same. Changes should be minimal. Most of the changes listed in thefollowing procedure are similar <strong>to</strong> those per<str<strong>on</strong>g>for</str<strong>on</strong>g>med under the interoperati<strong>on</strong> scenariodescribed in the "Scenario 1: Interoperating Java <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong> " secti<strong>on</strong>earlier in this chapter. To port the applicati<strong>on</strong> <strong>to</strong> Win32, follow these comm<strong>on</strong> steps:1. Install Java <strong>on</strong> the Windows server.If the migrati<strong>on</strong> path includes porting the Java applicati<strong>on</strong> <strong>to</strong> the Windowsenvir<strong>on</strong>ment, then the Java applicati<strong>on</strong> server should be installed <strong>on</strong> Windows.Ensure that the hardware satisfies the installati<strong>on</strong> prerequisites <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong>server.2. Determine if the existing JDBC driver will per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the needed functi<strong>on</strong>s, or if a newJDBC driver will be required.3. C<strong>on</strong>figure the applicati<strong>on</strong> server <str<strong>on</strong>g>for</str<strong>on</strong>g> use with Windows. Update the path andclasspath in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>.4. Test the installati<strong>on</strong> of the applicati<strong>on</strong> server using the test utility provided with theapplicati<strong>on</strong> server.5. Determine how the applicati<strong>on</strong> c<strong>on</strong>nects <strong>to</strong> the data source.<strong>SQL</strong> <strong>Server</strong> has two types of authenticati<strong>on</strong>, Windows authenticati<strong>on</strong> and<strong>SQL</strong> <strong>Server</strong> authenticati<strong>on</strong>. When the applicati<strong>on</strong> exists <strong>on</strong> the <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, theWindows authenticati<strong>on</strong> method is not possible without the installati<strong>on</strong> of additi<strong>on</strong>alsoftware such as the Vintela Authenticati<strong>on</strong> Services (VAS) product from Vintela(http://www.vintela.com/products/vas/). However, with the applicati<strong>on</strong> migrated <strong>to</strong>the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, the Windows authenticati<strong>on</strong> feature of <strong>SQL</strong> <strong>Server</strong> can betaken advantage of.Windows authenticati<strong>on</strong> is specified using the c<strong>on</strong>necti<strong>on</strong> propertytrustedAuthenticati<strong>on</strong>. The property may be set in either a driver managerc<strong>on</strong>necti<strong>on</strong> string or a datasource. There is no need <strong>to</strong> specify the user andpassword properties when using trusted authenticati<strong>on</strong>.Windows authenticati<strong>on</strong> can be used by the JDBC clients <strong>on</strong> Windows <strong>on</strong>ly.6. Move the Java code from <strong>UNIX</strong> <strong>to</strong> Windows. All the files and folders which theJava applicati<strong>on</strong> interacts with should be migrated <strong>to</strong> Windows. Make sure that thepaths in the Java applicati<strong>on</strong> and the c<strong>on</strong>figurati<strong>on</strong> files point <strong>to</strong> the corresp<strong>on</strong>dingfolders in the Windows file system. If the Java applicati<strong>on</strong> uses any native codewritten in other languages, then that code also has <strong>to</strong> be migrated <strong>to</strong> Windows.7. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>-specific <strong>SQL</strong> and s<strong>to</strong>red programs will need <strong>to</strong> be rewritten in T-<strong>SQL</strong>syntax. Migrati<strong>on</strong> of PL/<strong>SQL</strong> <strong>to</strong> T-<strong>SQL</strong> is covered in detail in Chapter 11,"Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>."8. The metadata in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> returned by the metadata methods should refer <strong>to</strong><strong>SQL</strong> <strong>Server</strong> and the new JDBC Driver.9. After the applicati<strong>on</strong> changes are complete, create a new release build and fullytest the applicati<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 26115Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Pyth<strong>on</strong>Introducti<strong>on</strong> and GoalsThis chapter c<strong>on</strong>tains a detailed discussi<strong>on</strong> of changes that must be made <strong>to</strong> existingPyth<strong>on</strong> applicati<strong>on</strong>s <strong>to</strong> work with Microsoft® <strong>SQL</strong> <strong>Server</strong>. At the c<strong>on</strong>clusi<strong>on</strong> of thischapter, the Pyth<strong>on</strong> applicati<strong>on</strong> should be capable <strong>to</strong> successfully c<strong>on</strong>nect <strong>to</strong> the<strong>SQL</strong> <strong>Server</strong> database that was migrated from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The soluti<strong>on</strong> can then be tested.As discussed in the "Define the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> C<strong>on</strong>cept" secti<strong>on</strong> of Chapter 2, "Envisi<strong>on</strong>ingPhase," there are four different strategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> transiti<strong>on</strong>ing applicati<strong>on</strong>s in an<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> project. The strategies are:● Interoperate the applicati<strong>on</strong> with <strong>UNIX</strong>● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> Microsoft Win32® Plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m● Quick port using the Microsoft Windows® Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mPyt h<strong>on</strong> is a portable, plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m-independent, and general-purpose language with support<str<strong>on</strong>g>for</str<strong>on</strong>g> writing database client applicati<strong>on</strong>s. Database capabilities are modularized, and theycan be augmented through the use of additi<strong>on</strong>al APIs.Pyth<strong>on</strong> database modules that are based <strong>on</strong> the Database API (DB-API) specificati<strong>on</strong>can be used <strong>to</strong> access relati<strong>on</strong>al databases, including <strong>SQL</strong> <strong>Server</strong> and <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. As l<strong>on</strong>g asthe data base module used <strong>to</strong> access the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database adheres <strong>to</strong> the DB-APIspecificati<strong>on</strong>, porting <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> is straight<str<strong>on</strong>g>for</str<strong>on</strong>g>ward and can be d<strong>on</strong>e with minimalchanges. If the existing database drivers do not meet DB-API specificati<strong>on</strong>s, the driverwill need <strong>to</strong> be replaced and c<strong>on</strong>figured.Because of the cross-plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m capabilities and the use of modular database drivers,some of the migrati<strong>on</strong> strategies are more feasible than others. For example, becausePyth<strong>on</strong> can be ported <strong>to</strong> Windows, there is no need <strong>to</strong> rewrite the applicati<strong>on</strong> in the .NETframework or <str<strong>on</strong>g>for</str<strong>on</strong>g> the Win32 envir<strong>on</strong>ment. Also, because the applicati<strong>on</strong> can run within theWindows envir<strong>on</strong>ment, a quick port using Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> is not necessary inmost cases.Based <strong>on</strong> the available migrati<strong>on</strong> strategies, two scenarios can be developed <strong>to</strong> migratethe Pyth<strong>on</strong> applicati<strong>on</strong>. These scenarios include:


262 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Pyth<strong>on</strong>●●Scenario 1: Interoperating Pyth<strong>on</strong> <strong>on</strong> <strong>UNIX</strong> with <strong>SQL</strong> <strong>Server</strong>If the business requirements do not include eliminating the <strong>UNIX</strong> envir<strong>on</strong>ment, aninteroperati<strong>on</strong> strategy can be implemented quickly. Few changes need <strong>to</strong> bemade <strong>to</strong> the source code, and installing a new driver allows the Pyth<strong>on</strong> applicati<strong>on</strong><strong>to</strong> c<strong>on</strong>nect <strong>to</strong> a <strong>SQL</strong> <strong>Server</strong> database. Interoperati<strong>on</strong> can also be used as aninterim step, if the migrati<strong>on</strong> is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in phases.Scenario 2: Port the Pyth<strong>on</strong> Applicati<strong>on</strong> <strong>to</strong> Win32Pyth<strong>on</strong> applicati<strong>on</strong>s can also be ported <strong>to</strong> run natively <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Aswith interoperati<strong>on</strong>, few changes need <strong>to</strong> be made <strong>to</strong> the source code. Thesechanges are usually related <strong>to</strong> c<strong>on</strong>nectivity issues.Note: If your Pyth<strong>on</strong> applicati<strong>on</strong>s use <strong>UNIX</strong> system calls extensively (such asfrequently calling exec), porting them <strong>to</strong> Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>/Interix may be asuitable opti<strong>on</strong> because Interix has more support <str<strong>on</strong>g>for</str<strong>on</strong>g> the desired system calls. Chapter2, " Envisi<strong>on</strong>ing Phase," provides a more detailed discussi<strong>on</strong> of when choosingWindows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> would be more appropriate when moving <strong>to</strong> a Windowsbasedplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.You will need the following <strong>to</strong> implement this opti<strong>on</strong> (porting Pyth<strong>on</strong> applicati<strong>on</strong>s <strong>to</strong>SFU/<strong>SQL</strong> <strong>Server</strong>):● A port of Pyth<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> interix has been made available by Interop Systems and canbe downloaded from http://www.interopsystems.com/<strong>to</strong>ols/warehouse.htm.● A c <strong>on</strong>nectivity driver <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. This is provided by the port ofFreeTDS <strong>on</strong> Interix and is downloadable from Interop Systems athttp://www.interopsystems .com/<strong>to</strong>ols/db.htm. FreeTDS provides two c<strong>on</strong>nectivityopti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> the Pyth<strong>on</strong> applicati<strong>on</strong>s <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> database. One isa library called CTlib, The other is an ODBC driver.● If you chose the CTLib opti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> your database c<strong>on</strong>nectivity driver, you will needthe Sybase C<strong>on</strong>nectivity Module <str<strong>on</strong>g>for</str<strong>on</strong>g> your Pyth<strong>on</strong> applicati<strong>on</strong> <strong>to</strong> make appropriatecalls <strong>to</strong> CTLib. The source code <str<strong>on</strong>g>for</str<strong>on</strong>g> this Sybase C<strong>on</strong>nectivity Module can obtainfrom Object Craft at http://www.object-craft.com.au/projects/sybase/ . This soluti<strong>on</strong>is not available pre-compiled from Interop Systems but is a simple port <str<strong>on</strong>g>for</str<strong>on</strong>g> a <strong>UNIX</strong>developer.● If you chose ODBC <str<strong>on</strong>g>for</str<strong>on</strong>g> your database c<strong>on</strong>nectivity, you will need an additi<strong>on</strong>alinterface <str<strong>on</strong>g>for</str<strong>on</strong>g> the Pyth<strong>on</strong> applicati<strong>on</strong> <strong>to</strong> make ODBC calls. This is available as acommercial package called mxODBC and can be obtained fromhttp://www.egenix.com.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 263● If you use the ODBC driver, you will also need an ODBC driver manager. Twodifferent ODBC driver managers iODBC and unixODBC are available <str<strong>on</strong>g>for</str<strong>on</strong>g>Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> fromhttp://www.interopsystems.com/<strong>to</strong>ols/warehouse.htm.This technology opti<strong>on</strong> (porting Pyth<strong>on</strong> applicati<strong>on</strong>s <strong>to</strong> SFU), however, has not beenfully tested as a part of development of this soluti<strong>on</strong> and there<str<strong>on</strong>g>for</str<strong>on</strong>g>e has not beendetailed further.Scenario 1: Interoperating Pyth<strong>on</strong> <strong>on</strong> <strong>UNIX</strong> with<strong>SQL</strong> <strong>Server</strong>Two com m<strong>on</strong> modules used <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>necting a Pyth<strong>on</strong> applicati<strong>on</strong> <strong>to</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database inthe <strong>UNIX</strong> envir<strong>on</strong>ment are:● DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2● mxODBCDC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2 (http://www.zope.org/Products/DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>/) does not support <strong>SQL</strong> <strong>Server</strong>, butmxODBC ( http://www.egenix.com/) supports the ODBC interface and can be used with<strong>SQL</strong> <strong>Server</strong>. If the existing applicati<strong>on</strong> uses DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2, this interface will need <strong>to</strong> bereplaced <strong>to</strong> allow c<strong>on</strong>nectivity with <strong>SQL</strong> <strong>Server</strong>.Because ODBC is not database-specific, <strong>on</strong>ly minor modificati<strong>on</strong>s are needed <strong>to</strong> c<strong>on</strong>nect<strong>to</strong> the migrated database.Case 1: Interoperating Using the mxODBC Module To interoperate a Pyth<strong>on</strong>-based applicati<strong>on</strong> using DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2 module with<strong>SQL</strong> <strong>Server</strong>, follow these steps:Note that these steps assume that a DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2 module will be replaced with the mxODBCmodule.1. Install the ODBC driver.In order <str<strong>on</strong>g>for</str<strong>on</strong>g> mxODBC <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, an ODBC driver manager must beinstalled. Two available driver managers are:● iODBC, available at http://www.iodbc.org/.● DataDirect ODBC <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> Plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms, available athttp://www.datadirect.com/techz<strong>on</strong>e/use_case/odbc-unix-sqlservermain/index.ssp.For detailed installati<strong>on</strong> instructi<strong>on</strong>s, refer <strong>to</strong>http://www.datadirect.com/techz<strong>on</strong>e/use_case/odbc-unix-sqlserverinstall/index.ssp.2. Install the mxODBC module based <strong>on</strong> the Pyth<strong>on</strong> versi<strong>on</strong> being used.For installati<strong>on</strong> instructi<strong>on</strong>s, refer <strong>to</strong> http://www.egenix.com/files/pyth<strong>on</strong>/mxODBC-Zope-DA.html#Installati<strong>on</strong>.3. C<strong>on</strong>figure the ODBC driver <strong>to</strong> work with mxODBC through the driver manager.4. Create a <strong>SQL</strong> <strong>Server</strong> data source.To functi<strong>on</strong>, ODBC needs a data source <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the database. The DataSource Name (DSN) is generally defined in an odbc.ini file that is used by thedriver ma nager. The DSN is used by the driver manager <strong>to</strong> load the ODBC driver.iODBC offers a graphical user interface <strong>to</strong> set up the DSN. Complete instructi<strong>on</strong>sare available at http://www.iodbc.org/index.php?page=docs/odbcs<strong>to</strong>ry.


264 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Pyth<strong>on</strong>The DSN can also be c<strong>on</strong>figured by manually modifying the odbc.ini file. Thefollowing example file uses a <strong>SQL</strong> <strong>Server</strong> DSN.[ODBC Data Sources]SS_ HR_DB=Sample MS <strong>SQL</strong><strong>Server</strong>[SS_HR_DB]Driver=/opt/odbc/lib/mxODBC.soDescripti<strong>on</strong>=<strong>SQL</strong> <strong>Server</strong> 2000Database=hrappLog<strong>on</strong>ID=davebPassword=cougarAddress=win2kdbp1,14335. Test the c<strong>on</strong>nectivity.iODBC c<strong>on</strong>tains a utility named odbctest which can be used <strong>to</strong> test DSN entriesand interact with the database by c<strong>on</strong>necting and issuing queries directly withoutany code.The mxODBC package c<strong>on</strong>sists of a test script that can also be used <strong>to</strong> verify thedatabase c<strong>on</strong>nectivity. To per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the test, execute the following command:pyth<strong>on</strong> mx/ODBC/Misc/test.py6. Modify the applicati<strong>on</strong> <strong>to</strong> use mxODBC instead of the existing DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2 API.Note The examples in this secti<strong>on</strong> use the iODBC driver. Syntax may vary slightlybased <strong>on</strong> the ODBC driver that is used in your soluti<strong>on</strong>.There are several, minor changes that may need <strong>to</strong> be made <strong>to</strong> the existing Pyth<strong>on</strong>applicati<strong>on</strong> <strong>to</strong> allow c<strong>on</strong>nectivity with the <strong>SQL</strong> <strong>Server</strong> database. These comm<strong>on</strong>issues that should be modified include:● Import statementsThe import statement, generally found at the head of the applicati<strong>on</strong> code,should be modified <strong>to</strong> include the new database module.If the applicati<strong>on</strong> currently uses the DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2 module, the import statement isas follows:●import DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2This entry should be modified <strong>to</strong> allow <str<strong>on</strong>g>for</str<strong>on</strong>g> the mxODBC module. The importstatement should be changed as follows:import mx.ODBC.iODBCC<strong>on</strong>necti<strong>on</strong> objectsThe c<strong>on</strong>necti<strong>on</strong> object will also need <strong>to</strong> be modified <strong>to</strong> point <strong>to</strong> the new datasource. The current entry should be similar <strong>to</strong> the following example:db = DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2.C<strong>on</strong>nect('scott/tiger@orahrdb')This entry should be modified <strong>to</strong> reflect the new data source. In the followingexample, the DriverC<strong>on</strong>nect() API is used <strong>to</strong> pass additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>to</strong><strong>SQL</strong> <strong>Server</strong>.db = mx.ODBC.iODBC.DriverC<strong>on</strong>nect('DSN=sqlserverDSN;UID=scott;PWD=tiger')This iODBC string will have <strong>to</strong> be modified based <strong>on</strong> the driver manager in use.There are other c<strong>on</strong>necti<strong>on</strong> methods, such as ODBC() and c<strong>on</strong>nect(), whichare also supported by mxODBC. The advantage with DriverC<strong>on</strong>nect() is that itallows more c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, such as the log file name, <strong>to</strong> be passedas part of the c<strong>on</strong>necti<strong>on</strong> string.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 265●Cursor Executi<strong>on</strong>Change the cursor object execute() and executemany() method calls <strong>to</strong> use aquesti<strong>on</strong> mark (?) <str<strong>on</strong>g>for</str<strong>on</strong>g> parameters instead of numeric parameters (:1) or namedparameters (:column_name). The following example should be similar <strong>to</strong> yourexisting Pyth<strong>on</strong> code being used with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.c = db.cursor()custId = "ALFKI"c.execute("Select * from cus<strong>to</strong>mers where cus<strong>to</strong>merID = :1", custId)...id = "123"name = "Bill"desc = "CoffeeShop"●c.execute("insert in<strong>to</strong> categories " + \" (categoryid, categoryName, descripti<strong>on</strong>)" + \"values (:cid,:cname,:cdesc)" \,cid = id , cname = name ,cdesc= desc \)The code should be modified <str<strong>on</strong>g>for</str<strong>on</strong>g> use with <strong>SQL</strong> <strong>Server</strong>. In the following code,note that numeric and named parameters have been replaced.c= db.cursor()custId = "ALFKI"c.execute("Select * from cus<strong>to</strong>mers where cus<strong>to</strong>merID = ?",(custId,))...id = "123"name = "Bill"desc = "CoffeeShop"c.execute("insert in<strong>to</strong> categories" + \" (categoryid, categoryName, descripti<strong>on</strong>)" + \"values (?,?,?)" \,(id, name, desc) \)Cursors — multiple executi<strong>on</strong>sThe executemany() functi<strong>on</strong> is used with DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2 <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m multiple insertswith a single call by passing a list of parameters. For example,cursor.executemany("insert in<strong>to</strong> inven<strong>to</strong>ryinfo values (:1,:2)",\[('Bill','Dallas'),('Bob','Atlanta'),('David','Chicago'), \('Ann','Miami'),('Fin','Detroit'),('Paul','Dallas'),\('Scott','Dallas'),('Mike','Dallas'),('Leigh','Dallas')])For using multiple cursors <strong>on</strong> a c<strong>on</strong>necti<strong>on</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, use thesetc<strong>on</strong>nec<strong>to</strong>pti<strong>on</strong>() method <strong>to</strong> set the <strong>SQL</strong>.CURSOR_TYPE <strong>to</strong><strong>SQL</strong>.CURSOR_DYNAMIC as shown as follows and replace the parameterspecificati<strong>on</strong> style in the executemany() call:# C<strong>on</strong>nect <strong>to</strong> the databasedb = mx.ODBC.iODBC.DriverC<strong>on</strong>nect('DSN=sqlserverDSN;UID=scott;PWD=tiger'# Set <strong>SQL</strong> <strong>Server</strong> c<strong>on</strong>necti<strong>on</strong> opti<strong>on</strong>DB.setc<strong>on</strong>nec<strong>to</strong>pti<strong>on</strong>(<strong>SQL</strong>.CURSOR_TYPE, <strong>SQL</strong>.CURSOR_DYNAMIC)cursor = db.cursor ()cursor.executemany("insert in<strong>to</strong> inven<strong>to</strong>ryinfo values (?,?)",\[('Bill','Dallas'),('Bob','Atlanta'),('David','Chicago'), \


266 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> Pyth<strong>on</strong>●('Ann','Miami'),('Fin','Detroit'),('Paul','Dallas'),\('Scott','Dallas'),('Mike','Dallas'),('Leigh','Dallas')])S<strong>to</strong>red ProceduresThe DB API 2.0 callProc() method <str<strong>on</strong>g>for</str<strong>on</strong>g> executing s<strong>to</strong>red procedures is notimplemented in mxODBC. To overcome this deficiency, a s<strong>to</strong>red procedurecan be executed similar <strong>to</strong> a <strong>SQL</strong> statement using <strong>on</strong>e of the execute methods.However, a requirement in this case is that the s<strong>to</strong>red procedure returns someresult. All calls <strong>to</strong> callProc() need <strong>to</strong> change <strong>to</strong> use cursor.execute, as shownin the following example:c.execute("{call proc_name(?,?)}", (1,2)})7. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.This is a step comm<strong>on</strong> <strong>to</strong> all migrati<strong>on</strong>s. Refer <strong>to</strong> Chapter 11, "Developing:Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> a detailed discussi<strong>on</strong> <strong>on</strong>modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.Scenario 2: Port the Pyth<strong>on</strong> Applicati<strong>on</strong> <strong>to</strong> Win32Because Pyth<strong>on</strong> is a cross-plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m language, porting applicati<strong>on</strong>s from a <strong>UNIX</strong>envir<strong>on</strong>ment <strong>to</strong> Windows is not much more complex than the steps required <str<strong>on</strong>g>for</str<strong>on</strong>g>interoperati<strong>on</strong>. The API used in the discussi<strong>on</strong> <strong>on</strong> porting <strong>to</strong> the Windows envir<strong>on</strong>ment isthe mxODBC. The strategy, steps, and actual changes required are very similar <strong>to</strong> thosediscussed <str<strong>on</strong>g>for</str<strong>on</strong>g> interoperati<strong>on</strong>. Zope offers an ADO adapter <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> theWindows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m which can give better per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance than the use of ODBC. Details <strong>on</strong>this can be obtained from http://zope.org/Members/freiser/ZADODA.Case 1: Porting a Pyth<strong>on</strong> Applicati<strong>on</strong> using mxODBCMost of the following steps are covered in more detail in the "Case 1: InteroperatingUsing the mxODBC Module" secti<strong>on</strong> discussed in scenario 1. To port the applicati<strong>on</strong> <strong>to</strong> Windows, follow these steps:1. Download Pyth<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> Windows from http://www.pyth<strong>on</strong>.org.2. Install Pyth<strong>on</strong> <strong>on</strong> Windows.3. Add the Pyth<strong>on</strong> folder <strong>to</strong> the Windows CLASSPATH envir<strong>on</strong>ment variable.4. Install the appropriate mxODBC <str<strong>on</strong>g>for</str<strong>on</strong>g> the versi<strong>on</strong> of Pyth<strong>on</strong> installed.5. Create an ODBC DSN <str<strong>on</strong>g>for</str<strong>on</strong>g> the target database.Create an ODBC data source <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>. After the DSN is created,a Pyth<strong>on</strong> applicati<strong>on</strong> using mxODBC can c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> and run queries.6. Transport source code <strong>to</strong> the target server.7. Update the applicati<strong>on</strong> code.If your applicati<strong>on</strong> uses DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2, then the applicati<strong>on</strong> changes required will besimilar <strong>to</strong> those discussed in the "Scenario 1: Interoperating Pyth<strong>on</strong> <strong>on</strong> <strong>UNIX</strong> with<strong>SQL</strong> <strong>Server</strong>" secti<strong>on</strong> earlier in this chapter. Some variati<strong>on</strong>s based <strong>on</strong> the Windowsenvir<strong>on</strong>ment include the import statement and the c<strong>on</strong>necti<strong>on</strong> object as shown inthe following examples.● The import statement should be changed from:import DC<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>2<strong>to</strong>import mx.ODBC.Windows


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 267●The c<strong>on</strong>necti<strong>on</strong> object must be initialized as in the following example:db = mx.ODBC.Windows.DriverC<strong>on</strong>nect('DSN=sqlserverDS')Note This DSN uses Windows Authenticati<strong>on</strong> Mode <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>.8. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>.This is a step comm<strong>on</strong> <strong>to</strong> all migrati<strong>on</strong>s. Refer <strong>to</strong> Chapter 11, "Developing:Applicati<strong>on</strong>s— <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>" <str<strong>on</strong>g>for</str<strong>on</strong>g> a detailed discussi<strong>on</strong> <strong>on</strong>modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be <strong>SQL</strong> <strong>Server</strong>-compliant.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 26916Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*CIntroducti<strong>on</strong> and GoalsThir d generati<strong>on</strong> languages (3GL) such as C and C++ do not have the capability <strong>to</strong>interface with databases. Databases can <strong>on</strong>ly communicate using the <strong>SQL</strong> fourthgenerati<strong>on</strong> language (4GL). Using embedded <strong>SQL</strong> allows a database <strong>to</strong> interface directlywith the 3GL languages. Pro*C is <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s proprietary interface <strong>to</strong> the C language whichpermits the use of embedded <strong>SQL</strong>.As discussed in the "Define the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> C<strong>on</strong>cept" secti<strong>on</strong> of Chapter 2, "Envisi<strong>on</strong>ingPhase," there are four different strategies available <str<strong>on</strong>g>for</str<strong>on</strong>g> transiti<strong>on</strong>ing applicati<strong>on</strong>s in an<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> Microsoft® <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong> project. The strategies are:● Interoperate the applicati<strong>on</strong> with <strong>UNIX</strong>● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m● Port or rewrite the applicati<strong>on</strong> <strong>to</strong> the Microsoft Win32® plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m● Quick port using the Microsoft Windows® Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> 3.5 plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mBecause Pro*C is specific <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, migrati<strong>on</strong> strategies are limited. Interoperati<strong>on</strong> andporting cannot be utilized because no methods exist that allow Pro*C <strong>to</strong> communicatewith <strong>SQL</strong> <strong>Server</strong>. A complete rewrite is the <strong>on</strong>ly opti<strong>on</strong>.This chapter focuses <strong>on</strong> the preferred scenario that can be used in Pro*C applicati<strong>on</strong>migrati<strong>on</strong>s: Scenario 1: Rewriting the applicati<strong>on</strong> <strong>to</strong> the .NET plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.Rewriting an applicati<strong>on</strong> is a challenging endeavor because a <strong>on</strong>e-<strong>to</strong>-<strong>on</strong>e mapping fromthe source envir<strong>on</strong>ment <strong>to</strong> the target envir<strong>on</strong>ment is very difficult <strong>to</strong> achieve. When anapplicati<strong>on</strong> is rewritten, there is always a risk that some functi<strong>on</strong>ality from the originalapplicati<strong>on</strong> may be lost during the transiti<strong>on</strong>. Comm<strong>on</strong>ly, Pro*C programs are proceduraland do not have a graphical user interface. <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> procedural code is easier thanmigrating GUI-based applicati<strong>on</strong>s. Extensive testing needs <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong> therewritten applicati<strong>on</strong> <strong>to</strong> ensure that all of the business logic and functi<strong>on</strong>ality hasaccurately been recreated.This chapter <strong>on</strong>ly discusses the trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> that needs <strong>to</strong> occur <strong>to</strong> the most comm<strong>on</strong>database-related comp<strong>on</strong>ents when rewriting a Pro*C applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the .NETenvir<strong>on</strong>ment. A comprehensive study of the entire rewrite is bey<strong>on</strong>d the scope of thisguidance.


270 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*CUnderstanding the TechnologyPro*C is available <strong>on</strong> the Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. Un<str<strong>on</strong>g>for</str<strong>on</strong>g>tunately, there are no methodsavailable <strong>to</strong> allow Pro*C code <strong>to</strong> interface with <strong>SQL</strong> <strong>Server</strong>. Microsoft offers a productsimilar <strong>to</strong> Pro*C called Embedded <strong>SQL</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> C (E<strong>SQL</strong>/ C) which allows Transact-<strong>SQL</strong>statements <strong>to</strong> be embedded in C language programs. E<strong>SQL</strong>/C can be used as the targetlanguage <str<strong>on</strong>g>for</str<strong>on</strong>g> rewriting Pro*C programs because of its close resemblance <strong>to</strong> Pro*C.However, using this language is not recommended because Microsoft no l<strong>on</strong>ger developsthis product, and future versi<strong>on</strong>s of <strong>SQL</strong> <strong>Server</strong> will not support E<strong>SQL</strong>/C.Visual Basic .NET is recommended <str<strong>on</strong>g>for</str<strong>on</strong>g> rewriting the applicati<strong>on</strong>. Visual Basic .NETprovides a robust scripting language and can easily be interfaced with <strong>SQL</strong> <strong>Server</strong>.When migrating the database from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, the Pro* C code and itsinteracti<strong>on</strong>s with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> should be examined <strong>to</strong> ensure that the functi<strong>on</strong>s can berecreated in the rewritten applicati<strong>on</strong>.Understanding Pro*CBe<str<strong>on</strong>g>for</str<strong>on</strong>g>e the applicati<strong>on</strong> can be rewritten, you must evaluate the functi<strong>on</strong>ality currentlyprovided by the Pro*C applicati<strong>on</strong>. While the computati<strong>on</strong>al and business logic isprovided by the host C language, Pro*C provides the syntax <strong>to</strong> implement the databasetransacti<strong>on</strong>s. The embedded <strong>SQL</strong> in Pro*C offers the following functi<strong>on</strong>ality that will have<strong>to</strong> be migrated:● C<strong>on</strong>nect <strong>to</strong> and maintain a c<strong>on</strong>necti<strong>on</strong> <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database.● Declare, open, and use cursors <strong>to</strong> manipulate data.● Interact with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases through <strong>SQL</strong> statements.● Provide mechanisms (host variables) <strong>to</strong> interface between the host code and thedatabase code.● Close any open cursors.● Handle any database excepti<strong>on</strong>s.● Close the c<strong>on</strong>necti<strong>on</strong> <strong>to</strong> the database.Each of these functi<strong>on</strong>s will need <strong>to</strong> be recreated in the new applicati<strong>on</strong>. Pro*C is mostlyused as an imperative programming language and is used <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>structing programswhich involve computati<strong>on</strong>. The target programming envir<strong>on</strong>ment should haveprogramming capabilities and features that are similar <strong>to</strong> those of C/C++ and alsointerface with <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> retrieving and manipulating data. The GUI capabilities willnot be discussed in this guide.Understanding .NET and ADO.NETThe Microsoft .NET Framework provides a programming infrastructure <str<strong>on</strong>g>for</str<strong>on</strong>g> building,deploying, and operating applicati<strong>on</strong>s and services. When working with databases,ADO.NET is a key comp<strong>on</strong>ent.ADO.NET is a set of libraries included with the Microsoft .NET Framework that enablescommunicati<strong>on</strong> with various data s<strong>to</strong>res from .NET applicati<strong>on</strong>s. The ADO.NET librariesinclude classes <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>necting <strong>to</strong> a data source, submitting queries, and processingresults. ADO.NET provides the <strong>to</strong>ols <strong>to</strong> efficiently implement data access andfuncti<strong>on</strong>ality provided by Pro*C. Data access in ADO.NET relies <strong>on</strong> the following twoentities:● DataSet


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 271●Data providerDataSetThe DataSet is a copy of the data retrieved from the database cached in memory. Datacan be loaded in<strong>to</strong> a DataSet from any valid data source, such as a <strong>SQL</strong> <strong>Server</strong>database, or an XML file. The DataSet persists in memory, and the data therein can bemanipulated and updated independent of the database. When appropriate, the DataSetcan then be used <str<strong>on</strong>g>for</str<strong>on</strong>g> updating the database.Data ProviderA data provider <str<strong>on</strong>g>for</str<strong>on</strong>g>ms the link between the Visual Basic .NET program and the database.A data provider is not a single comp<strong>on</strong>ent; rather it is a set of related comp<strong>on</strong>ents thatwork <strong>to</strong>gether <strong>to</strong> provide data in an efficient, per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance-driven manner.Two data providers are available <str<strong>on</strong>g>for</str<strong>on</strong>g> Visual Basic .NET. The <strong>SQL</strong> <strong>Server</strong> Data Provider isdesigned specifically <strong>to</strong> work with <strong>SQL</strong> <strong>Server</strong> 7 or later, and the OLE DB Data Provider,which can also c<strong>on</strong>nect <strong>to</strong> other types of databases. Each data provider c<strong>on</strong>sists ofversi<strong>on</strong>s of the following generic comp<strong>on</strong>ent classes:● The C<strong>on</strong>necti<strong>on</strong> object provides the c<strong>on</strong>necti<strong>on</strong> <strong>to</strong> the database.● The Command object executes a command against a data source. It can executen<strong>on</strong>-query commands, such as INSERT, UPDATE, or DELETE, or return aDataReader with the results of a SELECT command.● The DataReader object provides a <str<strong>on</strong>g>for</str<strong>on</strong>g>ward-<strong>on</strong>ly, read-<strong>on</strong>ly, c<strong>on</strong>nected recordset.● The DataAdapter object populates a disc<strong>on</strong>nected DataSet or DataTable with dataand per<str<strong>on</strong>g>for</str<strong>on</strong>g>ms updates.The following classes are also offered: Transacti<strong>on</strong>, CommandBuilder, Parameter,Excepti<strong>on</strong>, Error, and ClientPermissi<strong>on</strong>.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> data provider comp<strong>on</strong>ents, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpc<strong>on</strong>usingad<strong>on</strong>etproviders<strong>to</strong>a ccessdata.asp.Even though the syntax and use of the functi<strong>on</strong>s differ, ADO.NET provides equivalentdatabase functi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>. It is important <strong>to</strong> ensure that these functi<strong>on</strong>s aretranslated <strong>to</strong> the new envir<strong>on</strong>ment during the rewriting process.Scenario 1: Rewriting Pro*C <strong>to</strong> the .NET Plat<str<strong>on</strong>g>for</str<strong>on</strong>g>mRewriting the applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> Windows makes use of native <strong>SQL</strong> <strong>Server</strong> APIs, ADO.NET,Microsoft ActiveX Data Objects (ADO), or Open Database C<strong>on</strong>nectivity (ODBC) runningnatively in the Windows subsystem. Rewriting the applicati<strong>on</strong> can result in a more stableand integrated c<strong>on</strong>figurati<strong>on</strong> after the project is complete.Case 1: Rewrite the Applicati<strong>on</strong> using Visual Basic.NETVisual Basic.NET provides all the functi<strong>on</strong>ality of the C programming language as well asseveral interfaces <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> databases <strong>to</strong> execute <strong>SQL</strong> statements. This scenariodescribes how <strong>to</strong> rewrite a Pro*C applicati<strong>on</strong> with Visual Basic .NET.The figure that follows shows a graphical representati<strong>on</strong> of howthe Pro*C code willmigrate over <strong>to</strong> Visual Basic .NET during the rewrite.


272 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*CFigure 16.1Database access in Pro*C and Visual Basic .NETEach functi<strong>on</strong> that currently resides in Pro*C code will need <strong>to</strong> be rewritten, from the userinterface <strong>to</strong> the database c<strong>on</strong>necti<strong>on</strong>. There are two opti<strong>on</strong>s available <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the<strong>SQL</strong> <strong>Server</strong> data source from the .NET framework.These opti<strong>on</strong>s are:● The <strong>SQL</strong> <strong>Server</strong> .NET Data Provider is implemented in the <strong>SQL</strong>Client namespace.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 273● The OLE DB provider is in the OLE DB namespace. There are OLE DB providers<str<strong>on</strong>g>for</str<strong>on</strong>g> both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. To rewrite an applicati<strong>on</strong> using Visual Basic .NET, follow these steps:For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> data access services available with ADO.NET, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/cpguide/html/cpc<strong>on</strong>accessingdatawithad<strong>on</strong>et.asp.The examples used in these procedures are based <strong>on</strong> <strong>SQL</strong> <strong>Server</strong> .NET DataProvider andDataReader objects. If an OLE DB provider is used, there may be slight variati<strong>on</strong>s <strong>to</strong> thefollowing steps.1. Install the .NET Framework SDK and redistributi<strong>on</strong>. The SDK c<strong>on</strong>tains thereso urces <str<strong>on</strong>g>for</str<strong>on</strong>g> building, testing, and deploying .NET Framework applicati<strong>on</strong>s. Foraccess <strong>to</strong> the latest SDK, refer <strong>to</strong>http://msdn.microsoft.com/netfram ework/downloads/updates/default.aspx.The Microsoft Visual Basic .NET software is required <str<strong>on</strong>g>for</str<strong>on</strong>g> programming theapplicati<strong>on</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer <strong>to</strong>http ://www.microsoft.com/downloads/details.aspx?FamilyID=dd6ec730-fd9a-4e36-8552-8accc4cd8fb3&DisplayLang=en.At t his point, it is assumed that you have all the comp<strong>on</strong>ents in place <strong>to</strong> write a VB.NET applicati<strong>on</strong> using the <strong>SQL</strong> <strong>Server</strong> .NET DataProvider. It is also assumed thatthe migrated <strong>SQL</strong> <strong>Server</strong> database is in place.For access <strong>to</strong> several references <str<strong>on</strong>g>for</str<strong>on</strong>g> creating Windows <str<strong>on</strong>g>for</str<strong>on</strong>g>ms applicati<strong>on</strong>s, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpc<strong>on</strong>CreatingWindowsFormsApplicat i<strong>on</strong>s.asp.2. Rewrite c<strong>on</strong>nectivity statements within applicati<strong>on</strong> code.● In Pro*C, database open and close statements are similar <strong>to</strong> the followingexample:/* assign username and password <strong>to</strong> host variables */strcpy(username.arr,"SCOTT");username.len=strlen(username.arr);strcpy(password.arr,"TIGER");password.len=strlen(password.arr);/* execute c<strong>on</strong>nect statement */EXEC <strong>SQL</strong> CONNECT :username IDENTIFIED BY :password;●/* execute close statements */EXEC <strong>SQL</strong> COMMIT WORK RELEASE;These same functi<strong>on</strong>s can be recreated using ADO.NET. Here are examplesof the same functi<strong>on</strong>s as written <str<strong>on</strong>g>for</str<strong>on</strong>g> .NET.' declare a c<strong>on</strong>necti<strong>on</strong> objectDim cn As New SqlC<strong>on</strong>necti<strong>on</strong>' define a c<strong>on</strong>necti<strong>on</strong> stringDim strC<strong>on</strong>n As String'This is the c<strong>on</strong>necti<strong>on</strong> stringstrC<strong>on</strong>n = "Data Source=(local)\DataSourceName;" & _"Initial Catalog=databaseName;" & _"Trusted_C<strong>on</strong>necti<strong>on</strong>=Yes;"' instantiate c<strong>on</strong>necti<strong>on</strong> object


274 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*Ccn = SqlC<strong>on</strong>necti<strong>on</strong>(strC<strong>on</strong>n)' open c<strong>on</strong>necti<strong>on</strong>scn.Open()' close c<strong>on</strong>necti<strong>on</strong>scn.Close()For more details <strong>on</strong> SqlC<strong>on</strong>necti<strong>on</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/cpref/html/frlrfsystemdatasqlclientsqlc<strong>on</strong>necti<strong>on</strong>class<strong>to</strong>pic.asp3. Rewrite the queries and cursor functi<strong>on</strong>s.Pro*C uses embedded <strong>SQL</strong> <strong>to</strong> s<strong>to</strong>re the output of a query statement in a cursorfrom which rows can be fetched. Visual Basic.NET does not support cursors;instead, it uses several other methods <str<strong>on</strong>g>for</str<strong>on</strong>g> retrieving data sets from <strong>SQL</strong> queries.One of these data retrieval methods is the DataReader object, which is aligh tweight object that is read-<strong>on</strong>ly and, hence, ideal <str<strong>on</strong>g>for</str<strong>on</strong>g> queries. The following linkprovides access <strong>to</strong> more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> retrieving data using DataReader object:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpc<strong>on</strong>thead<strong>on</strong>etdatareader.asp.● Here are some comm<strong>on</strong> cursor operati<strong>on</strong>s encountered in Pro*C applicati<strong>on</strong>s:Defining a cursor:●EXEC <strong>SQL</strong> DECLARE cust_cursor FORSELECT Cus<strong>to</strong>merID, CompanyName FROM Cus<strong>to</strong>mers;Opening the cursor:EXEC <strong>SQL</strong> OPEN cust_cursor;Fetching rows using the cursor:<str<strong>on</strong>g>for</str<strong>on</strong>g> (;;){EXEC <strong>SQL</strong> WHENEVER NOT FOUND DO break;EXEC <strong>SQL</strong> FETCH cust_cursor INTO :cus<strong>to</strong>merid, :companyname;printf("Cus<strong>to</strong>merID: %s – CompanyName: %s\n", cus<strong>to</strong>merid,companyname);}Closing the cursor:EXEC <strong>SQL</strong> CLOSE cust_cursor;Although <strong>SQL</strong> <strong>Server</strong> does not support cursors, equivalent functi<strong>on</strong>s can becreated using ADO.NET:Defining the query:str<strong>SQL</strong> = "SELECT Cus<strong>to</strong>merID, CompanyName FROM Cus<strong>to</strong>mers"Creating a command object:Dim cmd As New SqlCommand(str<strong>SQL</strong>, cn)Creating a data reader object:Dim rdr As SqlDataReader = cmd.ExecuteReader()Displaying the data reader result set:While rdr.Read()C<strong>on</strong>sole.WriteLine(rdr("Cus<strong>to</strong>merID") & " – " & rdr("CompanyName"))End WhileDo While rdr.Read()C<strong>on</strong>sole.WriteLine(rdr.GetInt32(0) & " " & _“ rdr.GetString(1) & " " & rdr.GetFloat(2))


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 275For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> implementing a DataReader, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpc<strong>on</strong>implementingdatareader.asp.4. Rewrite the embedded DML statementsThe embedded DML is used <strong>to</strong> insert, update, and delete data. The SqlCommandobject can be used <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m these <strong>SQL</strong> operati<strong>on</strong>s. The DataAdapter andDataSet objects are required <str<strong>on</strong>g>for</str<strong>on</strong>g> executing DML and s<strong>to</strong>red procedures. Migrati<strong>on</strong>of these operati<strong>on</strong>s is shown in the following examples:● The DML operati<strong>on</strong>s using Pro*C:Executing an INSERT DML statement:LoopClosing the data reader object:rdr.Close()●EXEC <strong>SQL</strong> INSERT INTO Cus<strong>to</strong>mer VALUES (:newcompanyname, :cus<strong>to</strong>merid);Executing an UPDATE DML statement:EXEC <strong>SQL</strong> UPDATE Cus<strong>to</strong>merSET CompanyName = :newcompanynameWHERE Cus<strong>to</strong>merID = 'ACME';Executing a DELETE DML statement:EXEC <strong>SQL</strong> DELETE FROM Cus<strong>to</strong>merWHERE Cus<strong>to</strong>merID = 'ACME';For each of the DML operati<strong>on</strong>s shown, the equivalent operati<strong>on</strong>s can beper<str<strong>on</strong>g>for</str<strong>on</strong>g>med using ADO.NET:Executing an INSERT DML statement:Dim str<strong>SQL</strong> As Stringstr<strong>SQL</strong> = " INSERT INTO Cus<strong>to</strong>mer VALUES " & _" (@newcompanyname,@cus<strong>to</strong>merid)"Dim cmd As New SqlCommand(str<strong>SQL</strong>, cn)Dim param1, param2 As SqlParameterParam1 = cmd.Parameters.Add("@newcompanyname",SqlDbType.VarChar, 10)Param2 = cmd.Parameters.Add("@cus<strong>to</strong>merid", SqlDbType.NChar, 5)Param1.Value = ”COMPANY1"Param1.Value = "VALUE1"cmd.ExecuteN<strong>on</strong>Query()Executing an UPDATE DML statement:Dim str<strong>SQL</strong> As Stringstr<strong>SQL</strong> = "UPDATE Cus<strong>to</strong>mer SET CompanyName = @newcompanyname " & _"WHERE Cus<strong>to</strong>merID = 'ACME'"Dim cmd As New SqlCommand(str<strong>SQL</strong>, cn)Dim param1 As SqlParameterParam1 = cmd.Parameters.Add("@newcompanyname", SqlDbType.VarChar, 10)Param1.Value = "NewName"Dim InsertRecordsAffected As Integer = cmd.ExecuteN<strong>on</strong>Query()Executing a DELETE DML statement:Dim str<strong>SQL</strong> As Stringstr<strong>SQL</strong> = " DELETE FROM Cus<strong>to</strong>mer WHERE Cus<strong>to</strong>merID = 'ACME'"Dim cmd As New SqlCommand(str<strong>SQL</strong>, cn)Dim InsertRecordsAffected As Integer = cmd.ExecuteN<strong>on</strong>Query()


276 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Pro*C5. Rewrite Transacti<strong>on</strong> Management operati<strong>on</strong>s●The Transacti<strong>on</strong> Management operati<strong>on</strong>s in Pro*C are:Beginning a transacti<strong>on</strong>:EXEC <strong>SQL</strong> SET TRANSACTION READ ONLY;Committing a transacti<strong>on</strong>:EXEC <strong>SQL</strong> COMMIT WORK RELEASE;Setting a savepoint:EXEC <strong>SQL</strong> SAVEPOINT save_point;Rollback a transacti<strong>on</strong>:EXEC <strong>SQL</strong> ROLLBACK WORK RELEASE;Rollback <strong>to</strong> a savepoint:EXEC <strong>SQL</strong> ROLLBACK TO SAVEPOINT save_point;● Transacti<strong>on</strong> Management in ADO.NETChanges are made through the DataSet object. The Update method is used <str<strong>on</strong>g>for</str<strong>on</strong>g>copying the changes made <strong>to</strong> the dataset back <strong>to</strong> the database which implicitlycommits the changes.6. Rewrite calls <strong>to</strong> s<strong>to</strong>red procedures.● S<strong>to</strong>red procedures are executed in Pro*C using the syntax shown in thefollowing example. In this example, the host variables represent IN or OUTparameters.EXEC <strong>SQL</strong> EXECUTE●BEGINGET_ROOM_DETAILS(:HotelId, :RoomType, :AvailableRooms,:StandardRate);END;END-EXEC;S<strong>to</strong>red procedure calls in ADO.NET: SqlCommand objects can be used <strong>to</strong> call<strong>SQL</strong> <strong>Server</strong> and MSDE s<strong>to</strong>red procedures. The SqlCommand object exposesa CommandType property that can be used <strong>to</strong> help simplify the code <strong>to</strong> calls<strong>to</strong>red procedures. Set SqlCommand object’s CommandText property <strong>to</strong> thes<strong>to</strong>red procedure name, and the CommandType property <strong>to</strong> S<strong>to</strong>redProcedure,and then call the s<strong>to</strong>red procedure, as shown in the following code:Dim strC<strong>on</strong>n As StringstrC<strong>on</strong>n = "Data Source=(local)\<strong>Net</strong>SDK;Initial Catalog=Northwind;" & _"Trusted_C<strong>on</strong>necti<strong>on</strong>=Yes;"Dim cn As New SqlC<strong>on</strong>necti<strong>on</strong>(strC<strong>on</strong>n)Dim cmd As New SqlCommand("GET_ROOM_DETAILS", cn)cmd.CommandType = CommandType.S<strong>to</strong>redProcedureDim param As SqlParameterparam = cmd.Parameters.Add("@HotelId", SqlDbType.NChar, 5)param.Value = "HOTEL1"………………cn.Open()Dim rdr As SqlDataReader = cmd.ExecuteReader()Do While rdr.Read()C<strong>on</strong>sole.WriteLine(rdr("OrderID"))…………Loop


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 277rdr.Close()A more detailed discussi<strong>on</strong> <strong>on</strong> using s<strong>to</strong>red procedures in Visual Basic.NET isavailable at http://msdn.microsoft.com/library/default.asp?url=/library/enus/dnadvnet/html/vbnet09102002.asp.7. Rewrite excepti<strong>on</strong> handling.●●There are two ways <strong>to</strong> handle <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> errors in Pro*C:●●<strong>SQL</strong>EXECembedded statements. The syntax is:<strong>SQL</strong> WHENEVER [c<strong>on</strong>diti<strong>on</strong>] [acti<strong>on</strong>];Checking error codes in <strong>SQL</strong>CAThe generic syntax isif ( sqlca.sqlcode == [a value i.e., -1] ){Handler code}Excepti<strong>on</strong> handling in Visual Basic .NETUse a Try block <strong>to</strong> add excepti<strong>on</strong> handling <strong>to</strong> a block of code. Add Catchblocks, as necessary, <strong>to</strong> trap individual excepti<strong>on</strong>s. The .NET runtime handlesCatch blocks in order, looking <str<strong>on</strong>g>for</str<strong>on</strong>g> an "is a" match against the current excepti<strong>on</strong>.It uses the first block it finds that matches. You can nest Try blocks, making iteasy <strong>to</strong> effectively push and pop excepti<strong>on</strong>-handling states. Add a Finally block<strong>to</strong> your Try block <strong>to</strong> run code unc<strong>on</strong>diti<strong>on</strong>ally, regardless of whether an erroroccurs or not.You can create your own excepti<strong>on</strong> classes that inherit from the baseexcepti<strong>on</strong> class (or any class that inherits from that class) <strong>to</strong> add your ownfuncti<strong>on</strong>ality:Try' Code that throws excepti<strong>on</strong>sCatch E As OverflowExcepti<strong>on</strong>' Catch a specific excepti<strong>on</strong>Catch E As Excepti<strong>on</strong>' Catch the generic excepti<strong>on</strong>sFinally' Execute some cleanup codeEnd TryA more detailed discussi<strong>on</strong> of error handling in VB.NET can be found athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/dnvbdev01/html/vb01f1.asp.8. Change all embedded <strong>SQL</strong> statements <strong>to</strong> T-<strong>SQL</strong>. This is a step comm<strong>on</strong> <strong>to</strong> allmigrati<strong>on</strong>s. Refer <strong>to</strong> Chapter 11, "Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g><strong>SQL</strong> and PL/<strong>SQL</strong>," <str<strong>on</strong>g>for</str<strong>on</strong>g> a detailed discussi<strong>on</strong> <strong>on</strong> modifying <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>to</strong> be<strong>SQL</strong> <strong>Server</strong>-compliant.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 27917Developing: Applicati<strong>on</strong>s —<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsIntroducti<strong>on</strong> and Goals<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms are applicati<strong>on</strong>s built using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Developer, a Rapid Applicati<strong>on</strong>Development (RAD) envir<strong>on</strong>ment available from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms-basedapplicati<strong>on</strong>s can retrieve and manipulate data in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases. These <str<strong>on</strong>g>for</str<strong>on</strong>g>ms can alsobe deployed across the Web.It is not possible <strong>to</strong> modify an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> interoperati<strong>on</strong> with aMicrosoft® <strong>SQL</strong> <strong>Server</strong> database, and it is recommended that applicati<strong>on</strong>s of this typeare rewritten. Microsoft Visual Basic® .NET is an ideal choice <str<strong>on</strong>g>for</str<strong>on</strong>g> rewriting an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Forms applicati<strong>on</strong> because it is very similar in nature <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Developer, both in termsof the development <strong>to</strong>ols and wizards, as well as the end product itself.This chapter is <str<strong>on</strong>g>for</str<strong>on</strong>g> developers who want <strong>to</strong> migrate their <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> running<strong>on</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database <strong>to</strong> Visual Basic .NET running <strong>on</strong> <strong>SQL</strong> <strong>Server</strong>. The <strong>to</strong>ols,processes, and techniques required <str<strong>on</strong>g>for</str<strong>on</strong>g> a successful c<strong>on</strong>versi<strong>on</strong> are described.In this guide, the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> is first analyzed <str<strong>on</strong>g>for</str<strong>on</strong>g> its comp<strong>on</strong>ents, and thena similar analysis of the Visual Basic .NET applicati<strong>on</strong> envir<strong>on</strong>ment is c<strong>on</strong>ducted.Strategies <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong> Visual Basic .NET are then examined. Adetailed discussi<strong>on</strong> <strong>on</strong> how <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the migrati<strong>on</strong> is bey<strong>on</strong>d the scope of this guide.The goal of this chapter is <strong>to</strong> provide a blueprint <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the migrati<strong>on</strong>.Migrati<strong>on</strong> Approach<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> <strong>to</strong> Visual Basic .NET is complex, and thetreatment of the subject here should be seen as a design sketch from which a detailedanalysis and plans <str<strong>on</strong>g>for</str<strong>on</strong>g> an applicati<strong>on</strong> migrati<strong>on</strong> can be made.The basic approach is feasible <str<strong>on</strong>g>for</str<strong>on</strong>g> the following two reas<strong>on</strong>s:1. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms and Visual Basic user interfaces share many comm<strong>on</strong> elements.2. The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Designer is capable <strong>to</strong> generate Visual Basic code.The <str<strong>on</strong>g>for</str<strong>on</strong>g>m is the basis <str<strong>on</strong>g>for</str<strong>on</strong>g> the user interface (UI) in both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms and Visual Basic.The <str<strong>on</strong>g>for</str<strong>on</strong>g>m is graphical in nature and is used <strong>to</strong> present data and accept user input, and the<str<strong>on</strong>g>for</str<strong>on</strong>g>m can c<strong>on</strong>tain elements which are both graphical and n<strong>on</strong>-graphical in nature. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>


280 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsForms and Visual Basic have several comm<strong>on</strong> elements between them. However, theirorganizati<strong>on</strong>, naming, and properties differ.Figure 17.1 illustrates how different comp<strong>on</strong>ents of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms map <strong>to</strong> comp<strong>on</strong>ents inVisual Basic .NET.Figure 17.1Mapping of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong> Visual Basic .NET WinFormThis diagram shows how all the high-level comp<strong>on</strong>ents of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>map <strong>to</strong> comp<strong>on</strong>ents in Visual Basic .NET. This mapping serves as a c<strong>on</strong>venient guide <str<strong>on</strong>g>for</str<strong>on</strong>g>the work <strong>to</strong> be d<strong>on</strong>e and also helps maintain the logical compositi<strong>on</strong> of the applicati<strong>on</strong>.The mapping also helps avoid introducing <strong>to</strong>o many unintended side effects, such asfiring of triggers at the wr<strong>on</strong>g time and complicating the migrati<strong>on</strong>. This diagram is used inthis chapter <strong>to</strong>document the source <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>, define the targetVisual Basic .NET applicati<strong>on</strong>, and plan <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the migrati<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 281Examining <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>s are <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database optimized transacti<strong>on</strong>al applicati<strong>on</strong>s builtusing the <strong>to</strong>ols provided by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s Developer Suite. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder, a part of<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Developer suite, enables you <strong>to</strong> quickly and easily create database <str<strong>on</strong>g>for</str<strong>on</strong>g>ms andbusiness logic. The development is d<strong>on</strong>e using wizards, drag-and-drop comp<strong>on</strong>ents, andbuilt-in functi<strong>on</strong>s. A visual edi<strong>to</strong>r can be used <strong>to</strong> refine the <str<strong>on</strong>g>for</str<strong>on</strong>g>ms with graphics and othercomp<strong>on</strong>ents. The coding language is PL/<strong>SQL</strong>. A client/server Forms applicati<strong>on</strong> can run<strong>on</strong> the Web with very little or no modificati<strong>on</strong>.Like most GUI applicati<strong>on</strong>s, an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> is composed of two parts: theapplicati<strong>on</strong> logic and the user interface. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms maintains this separati<strong>on</strong>throughout its design. Hence the Forms Runtime is the same in both the two-tier andthree-tier architectures.An understanding of the basic c<strong>on</strong>cepts and comp<strong>on</strong>ents that make up a <str<strong>on</strong>g>for</str<strong>on</strong>g>m isimportant <strong>to</strong> planning an applicati<strong>on</strong> migrati<strong>on</strong>. Figure 17.2 shows a simplified view of the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms envir<strong>on</strong>ment.Figure 17.2High-level organizati<strong>on</strong> of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms comp<strong>on</strong>entsAn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> is an organizati<strong>on</strong> of items. The organizati<strong>on</strong> of the itemshas two perspectives: that of the developer, called the <str<strong>on</strong>g>for</str<strong>on</strong>g>m view; and that of the user,called the visual (or presentati<strong>on</strong>) view. In the <str<strong>on</strong>g>for</str<strong>on</strong>g>m view, the items are organized in<strong>to</strong>logical blocks and have no visual structure. The visual structure is provided byc<strong>on</strong>structing the visual view where items are placed <strong>on</strong> a canvas and presented <strong>to</strong> theuser in windows. It is very important <strong>to</strong> maintain the same visual view when an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Forms applicati<strong>on</strong> is migrated. The Visual Basic .NET developers need <strong>to</strong> look at thevisual view <strong>to</strong> understand how many screen layouts they need in Visual Basic .NET.Each item in a canvas will corresp<strong>on</strong>d <strong>to</strong> <strong>on</strong>e c<strong>on</strong>trol in .NET.The migrati<strong>on</strong> should be attempted by creating two models: <strong>on</strong>e is based <strong>on</strong> the<str<strong>on</strong>g>for</str<strong>on</strong>g>mview, called the Form Model; and the other is based <strong>on</strong> the visual view, called the VisualModel. Figure 17.1 shows the <str<strong>on</strong>g>for</str<strong>on</strong>g>m view of the mapping from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong>Visual Basic .NET. The equivalent visual view is shown in Figure 17.3.


282 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsFigure 17.3Mapping of visual view of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong> Visual Basic .NETThe <str<strong>on</strong>g>for</str<strong>on</strong>g>m view is used by the developer <strong>to</strong> access the business logic and the dataaccess. The visual view is used <strong>to</strong> build the user interface.Note Providing a complete descripti<strong>on</strong> of how <strong>to</strong> trans<str<strong>on</strong>g>for</str<strong>on</strong>g>m every item and every pieceof code from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> <strong>to</strong> a Visual Basic .NET applicati<strong>on</strong> is bey<strong>on</strong>dthe scope of this guide.In this secti<strong>on</strong>, the entire <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> is examined, with an emphasis <strong>on</strong>understanding the database-related comp<strong>on</strong>ents.An <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> is built using comp<strong>on</strong>ents called modules. The following fourtypes of modules are visible when a <str<strong>on</strong>g>for</str<strong>on</strong>g>m applicati<strong>on</strong> is opened up in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsBuilder:1. Object Library2. PL/<strong>SQL</strong> Library3. Form Module4. Menu ModuleFigure 17.4 shows the details of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> as seen in the OwnershipView using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder. This <strong>to</strong>ol will be employed in documenting the currentapplicati<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 283Figure 17.4An <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Form as visible in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms BuilderAn applicati<strong>on</strong> can be built using multiple <str<strong>on</strong>g>for</str<strong>on</strong>g>ms, menus, and library modules. The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Forms Builder can be used <strong>to</strong> browse the comp<strong>on</strong>ent model and understand the modulesand their characteristics so that the Forms Model can be built. The elements offered bythese modules account <str<strong>on</strong>g>for</str<strong>on</strong>g> the capabilities, features, and functi<strong>on</strong>ing of the applicati<strong>on</strong>and should be the focus of the developer involved in migrating an applicati<strong>on</strong>.


284 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsTable 17.1 is a compilati<strong>on</strong> of the files that make up an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>.Table 17.1: <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms File Extensi<strong>on</strong>sModule Extensi<strong>on</strong> CharacteristicForm .fmb Form design file.fmx.fmtForm executable runfileForm text export fileMenu .mmb Menu design file.mmxMenu executable runfile.mmt Menu text export filePL/<strong>SQL</strong> Library .pll PL/<strong>SQL</strong> library design file (can also be executed— c<strong>on</strong>tains both source and executable code).plxPL/<strong>SQL</strong> library executable runfile (c<strong>on</strong>tains nosource code).pldPL/<strong>SQL</strong> library text export fileObject Library .olb Object library design file.oltObject library text export file<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder can be used <strong>to</strong> view all the comp<strong>on</strong>ents in a Forms applicati<strong>on</strong> byopening the <str<strong>on</strong>g>for</str<strong>on</strong>g>m and clicking View, and then Show PL/<strong>SQL</strong> <strong>on</strong>ly.Object LibraryThe object-oriented programming c<strong>on</strong>cept of reusing code is implemented in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Forms by the object library and PL/<strong>SQL</strong> library modules. The Object library c<strong>on</strong>tainsreusable objects and the PL/<strong>SQL</strong> library c<strong>on</strong>tains reusable code. Hence, these areexamined first <str<strong>on</strong>g>for</str<strong>on</strong>g> a migrati<strong>on</strong>.The Object library is a collecti<strong>on</strong> of <str<strong>on</strong>g>for</str<strong>on</strong>g>ms objects that can be used in other <str<strong>on</strong>g>for</str<strong>on</strong>g>m, menu, orlibrary modules. The Object Library is used <strong>to</strong> s<strong>to</strong>re, maintain, and distribute standard<str<strong>on</strong>g>for</str<strong>on</strong>g>ms objects, which can then be reused across the entire applicati<strong>on</strong>. They also helpc<strong>on</strong>serve runtime memory and encourage reuse. The objects in an Object Library arecomm<strong>on</strong>ly organized as folders. The organizati<strong>on</strong> may be by type of item or byapplicati<strong>on</strong> functi<strong>on</strong>al area.A good example of the use of an object library is a c<strong>on</strong>trol block used <strong>to</strong> enter complexsearch criteria in a query-<strong>on</strong>ly <str<strong>on</strong>g>for</str<strong>on</strong>g>m. This c<strong>on</strong>trol block is then used in multiple <str<strong>on</strong>g>for</str<strong>on</strong>g>ms.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder allows creati<strong>on</strong> of a subclassed versi<strong>on</strong> of a library object <str<strong>on</strong>g>for</str<strong>on</strong>g> reusein any desired module. To be able <strong>to</strong> tell whether an object is subclassed or not, look atthe subclass in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> property of the data block.The object-oriented features of Visual Basic .NET allow you <strong>to</strong> model library objectinheritance closely <strong>to</strong> maintainthe same structure. The object library can be viewed as aDLL.PL/<strong>SQL</strong> LibraryThe PL/<strong>SQL</strong> library c<strong>on</strong>tains reusable code invoked by other <str<strong>on</strong>g>for</str<strong>on</strong>g>m, menu, or librarymodules. The code, also called a program unit, can be user-named functi<strong>on</strong>s,procedures, or packages. The program unit is s<strong>to</strong>red and executed <strong>on</strong> the client. Theprogram units are not <str<strong>on</strong>g>for</str<strong>on</strong>g> database-related code al<strong>on</strong>e. They may c<strong>on</strong>tain purely businesslogic. For example, the code could be used <strong>to</strong> check the validity of a user input in a <str<strong>on</strong>g>for</str<strong>on</strong>g>m.Any <strong>SQL</strong> c<strong>on</strong>tained in these program units is passed <strong>to</strong> the database.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 285Libraries make all the PL/<strong>SQL</strong> code available <strong>to</strong> the <str<strong>on</strong>g>for</str<strong>on</strong>g>m without being part of the <str<strong>on</strong>g>for</str<strong>on</strong>g>m.The libraries are loaded dynamically. Multiple <str<strong>on</strong>g>for</str<strong>on</strong>g>ms can attach the same PL/<strong>SQL</strong> library.Table 17.1 identifies the files that are related <strong>to</strong> the PL/<strong>SQL</strong>needs <strong>to</strong> be migrated.Form ModuleLibrary that c<strong>on</strong>tain code thatA <str<strong>on</strong>g>for</str<strong>on</strong>g>m (or <str<strong>on</strong>g>for</str<strong>on</strong>g>m module) is the main comp<strong>on</strong>ent that anchors an applicati<strong>on</strong> and providesthe necessary code <strong>to</strong> interact with the datasource and the user interface. The underlyingdatabase data is reflected in multiple items, including fields, check boxes, and radiogroups. A <str<strong>on</strong>g>for</str<strong>on</strong>g>m is logically organized in<strong>to</strong> blocks.BlocksA block is a c<strong>on</strong>tainer <str<strong>on</strong>g>for</str<strong>on</strong>g> a group of related items such as text boxes, lists, and butt<strong>on</strong>s.The block itself does not have a visual representati<strong>on</strong>.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder c<strong>on</strong>sists of two main types of blocks. These are:1. Data blocks2. C<strong>on</strong>trol blocksThese two kinds of blocks are very different from each other. The data block serves as abridge <strong>to</strong> the underlying data and provides an abstracti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> how the data is reached.The c<strong>on</strong>trol blocks are more like programming units that can organize c<strong>on</strong>trols in<strong>to</strong> logicalgroups <str<strong>on</strong>g>for</str<strong>on</strong>g>ming part of the same user interface navigati<strong>on</strong> cycle. Whether a block is adata block or a c<strong>on</strong>trol block can be determined by verifying the Database Data Blockproperty <str<strong>on</strong>g>for</str<strong>on</strong>g> the block. It is a data block if the setting is "Yes" and a c<strong>on</strong>trol block if thesetting is "No."Data BlockA data block can be associated with a specific database table (or a view), a s<strong>to</strong>redprocedure, a FROM clause query, or a transacti<strong>on</strong>al triggers. By default, the associati<strong>on</strong>between a data block and the database allows <str<strong>on</strong>g>for</str<strong>on</strong>g> au<strong>to</strong>matic access and manipulati<strong>on</strong> ofdata in the database. Triggers are used when a data block needs access <strong>to</strong> tables notdirectly associated with it (n<strong>on</strong>-base tables).Various relati<strong>on</strong>ships can exist between data blocks and their underlying base tables. Acomm<strong>on</strong> relati<strong>on</strong>ship is the master-detail relati<strong>on</strong>ship where each row in the master tablecorresp<strong>on</strong>ds <strong>to</strong> <strong>on</strong>e or more rows in the detail table. The master-detail relati<strong>on</strong>shipallows the primary key and <str<strong>on</strong>g>for</str<strong>on</strong>g>eign key values <strong>to</strong> be linked across data blocks. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Forms Builder au<strong>to</strong>matically generates the objects and the PL/<strong>SQL</strong> code needed <strong>to</strong>support the master-detail relati<strong>on</strong>ships when these blocks are built using the Data BlockWizard.


286 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsFigure 17.5 shows the different comp<strong>on</strong>ents that make up a master-detail block ascreated by the Data Block Wizard.Figure 17.5Code generated by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder Data Block Wizard in creating a master-detail blockBy capturing a query <strong>on</strong> a table, a block can also be designed <strong>to</strong> show <strong>on</strong>e or morerecords at a time. These are called single-record blocks or multi-record blocks,respectively.Visual Basic .NET developers can use <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder <strong>to</strong> look at the generatedcode <strong>to</strong> find out about the relati<strong>on</strong>ships between the blocks. For example, in Figure 17. 5,code in the ON-POPULATE-DETAILS trigger <strong>on</strong> the DEPT block suggests that it is themaster block of the EMP block.In Visual Basic .NET, the equivalent of an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Form data block is a Dataset in<strong>to</strong> whichdata can be read from the database, and <strong>on</strong> the visual side, a DataGrid c<strong>on</strong>trol bound <strong>to</strong>the Dataset will be capable <strong>to</strong> display the data. Dataset is just <strong>on</strong>e opti<strong>on</strong>. In additi<strong>on</strong> <strong>to</strong>the Dataset, ADO.NET offers DataReader <str<strong>on</strong>g>for</str<strong>on</strong>g> read-<strong>on</strong>ly data access.Additi<strong>on</strong>al properties c<strong>on</strong>vey the associati<strong>on</strong> between a data block and a table, such asthe WHERE clause and ORDER BY clause that will be used <strong>to</strong> create <strong>SQL</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> theVisual Basic .NET Dataset. The Insert Allowed, Update Allowed, and Delete Allowedproperties will tell the Visual Basic .NET developer whether the block will insert, update,or delete any records.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 287Figure 17.6 shows all the properties of a data block.Figure 17.6Properties of a data blockC<strong>on</strong>trol BlockThe sec<strong>on</strong>d type of block is the c<strong>on</strong>trol block. The items in a c<strong>on</strong>trol block are notassociated with the database, and its items do not relate <strong>to</strong> any columns within anydatabase table. The items in a c<strong>on</strong>trol block are called c<strong>on</strong>trol items. For example,butt<strong>on</strong>s in a module can initiate certain acti<strong>on</strong>s and can be logically grouped in a c<strong>on</strong>trolblock. The c<strong>on</strong>trol block is <strong>on</strong>ly a logical grouping and the physical or visual placementmay differ. It is also a mechanism <strong>to</strong> segregate the c<strong>on</strong>trol block items from the items thatare dependent <strong>on</strong> the database. C<strong>on</strong>trol items are used <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m functi<strong>on</strong>s, such asaccepting input from the user and displaying calculated values and look values.Program UnitsProgram units are part of <str<strong>on</strong>g>for</str<strong>on</strong>g>ms modules and they c<strong>on</strong>tain named procedures, functi<strong>on</strong>s,or packages. The program units are similar <strong>to</strong> the program units created in the librariesbut are local <strong>to</strong> the <str<strong>on</strong>g>for</str<strong>on</strong>g>m in which they are created. They are s<strong>to</strong>red and executed <strong>on</strong> theclient with any embedded <strong>SQL</strong> passed <strong>to</strong> the database <str<strong>on</strong>g>for</str<strong>on</strong>g> processing. If this codec<strong>on</strong>tains database interacti<strong>on</strong>s, then it needs <strong>to</strong> be c<strong>on</strong>verted <strong>to</strong> T-<strong>SQL</strong>. If it c<strong>on</strong>tains <strong>on</strong>lyn<strong>on</strong>-database related code, then it needs <strong>to</strong> be c<strong>on</strong>verted <strong>to</strong> its equivalent inVisual Basic .NET.TriggersThe trigger object is a PL/<strong>SQL</strong> block executed <strong>on</strong> an event. Triggers can be owned by the<str<strong>on</strong>g>for</str<strong>on</strong>g>m module, a data block, or an item, depending up<strong>on</strong> their scope.


288 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsIf this code c<strong>on</strong>tains database interacti<strong>on</strong>s, then it needs <strong>to</strong> be c<strong>on</strong>verted <strong>to</strong> T-<strong>SQL</strong>. If itc<strong>on</strong>tains <strong>on</strong>ly n<strong>on</strong>-database code, then it needs <strong>to</strong> be c<strong>on</strong>verted <strong>to</strong> its equivalent inVisual Basic .NET.When a trigger is activated, it executes the code it c<strong>on</strong>tains. Each trigger’s name defineswhat event will fire it; <str<strong>on</strong>g>for</str<strong>on</strong>g> example, a WHEN-BUTTON-PRESSED trigger executes itscode each time the user clicks the butt<strong>on</strong> <strong>to</strong> which the trigger is attached.A trigger can be replaced by an equivalent event in Visual Basic .NET. The equivalent ofan <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms WHEN-BUTTON_PRESSED trigger in Visual Basic .NET is the Clickevent procedure. Double-click the page Butt<strong>on</strong> c<strong>on</strong>trol in design view <strong>to</strong> open the codebehind the page and create a Click event procedure.List of Values (LOV)A LOV is a pop-up window that provides the user with a selecti<strong>on</strong> of values. The valuescan be static or populated by querying the database. LOVs are populated using columnsreturned by record groups. Check the Record Group property of the LOV <str<strong>on</strong>g>for</str<strong>on</strong>g> the recordgroup which is used <strong>to</strong> provide values. Visual Basic .NET offers pop-up windows that canbe programmed <strong>to</strong> display a list of values obtained by the DataReader.Record GroupsA record group is a data structure in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m module which behaves like a local table <str<strong>on</strong>g>for</str<strong>on</strong>g>data retrieved from the databases. Record groups are a way <strong>to</strong> share small List of Values(LOV). The values can be retrieved using a query or a subprogram. Look in<strong>to</strong> theproperty Record Group Query <strong>to</strong> see the <strong>SQL</strong> statement up<strong>on</strong> which the record group isbased. A record group can be replaced by DataReader in Visual Basic .NET.Menu ModuleThe menu module c<strong>on</strong>sists of a hierarchy of menus. Each menu c<strong>on</strong>sists of the items thatcan be selected. Menu modules are usually attached <strong>to</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>m modules. Every <str<strong>on</strong>g>for</str<strong>on</strong>g>mmodule has a default menu that includes the commands <str<strong>on</strong>g>for</str<strong>on</strong>g> all basic databaseoperati<strong>on</strong>s, such as insert, update, delete, and query. Visual Basic .NET offers a widerange of functi<strong>on</strong>ality involving menus.After inserting, updating, or deleting records from an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g>m, changes are not madein the underlying database until the changes are committed with a save command. Whilerewriting this module in Visual Basic .NET, it is important <strong>to</strong> know whether inserts,updates, and deletes are permitted <strong>on</strong> a data block. The data block properties of InsertAllowed, Update Allowed, and Delete Allowed determine these.Any item in a menu can also be referenced through PL/<strong>SQL</strong> code <strong>to</strong> enable/disable menuitems, attach commands <strong>to</strong> menu items, initialize check or radio menu items, and changemenu start-up code.Windows and CanvasesWindows and canvases <str<strong>on</strong>g>for</str<strong>on</strong>g>m the basis <str<strong>on</strong>g>for</str<strong>on</strong>g> the visual presentati<strong>on</strong> of the <str<strong>on</strong>g>for</str<strong>on</strong>g>m. The visualmodel is built by looking at the windows and canvases through Form Builder. Thedeveloper can then create an identical representati<strong>on</strong> in Visual Basic .NET based <strong>on</strong> thevisual model using <str<strong>on</strong>g>for</str<strong>on</strong>g>ms.<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms has two types of windows: document windows (the main applicati<strong>on</strong> areas)and dialog windows (messages and other acti<strong>on</strong>s).The end user interacts with theapplicati<strong>on</strong> using these windows. In additi<strong>on</strong> <strong>to</strong> incorporating all the functi<strong>on</strong>ality in theoriginal applicati<strong>on</strong>, it is also important <strong>to</strong> maintain the general look and feel of theapplicati<strong>on</strong>.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 289The document window is composed of work areas called canvases where visual objectssuch as graphics and items are arranged. Several canvases can be located in a <str<strong>on</strong>g>for</str<strong>on</strong>g>mmodule. All canvases may appear in a single window (by default) or spread acrossmultiple windows (<strong>to</strong> view simultaneously).From the start, a new document window or dialog has a relati<strong>on</strong>ship with a <str<strong>on</strong>g>for</str<strong>on</strong>g>m in whichrelati<strong>on</strong>ships <strong>to</strong> blocks tie the visual representati<strong>on</strong> <strong>to</strong>gether with the underlying databasedata. Figure 17.7 shows a window which displays the master-detail view of the data. TheDept part is the header and the Employees part is the detail.Figure 17.7Sample applicati<strong>on</strong> windowFramesA frame is a visual object found <strong>on</strong> a canvas. Frames are used <strong>to</strong> arrange items in termsof blocks. The frame defines visual characteristics such as margins, offsets, anddistances between items. Frames may also be defined in the Object Library <strong>to</strong> en<str<strong>on</strong>g>for</str<strong>on</strong>g>cestandards across the applicati<strong>on</strong>. The equivalent of frames in Visual Basic .NET is thepanel.ItemItems are interface objects that present the data values <strong>to</strong> the users. Items also enablethe user <strong>to</strong> interact with the <str<strong>on</strong>g>for</str<strong>on</strong>g>m. The type of interacti<strong>on</strong> varies according <strong>to</strong> the type ofitem. Visual Basic .NET offers a wide range of equivalents <str<strong>on</strong>g>for</str<strong>on</strong>g> the <str<strong>on</strong>g>for</str<strong>on</strong>g>m items calledc<strong>on</strong>trols.The type of an item can be examined by locating the Item Type property of the item.Items have both a visual representati<strong>on</strong> and a <str<strong>on</strong>g>for</str<strong>on</strong>g>ms representati<strong>on</strong> (code) and willappear in both models. However, the properties captured in each of the models will differ.Only the comm<strong>on</strong> items, such as text item, check box, and radio groups, which could bedependent <strong>on</strong> the database are discussed here. For each of the items, the visual andfuncti<strong>on</strong>al characteristics are attached <strong>to</strong> the visual model and the logical characteristicsare captured in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m model. For example, the height, width, f<strong>on</strong>t size, and <str<strong>on</strong>g>for</str<strong>on</strong>g>matmas k are the visual characteristics. The database item (table and column) that is used <strong>to</strong>populate the text item is the <str<strong>on</strong>g>for</str<strong>on</strong>g>m characteristic.Text ItemText items allow <str<strong>on</strong>g>for</str<strong>on</strong>g> text <strong>to</strong> be displayed and manipulated. Text items are called by thename TextBox in Visual Basic .NET. When examining text items, Visual Basic .NETdevelopers need <strong>to</strong> determine whether this item corresp<strong>on</strong>ds <strong>to</strong> a column in a databasetabl e by looking at the Database Item property. If so, it needs <strong>to</strong> be tied <strong>to</strong> a dataset orother data source in Visual Basic .NET. The name of the text item is not necessarily thesame as the name of the database column. Look at the Column Name property <str<strong>on</strong>g>for</str<strong>on</strong>g> thename of database column.


290 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsCheck Box ItemA check box provides the user with a Boolean c<strong>on</strong>trol that has just two values, such astrue and false, or <strong>on</strong> and off. The check box values can be set by fetching from thedatabase. When creating the equivalent Check Box c<strong>on</strong>trol, Visual Basic .NETdevelopers need <strong>to</strong> look at the following three properties of a check box item: ValueWhen Checked, Value When Unchecked, and Check Box Mapping of Other Values.Radio Group ItemA radio group provides the user with a fixed set of opti<strong>on</strong>s that are mutually exclusive,Radio group item values can also be set using database columns. Under the radiobutt<strong>on</strong>, the developer should look at the Radio Butt<strong>on</strong> Value property <str<strong>on</strong>g>for</str<strong>on</strong>g> the valueassigned <strong>to</strong> the butt<strong>on</strong>. In Visual Basic .NET the radio group can be replaced by acombinati<strong>on</strong> of GroupBox and RadioButt<strong>on</strong>s.Butt<strong>on</strong>sButt<strong>on</strong>s are interface items that can display list of values, commit data in a <str<strong>on</strong>g>for</str<strong>on</strong>g>m, querythe database, or invoke PL/<strong>SQL</strong> blocks. The WHEN-BUTTON-PRESSED trigger holdsthe code <str<strong>on</strong>g>for</str<strong>on</strong>g> these acti<strong>on</strong>s. Butt<strong>on</strong>s are also found in Visual Basic .NET.Understanding Visual Basic .NETVisu al Basic.NET offers Windows® Forms (WinForms) Designer, which is very similar innatu re <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Builder. The product of the Windows Forms Designer is aWindows-based <str<strong>on</strong>g>for</str<strong>on</strong>g>m applicati<strong>on</strong> that is similar in nature <strong>to</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>.Forms are the fundamental elements of the applicati<strong>on</strong> <strong>on</strong> which c<strong>on</strong>trols (same as itemsin <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms) can be placed <str<strong>on</strong>g>for</str<strong>on</strong>g> user interacti<strong>on</strong>. As in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms, menus and<strong>to</strong>olbars provide a structure <str<strong>on</strong>g>for</str<strong>on</strong>g> the user <strong>to</strong> c<strong>on</strong>trol the applicati<strong>on</strong>. For readers who areunfamiliar with VB.NET, there is a lot of in-depth technical in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> available athttp://msdn.microsoft.com/vbasic/using/If the c<strong>on</strong>versi<strong>on</strong> of the <str<strong>on</strong>g>for</str<strong>on</strong>g>ms is d<strong>on</strong>e correctly, then the WinForm is simply thepresentati<strong>on</strong> layer with all of the database access logic and rules put in<strong>to</strong> a businessobject layer. The c<strong>on</strong>versi<strong>on</strong> <strong>to</strong> a Web Form soluti<strong>on</strong>, as a result, <strong>on</strong>ly requiresassociating the appropriate Web server c<strong>on</strong>trol <strong>to</strong> an object holding the data retrievedfrom the business object layer.The c<strong>on</strong>trols <strong>on</strong> a <str<strong>on</strong>g>for</str<strong>on</strong>g>m simply provide an interface <strong>to</strong> the event-driven model that is theequ ivalent of the triggers system in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms. As changes are made <strong>to</strong> textbox input,the pressing of butt<strong>on</strong>s, or the selecti<strong>on</strong> of items in a list, additi<strong>on</strong>al code is triggered (see"Triggers" in the "Form Module" secti<strong>on</strong> earlier in this chapter). The code is in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m ofsubroutines that handle the call from the raised event <strong>to</strong> provide some specific acti<strong>on</strong>.The PL/<strong>SQL</strong> routines will map <strong>to</strong> these subroutines. The acti<strong>on</strong> is typically defined as analgorithm or a business rule. In most applicati<strong>on</strong>s, the business rules extract in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>from the database.A summary of the entire array of c<strong>on</strong>trols in WinForms is available athttp://msdn.microsoft.com/library/en-us/vbc<strong>on</strong>/html/vboriC<strong>on</strong>trolsForWinForms.asp.The .NET Framework is so extensible that numerous Independent Software Vendors(ISVs) have created unique c<strong>on</strong>trols or have enhanced the functi<strong>on</strong>s in existing .NETc<strong>on</strong> trols. Developers themselves can generate their own c<strong>on</strong>trols <str<strong>on</strong>g>for</str<strong>on</strong>g> pers<strong>on</strong>al needs.Man y of the most comm<strong>on</strong> c<strong>on</strong>trols emulate functi<strong>on</strong>ality that has been used in visual<str<strong>on</strong>g>for</str<strong>on</strong>g>m s <str<strong>on</strong>g>for</str<strong>on</strong>g> years, whether in classic Visual Basic, Delphi, or <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. One of the mostbeneficial properties of most c<strong>on</strong>trols is the capability <strong>to</strong> bind them <strong>to</strong> data sources.Data


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 291sources do not have <strong>to</strong> be ADO.NET objects. Sources can come from arrays and othercollecti<strong>on</strong>-type objects.Scenario 1: Rewriting <strong>to</strong> Visual Basic .NETC<strong>on</strong> verting from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong> Visual Basic .NET is n<strong>on</strong>-trivial. There is no <strong>to</strong>ol thatau<strong>to</strong>mates the c<strong>on</strong>versi<strong>on</strong> <strong>to</strong> VB.NET. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms, an applicati<strong>on</strong> can be separatedin<strong>to</strong> a visual or presentati<strong>on</strong> comp<strong>on</strong>ent and a code comp<strong>on</strong>ent. This separati<strong>on</strong> makesthe migrati<strong>on</strong> easier and is the approach used in this guidance.Two methods are available <strong>to</strong> c<strong>on</strong>vert <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong> Visual Basic.NET:● Case 1: Using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Designer● Case 2: Manually Redesigning the applicati<strong>on</strong>Case 1: Using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DesignerVisual Basic code is generated from the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Form applicati<strong>on</strong> using the Visual BasicGenera<strong>to</strong>r, which is a functi<strong>on</strong> of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Designer. The Visual Basic code is thenupgraded <strong>to</strong> Visual Basic.NET using the guidance available from Microsoft athttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbc<strong>on</strong>/html/vbc<strong>on</strong>upgradingapplicati<strong>on</strong>screatedinpreviousversi<strong>on</strong>sofvisualbasic.asp.At the time of publicati<strong>on</strong>, this method is not perfect. Many manual changes will still need<strong>to</strong> be made after the au<strong>to</strong>mated c<strong>on</strong>versi<strong>on</strong>. Using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Designer is still a usefulexe rcise because it provides a valuable template structure of the migrated Visual Basicapplicati<strong>on</strong> even though subsequent changes <strong>to</strong> the code will be necessary.Case 2: Manually Redesigning the Applicati<strong>on</strong>In this method, the entire <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> is documented and the newapplicati<strong>on</strong> is built in an orderly fashi<strong>on</strong>. To document and redesign the applicati<strong>on</strong>, follow these steps:1. Create a list of <str<strong>on</strong>g>for</str<strong>on</strong>g>ms found in the applicati<strong>on</strong> and note the relati<strong>on</strong>ship betweenthem.2. Create two models <str<strong>on</strong>g>for</str<strong>on</strong>g> each <str<strong>on</strong>g>for</str<strong>on</strong>g>m.The first model, which is called the Forms Model, will c<strong>on</strong>tain all the <str<strong>on</strong>g>for</str<strong>on</strong>g>ms comp<strong>on</strong>ents. TheForms Model will document the four modules: <str<strong>on</strong>g>for</str<strong>on</strong>g>ms module, menu module, object libraries,and PL/<strong>SQL</strong> libraries. The sec<strong>on</strong>d model, called the Visual Model, will document all thelayout-related comp<strong>on</strong>ents: windows, canvases, frames, and items3. Document the Forms Model.Open a <str<strong>on</strong>g>for</str<strong>on</strong>g>m in the Ownership View using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Designer and note thecomp<strong>on</strong>ents under each module with their hierarchy from module down <strong>to</strong> items.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the following acti<strong>on</strong>s:a. Start with documenting all the modules: <str<strong>on</strong>g>for</str<strong>on</strong>g>ms modules, menu modules, objectlibraries, and PL/<strong>SQL</strong> libraries using Figure 17. 1 as reference.b. For each module, incrementally refine the model with the next level of detailusing multiple passes.c. Document all the supporting comp<strong>on</strong>ents, such as LOVs, record groups, andprogram units, found under the <str<strong>on</strong>g>for</str<strong>on</strong>g>m module.d. Based <strong>on</strong> the size of the <str<strong>on</strong>g>for</str<strong>on</strong>g>m, submodels or documents may be prepared <str<strong>on</strong>g>for</str<strong>on</strong>g>subsecti<strong>on</strong>s of the model.


292 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Formse. A block document may be created <str<strong>on</strong>g>for</str<strong>on</strong>g> just the data blocks and c<strong>on</strong>trol blocks.Use <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> runtime in debug mode <strong>to</strong> understand the flow. When you run<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms in debug mode, the runtime envir<strong>on</strong>ment displays the name ofeach trigger when it fires. Operate the <str<strong>on</strong>g>for</str<strong>on</strong>g>m as a user and document the flow ofexecuti<strong>on</strong> in the blocks document.f. A procedures document c<strong>on</strong>taining a compilati<strong>on</strong> of PL/<strong>SQL</strong> code or programunit found in triggers, user-named subprograms, packages, PL/<strong>SQL</strong>-type menuitems, and menu startup code. All places in a <str<strong>on</strong>g>for</str<strong>on</strong>g>m which c<strong>on</strong>tained PL/<strong>SQL</strong>code can be c<strong>on</strong>veniently viewed by switching the <str<strong>on</strong>g>for</str<strong>on</strong>g>m view <strong>to</strong> Show PL/<strong>SQL</strong>Only. For each program unit, note the existence of <strong>SQL</strong> or calls <strong>to</strong> databases<strong>to</strong>red programs.4. Document the Visual Model.Open the <str<strong>on</strong>g>for</str<strong>on</strong>g>m in the Visual View using <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms Designer and note thecomp<strong>on</strong>ents under each module, capturing the hierarchical relati<strong>on</strong>ship asshown in Figure 17.3. Document all the visual characteristics <str<strong>on</strong>g>for</str<strong>on</strong>g> each of thecomp<strong>on</strong>ents.5. C<strong>on</strong>vert the shared code.Start the migrati<strong>on</strong> by c<strong>on</strong>verting the shared comp<strong>on</strong>ents that are under the objectlibraries and PL/<strong>SQL</strong> libraries. While migrating from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong>Visual Basic .NET, c<strong>on</strong>tinue <strong>to</strong> maintain the same logical grouping andorganizati<strong>on</strong> of the various <str<strong>on</strong>g>for</str<strong>on</strong>g>ms comp<strong>on</strong>ents, including the shared libraries.In Visual Basic .NET, create a class library project, <strong>on</strong>e each <str<strong>on</strong>g>for</str<strong>on</strong>g> the object librariesand the PL/<strong>SQL</strong> libraries.● Migrate the PL/<strong>SQL</strong> libraries.The procedures document c<strong>on</strong>tains the required in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> migrating thePL/<strong>SQL</strong> libraries. For each PL/<strong>SQL</strong> library, create a Visual Basic .NET class inthe target project. Each program unit in a library can be migrated in<strong>to</strong> methodswith the equivalent functi<strong>on</strong>ality.● Migrate the object libraries.The migrati<strong>on</strong> of the object libraries can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med using the Forms Model.For each object library, create a Visual Basic .NET class in the target project.Each object in a library can be migrated in<strong>to</strong> an equivalent method in the class.6.C<strong>on</strong>vert the Visual Model.Create a Visual Basic .NET Windows applicati<strong>on</strong> project. The goal in this step is<strong>on</strong>ly <strong>to</strong> build the shell visually identical <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>. In this step,you are c<strong>on</strong>cerned with the <str<strong>on</strong>g>for</str<strong>on</strong>g>m and not the functi<strong>on</strong>. The functi<strong>on</strong>ality will beaddressed in the next step. For example, a DataGrid c<strong>on</strong>trol will be added <strong>to</strong> a<str<strong>on</strong>g>for</str<strong>on</strong>g>m in this step while the tasks <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> and access data areper<str<strong>on</strong>g>for</str<strong>on</strong>g>med in the next step.For each window found in the Visual Model, create a <str<strong>on</strong>g>for</str<strong>on</strong>g>m in the project. InVisual Basic .NET, the c<strong>on</strong>cept of canvas is handled by the <str<strong>on</strong>g>for</str<strong>on</strong>g>m itself. The framesin the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> should be c<strong>on</strong>verted <strong>to</strong> panels inVisual Basic .NET. The items in a frame should be replaced with its equivalentc<strong>on</strong>trols. Also add the menu c<strong>on</strong>trols <strong>to</strong> match the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>.For steps <strong>on</strong> adding <str<strong>on</strong>g>for</str<strong>on</strong>g>ms <strong>to</strong> a project, refer <strong>to</strong>http://msdn. microsoft.com/library/default.asp?url=/library/enus/vbc<strong>on</strong>/html/vbtskadding<str<strong>on</strong>g>for</str<strong>on</strong>g>m<strong>to</strong>project.asp.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> how <strong>to</strong> add Windows Forms C<strong>on</strong>trols, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/vbc<strong>on</strong>/html/vboriwin<str<strong>on</strong>g>for</str<strong>on</strong>g>msc<strong>on</strong>trols.asp.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 293For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about learning the techniques <str<strong>on</strong>g>for</str<strong>on</strong>g> arranging the variousc<strong>on</strong>trols <strong>on</strong> a Windows Form, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url= /library/en-us/vbc<strong>on</strong>/html/vbc<strong>on</strong><str<strong>on</strong>g>for</str<strong>on</strong>g>msdesigner.asp.For guidance <strong>on</strong> adding menus, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/vbc<strong>on</strong>/html/vbc<strong>on</strong>windowsaccessories.asp.7. C<strong>on</strong>vert the Form Model.At this stage, all the pieces are in place <strong>to</strong> code the business logic and applicati<strong>on</strong>functi<strong>on</strong>ality. The majority of the work is related <strong>to</strong> c<strong>on</strong>verting the code in theblocks and items, which was documented in the block document. Because analmost <strong>on</strong>e-<strong>to</strong>-<strong>on</strong>e mapping of the shared libraries and its objects has beenper<str<strong>on</strong>g>for</str<strong>on</strong>g>med, the code in Visual Basic .NET can be written as a parallel <strong>to</strong> the code inthe source applicati<strong>on</strong>.a. Start by c<strong>on</strong>verting the comp<strong>on</strong>ents, such as c<strong>on</strong>trol blocks, program units,record groups, LOVs, and triggers that could be tied <strong>to</strong> multiple c<strong>on</strong>trols.b. Code all the data comp<strong>on</strong>ents in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m because these could be possiblyassociated with multiple c<strong>on</strong>trols. A detailed account <strong>on</strong> how <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m this isprovided in the "Adding Data Comp<strong>on</strong>ents <strong>to</strong> a Windows Form" secti<strong>on</strong> later inthis chapter.c. Complete the migrati<strong>on</strong> of the data block by adding code <strong>to</strong> read data and bindthe grid.d. Although the grid is bound <strong>to</strong> the dataset you created, the dataset itself is notau<strong>to</strong>matically filled in. Instead, you must fill the dataset by calling a datasclass file in theadapter method. Double-click the page <strong>to</strong> display the page'Code Edi<strong>to</strong>r. In the <str<strong>on</strong>g>for</str<strong>on</strong>g>m's event handler, call the data adapter's Fill method,passing it the dataset you want <strong>to</strong> populate: SqlDataAdapter1.Fill(dsDept).e. For more details <strong>on</strong> data binding and Windows Forms, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/vbc<strong>on</strong>/html/vboriwindows<str<strong>on</strong>g>for</str<strong>on</strong>g>msdataarchitecture.asp.f. The number of lines of code generated by the Data wizard is far in excess ofwhat would be required if using Data Access Applicati<strong>on</strong> Block (DAAB) <str<strong>on</strong>g>for</str<strong>on</strong>g>.NET.g. Examine every c<strong>on</strong>trol and add code <strong>to</strong> the c<strong>on</strong>trol and its event.h. Achieve the proper flow of executi<strong>on</strong> through navigati<strong>on</strong> rules similar <strong>to</strong> thatseen when executing the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Form applicati<strong>on</strong> in the debug mode.Adding Data Comp<strong>on</strong>ents <strong>to</strong> a Windows FormYou do not directly add a dataset <strong>to</strong> a page. Access <strong>to</strong> the dataset can be created in <strong>on</strong>eof several ways. There are two preferred methods. One method is <strong>to</strong> use the set of visualobjects available in the Toolbox under the Data tab. The other is <strong>to</strong> take advantage ofthe Microsoft Data Access Applicati<strong>on</strong> Block <str<strong>on</strong>g>for</str<strong>on</strong>g> .NET.


294 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> FormsUsing the Visual Studio .NET Data WizardsVisual Studio® .NET Data Wizards are ADO.NET code genera<strong>to</strong>rs <str<strong>on</strong>g>for</str<strong>on</strong>g> creating access<strong>to</strong> <strong>SQL</strong> <strong>Server</strong>, OLEDB, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, and ODBC data soluti<strong>on</strong>s. There is a small series of dataobjects needed <strong>to</strong> generate datasets <strong>to</strong> sources under ADO.NET. They areDataAdapters, c<strong>on</strong>necti<strong>on</strong>s, commands, and the datasets themselves. C<strong>on</strong>necti<strong>on</strong>sprovide the necessary in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about data sources, authenticati<strong>on</strong>, and poolingopti<strong>on</strong>s. Commands define whether the source is queried through s<strong>to</strong>red procedures,direct table access, or through T-<strong>SQL</strong> Statements. DataAdapters provide a specific pipe<str<strong>on</strong>g>for</str<strong>on</strong>g> accessing data and trans<str<strong>on</strong>g>for</str<strong>on</strong>g>ming it back <strong>to</strong> the source by creating the Select, Update,Insert, and Delete commands; creating s<strong>to</strong>red procedures; or using existing s<strong>to</strong>redprocedures. DataSets act as the virtual database <strong>to</strong> the client. To use the wizards <strong>to</strong> access <strong>SQL</strong> <strong>Server</strong>, follow these steps:1. Create the SqlAdapter.From the Toolbox within VS.NET, choose the Data tab and drag theSqlDataAdapter <strong>on</strong><strong>to</strong> the <str<strong>on</strong>g>for</str<strong>on</strong>g>m area. If other data providers are needed, choose theappropriate OLEDB or ODBC Data Adapter. The wizard will start, and aSqlDataAdapter1 object will be created in the Comp<strong>on</strong>ent Tray area beneath the<str<strong>on</strong>g>for</str<strong>on</strong>g>m.2. Reference the c<strong>on</strong>necti<strong>on</strong>.The next step of the wizard is <strong>to</strong> choose from a drop-down list of pre-existingc<strong>on</strong>necti<strong>on</strong>s used with VS.NET or <strong>to</strong> generate a new c<strong>on</strong>necti<strong>on</strong>. Clicking NewC<strong>on</strong>necti<strong>on</strong> brings up the DataLink Properties dialog box <strong>to</strong> create the newc<strong>on</strong>necti<strong>on</strong> object.3. Choose a query type.The wizard then allows the developer <strong>to</strong> choose between <strong>SQL</strong> statements ors<strong>to</strong>red procedures. As previously menti<strong>on</strong>ed, it is best <strong>to</strong> use s<strong>to</strong>red procedureswhen possible.4. Generate the <strong>SQL</strong> statements, s<strong>to</strong>red procedures, or bind the commands.Depending <strong>on</strong> the choice in the previous step, the developer will be given theopportunity <strong>to</strong> provide or create an appropriate <strong>SQL</strong> statement. Inspecting thePL/<strong>SQL</strong> code is described earlier in the secti<strong>on</strong> "PL/<strong>SQL</strong> Library."5. Finish the wizard.Now the Comp<strong>on</strong>ent Tray c<strong>on</strong>tains both the SqlDataAdapter1 and SqlC<strong>on</strong>necti<strong>on</strong>1objects. The in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> created from the wizard can be viewed in from theProperties window of the designer or by looking at the generated code. TheProperties window of the DataAdapter shows the commands chosen (Delete,Insert, Select, Update) and their respective properties.6. Generate the DataSet.Now that the reference has been made <strong>to</strong> the source and the pipe has beencreated <strong>to</strong> work with the source, it is necessary <strong>to</strong> provide the client with the result.The c<strong>on</strong>tainer necessary <str<strong>on</strong>g>for</str<strong>on</strong>g> this is a dataset. Because the dataset is based <strong>on</strong> thein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> provided by the adapter, Visual Studio .NET has a wizard <strong>to</strong> takeadvantage of the in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> s<strong>to</strong>red within the adapter. This is d<strong>on</strong>e by rightclickingthe SqlDataAdapter1 inside the comp<strong>on</strong>ent tray, clicking Generatedataset, and then choosing most of the defaults (except when the object isrenamed).Using the Microsoft Data Access Applicati<strong>on</strong> BlockThe Data Access Applicati<strong>on</strong> Block encapsulates per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and resourcemanagement preferred practices <str<strong>on</strong>g>for</str<strong>on</strong>g> accessing <strong>SQL</strong> <strong>Server</strong> databases. If used, it willreduce the amount of cus<strong>to</strong>m code needed <strong>to</strong> create, test, and maintain.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 295Specifically, the Data Access Applicati<strong>on</strong> Block helps you:●●●Call s<strong>to</strong>red procedures or <strong>SQL</strong> text commands.Specify parameter details.Return SqlDataReader, DataSet or XMLReader objects.Instead of using the wizards (which create numerous references <strong>to</strong> adapter, command,and c<strong>on</strong>necti<strong>on</strong> objects), the Data Access Applicati<strong>on</strong> Block (DAAB) helps limit thecreati<strong>on</strong> of datasets <strong>to</strong> as little as <strong>on</strong>e line of code.The Data Access Applicati<strong>on</strong> Block is available athttp://www.microsoft.com/downloads/details.aspx?FamilyId=F63D1F0A-9877-4A7B-88EC-0426B48DF275&displaylang=en. After downloading, compile the assembly in theVB assembly. It will now be available <strong>to</strong> be referenced by any Visual Basic .NETapplicati<strong>on</strong>.Calling T-<strong>SQL</strong> S<strong>to</strong>red Procedures from Windows FormsTo call a s<strong>to</strong>red procedure, you first need <strong>to</strong> identify the s<strong>to</strong>red procedure, and thencreate a DataReader or DataAdapter object. Each requires a database c<strong>on</strong>necti<strong>on</strong> and areference <strong>to</strong> the s<strong>to</strong>red procedure name through the CommandText property. Next, youset the CommandType property <strong>to</strong> CommandType.S<strong>to</strong>redProcedure. Finally, anys<strong>to</strong>red procedure parameters need <strong>to</strong> be defined <str<strong>on</strong>g>for</str<strong>on</strong>g> input and/or output in a collecti<strong>on</strong> ofparameter objects. If the DataReader is used, then the developer must fill the appropriatec<strong>on</strong>trols by iterating though the collecti<strong>on</strong> of rows returned and applying the values <strong>to</strong> thec<strong>on</strong>trols. If the DataAdapter is used, then a DataSet must be filled and the c<strong>on</strong>trols mustbe bound through the DataSource or DataBinding properties.Testin g the Visual Basic .NET Applicati<strong>on</strong>The Visual Basic .NET applicati<strong>on</strong> is a newly written applicati<strong>on</strong> instead of a migratedapplicati<strong>on</strong>. Even though <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms and Visual Basic are architecturally andfuncti<strong>on</strong>ally similar, n<strong>on</strong>e of the code is reusable. Hence the applicati<strong>on</strong> should undergounit testing using a procedure that would be followed <str<strong>on</strong>g>for</str<strong>on</strong>g> new development. However, thisnewly developed Visual Basic .NET applicati<strong>on</strong> does differ from other new developmentprojects. Remember that the Visual Basic .NET applicati<strong>on</strong> was designed <strong>to</strong> mimic the<str<strong>on</strong>g>for</str<strong>on</strong>g>m and functi<strong>on</strong> of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong>, while most applicati<strong>on</strong>s are develop edbased <strong>on</strong> documented requirements.The objective of unit testing is <strong>to</strong> verify that the user interface closely resembles the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>Forms applicati<strong>on</strong> and every comp<strong>on</strong>ent functi<strong>on</strong>s correctly. Start by visuallycomparing every frame in th e <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms applicati<strong>on</strong> <strong>to</strong> the corresp<strong>on</strong>ding window inVisual Basic .NET. Ensure that all panels are present. E nsure that all the c<strong>on</strong>trols (items)are accurately presented <strong>on</strong> the panel. Crosscheck all the visual comp<strong>on</strong>ents against theVisual Model.The event models differ from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms <strong>to</strong> Visual Basic .NET. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Forms c<strong>on</strong>tainsa nested hierarchy, with events being fired when moving through the window and itsobjects. These have <strong>to</strong> be duplicated in Visual Basic . NET. Verify the behavior byper<str<strong>on</strong>g>for</str<strong>on</strong>g>ming a walk-through of the entire applicati<strong>on</strong> with tracing and debugging enabled.The logs can later be reviewed <str<strong>on</strong>g>for</str<strong>on</strong>g> errors and executi<strong>on</strong> sequences. Visual Basic .NETp rovides a set of methods and properties that help you trace and debug the executi<strong>on</strong>.Interactive debuggers are also available in the Visual Studio .NET SDK.The applicati<strong>on</strong> should then be tested <str<strong>on</strong>g>for</str<strong>on</strong>g> functi<strong>on</strong>ality. Start with testing the menus andthen drilling down window-by-window. Test the functi<strong>on</strong>alityof every c<strong>on</strong>trol. Use the


296 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Formssame set of test cases in both applicati<strong>on</strong>s. Populate the test data in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m and click allthe c<strong>on</strong>trols. Verify that all the functi<strong>on</strong>al areas and navigati<strong>on</strong> match the old applicati<strong>on</strong>.Validate that the presentati<strong>on</strong> domain screens are all called by the applicati<strong>on</strong>.For detailed guidance about all aspects of testing your Visual Basic .NET applicati<strong>on</strong> andthe available <strong>to</strong>ols, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/vsent7/html/vxoriTestingOptimizing.asp.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 29718Stabilizing PhaseIntroducti<strong>on</strong> and GoalsDuring this phase, the test team verifies that the soluti<strong>on</strong> meets the defined quality levelsand that the risk of bugs is eliminated or minimized. Any existing bugs should not affectcritical functi<strong>on</strong>ality or per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. After the soluti<strong>on</strong> has been stabilized, it will be ready<str<strong>on</strong>g>for</str<strong>on</strong>g> deployment in<strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment. This chapter highlights the processes ofstabilizati<strong>on</strong> as they relate <strong>to</strong> an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> Microsoft® <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>Windows® migrati<strong>on</strong> project.The main goals <str<strong>on</strong>g>for</str<strong>on</strong>g> the Stabilizing Phase include:● Improve the overall quality of the migrated soluti<strong>on</strong> and stabilize <str<strong>on</strong>g>for</str<strong>on</strong>g> release.● Ensure that the soluti<strong>on</strong> meets the requirements of the project outlined in theEnvisi<strong>on</strong>ing and Planning Phases.● Assemble all of the comp<strong>on</strong>ents of the soluti<strong>on</strong> and test the entire system be<str<strong>on</strong>g>for</str<strong>on</strong>g>edeployment.● Complete and validate documentati<strong>on</strong> that is required <str<strong>on</strong>g>for</str<strong>on</strong>g> deployment, operati<strong>on</strong>s,and end users.● Evaluate and mitigate the risks involved in releasing the soluti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> deployment.The deliverables produced during the Stabilizing Phase are listed in Table 18.1.Table 18.1: Deliverables <str<strong>on</strong>g>for</str<strong>on</strong>g> the Stabilizing PhaseTask Deliverables OwnerTesting the soluti<strong>on</strong> Release versi<strong>on</strong>s of source Test Rolecode, executables, releaseversi<strong>on</strong> of scripts, andinstallati<strong>on</strong> documentati<strong>on</strong>Testing the soluti<strong>on</strong> Release versi<strong>on</strong>s of enduserUser Experience Roletraining materials andoperati<strong>on</strong>s documentati<strong>on</strong>Testing the soluti<strong>on</strong> Release notes Release ManagementBug tracking and reporting Testing and bug reports Test RolePiloting the soluti<strong>on</strong> Pilot Review Release ManagementPiloting the soluti<strong>on</strong> Project documents Program ManagementPiloting the soluti<strong>on</strong> Sign off document Project team


298 Stabilizing PhaseTestingThe Stabilizing Phase c<strong>on</strong>sists of two major activities: testing the soluti<strong>on</strong> and piloting thesoluti<strong>on</strong>. During testing, the entire ecosystem is evaluated, including the hardware,software, database, c<strong>on</strong>nectivity layer, and the applicati<strong>on</strong>. As a result of the testing,bugs and issues will be tracked and resolved.The sec<strong>on</strong>d major activity of the Stabilizing Phase pertains <strong>to</strong> piloting the soluti<strong>on</strong> <strong>to</strong> aselect group c<strong>on</strong>sisting of end users, deployment, and operati<strong>on</strong>s pers<strong>on</strong>nel in theproducti<strong>on</strong> envir<strong>on</strong>ment. Pilot testing also helps anticipate and resolve any issues thatmay occur during deployment. While piloting the soluti<strong>on</strong> is opti<strong>on</strong>al, this activity is highlyrecommended because comp<strong>on</strong>ents are deployed in<strong>to</strong> the Windows envir<strong>on</strong>ment thatwere originally developed <str<strong>on</strong>g>for</str<strong>on</strong>g> another plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.Testing is an iterative refinement process and is initiated every time there is a change <strong>to</strong>the soluti<strong>on</strong> (including bug fixes). The occurrence of sec<strong>on</strong>d and third iterati<strong>on</strong>s iscomm<strong>on</strong> in data migrati<strong>on</strong>s involving complex data integrity rules. Applicati<strong>on</strong> testing willvary based <strong>on</strong> the amount of modificati<strong>on</strong>s needed <strong>to</strong> migrate the soluti<strong>on</strong> applicati<strong>on</strong>.Fo r example, when an applicati<strong>on</strong> is ported, the code coverage tests may be givenlimited importance because the code base has not changed from the existing applicati<strong>on</strong>.The test team should accumulate complete knowledge of the software's functi<strong>on</strong>ality andthe tests that should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> verify them. Often, the original designc<strong>on</strong>siderati<strong>on</strong>s and approach used <strong>to</strong> create the existing soluti<strong>on</strong> are not available <strong>to</strong> themigrati<strong>on</strong> team. This limits the effective knowledge of the test team. Testing should notbe limited <strong>on</strong>ly <strong>to</strong> the parts that the developers have identified as affected by themigrati<strong>on</strong>. Changes in the backend database and the envir<strong>on</strong>ment can manifest itself inunpredictable places.The project team should reuse test cases from the existing soluti<strong>on</strong>. If n<strong>on</strong>e exist, newtest cases can be created from the business requirements of the existing soluti<strong>on</strong>. Testscan then be run against both the source and target systems in the migrati<strong>on</strong> project andthe results compared <strong>to</strong> identify deviati<strong>on</strong>s and bugs in the new soluti<strong>on</strong>.Logs and audit reports that document any defects associated with the applicati<strong>on</strong>s need<strong>to</strong> be created and published <strong>to</strong> the entire team in c<strong>on</strong>juncti<strong>on</strong> with the tests per<str<strong>on</strong>g>for</str<strong>on</strong>g>med.This is because the source of the bug and the place where it manifests itself may bedifferent. For example, even though a problem may be detected in the applicati<strong>on</strong>, thesource may be a database c<strong>on</strong>figurati<strong>on</strong> or a hardware setting.Each iterati<strong>on</strong> of testing helps make the subsequent iterati<strong>on</strong> more robust and completethan the previous <strong>on</strong>e. This process must c<strong>on</strong>tinue until an iterati<strong>on</strong> has no excepti<strong>on</strong>s.The number of tests completed and the defect rate are used <strong>to</strong> measure progress andschedule c<strong>on</strong><str<strong>on</strong>g>for</str<strong>on</strong>g>mance.A c omprehensive series of tests is key <strong>to</strong> meeting the goals of the Stabilizing Phase.The se tests provide assurances of the quality and stability of the soluti<strong>on</strong>. The followingsecti<strong>on</strong>s provide in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about:● Best practices● Preparing <str<strong>on</strong>g>for</str<strong>on</strong>g> testing●●●the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>Types of testingBug tracking and reportingUser Acceptance Testing (UAT) and signoff


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 299This in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> will help you assure the quality and stability of the soluti<strong>on</strong> you havedeveloped.Best PracticesWhen testing a soluti<strong>on</strong>, two important best practices are clearly defining the successcriteria and approaching testing with a zero-defect mindset.Success CriteriaJudging whether a project has been successful is almost impossible without something <strong>to</strong>measure the project's results against. Success criteria, also called key per<str<strong>on</strong>g>for</str<strong>on</strong>g>manceindica<strong>to</strong>rs (KPIs), can be created by defining c<strong>on</strong>diti<strong>on</strong>s under which the proposedsoluti<strong>on</strong> will achieve its goals. In a migrati<strong>on</strong> project, the success criteria can be gaugedby the effectiveness of the new soluti<strong>on</strong>. Does it effectively replace the existing soluti<strong>on</strong> interms of features, per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, and functi<strong>on</strong> based <strong>on</strong> results from the test cases?Note Though measured in the Stabilizing Phase, success criteria <str<strong>on</strong>g>for</str<strong>on</strong>g> a project isestablished during the Envisi<strong>on</strong>ing and Planning Phases.Zero-defect MindsetThe c<strong>on</strong>cept of a zero-defect mindset should encompass the project team's commitment<strong>to</strong> p roducing the highest quality product possible. Each member is individuallyresp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> helping achieve the desired level of quality.The zero-defect mindset does not mean that the deployed soluti<strong>on</strong> must be flawless;rather, it specifies a predetermined quality bar <str<strong>on</strong>g>for</str<strong>on</strong>g> the deliverables. Oftentimes, theproject schedule will play a determining fac<strong>to</strong>r in achieving a zero-defect soluti<strong>on</strong>. Insituati<strong>on</strong>s where schedule does not allow <str<strong>on</strong>g>for</str<strong>on</strong>g> complete testing, tests should be prioritized<strong>to</strong> ensure that all critical functi<strong>on</strong>ality is evaluated.In additi<strong>on</strong>, the zero-defect mindset c<strong>on</strong>cept should be carried throughout the dynamiclife cycle of the soluti<strong>on</strong>. For example, as the database scales over time, additi<strong>on</strong>al tuningwill be required <strong>to</strong> ensure optimum per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.Preparing <str<strong>on</strong>g>for</str<strong>on</strong>g> TestingPreparati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> testing involves creating two key items:● Test envir<strong>on</strong>ment● Bug tracking systemEach of these items is discussed under the following headings.The Test Envir<strong>on</strong>mentThe development and test plans provide a list of requirements that must be met by thetest envir<strong>on</strong>ment, and the test envir<strong>on</strong>ment should be set up according <strong>to</strong> them. The testenvir<strong>on</strong>ment should be completely separate from the producti<strong>on</strong> envir<strong>on</strong>ment. Although itmay not mirror the producti<strong>on</strong> envir<strong>on</strong>ment, it is best if it does.If the development phase is completed, the same hardware and software may be used <strong>to</strong>test the soluti<strong>on</strong>. If the needs <str<strong>on</strong>g>for</str<strong>on</strong>g> the testing envir<strong>on</strong>ment are more demanding, thenadditi<strong>on</strong>al resources may be required. In some situati<strong>on</strong>s, it may be necessary <strong>to</strong> scalethe testing based <strong>on</strong> the available hardware.In MSF, setting up the test envir<strong>on</strong>ment starts <strong>to</strong>ward the end of the Planning Phase. Thisis <strong>to</strong> make sure that a test envir<strong>on</strong>ment is available <strong>to</strong> the development team while


300 Stabilizing Phaseindividual comp<strong>on</strong>ents are being developed. However, a full-scale test envir<strong>on</strong>ment <strong>to</strong>verify all aspects of an integrated soluti<strong>on</strong> will <strong>on</strong>ly be required in the Stabilizing Phase.Another c<strong>on</strong>siderati<strong>on</strong> of the testing envir<strong>on</strong>ment is ensuring that it is properly tunedbe<str<strong>on</strong>g>for</str<strong>on</strong>g>e testing commences. Some recommended best practices <str<strong>on</strong>g>for</str<strong>on</strong>g> optimal tuning of<strong>SQL</strong> <strong>Server</strong> running under Windows 2003 include:● Format disk partiti<strong>on</strong>s using NTFS 5.0. This file system provides per<str<strong>on</strong>g>for</str<strong>on</strong>g>manceenhancements in Windows 2003.● C<strong>on</strong>figure <strong>SQL</strong> <strong>Server</strong> as a stand-al<strong>on</strong>e server. If c<strong>on</strong>figured as a domainc<strong>on</strong>troller,additi<strong>on</strong>al resources are utilized, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is reduced.● Set the Applicati<strong>on</strong> Resp<strong>on</strong>se setting <strong>to</strong> optimize <str<strong>on</strong>g>for</str<strong>on</strong>g> background services. Thissetting allows background services <strong>to</strong> run at a higher priority than <str<strong>on</strong>g>for</str<strong>on</strong>g>egroundapplicati<strong>on</strong>s and is accessed through the System ic<strong>on</strong> in the C<strong>on</strong>trol Panel. Thissetting will improve the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of <strong>SQL</strong> <strong>Server</strong>.● Turn off additi<strong>on</strong>al security auditing. This will reduce I/O activities.● Set the size of PAGEFILE.SYS. M<strong>on</strong>i<strong>to</strong>r the usage of this swap file used by<strong>SQL</strong> <strong>Server</strong> and resize the resources slightly larger than your needs.● Turn off unnecessary services. Review all services and determine which can beturned off.● Turn off unnecessary network pro<strong>to</strong>cols.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> tuning the test envir<strong>on</strong>ment, refer <strong>to</strong>http://www.microsoft.com/windowsserver2003/evaluati<strong>on</strong>/per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance/tuning.mspx.Bug Tracking <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>An effective bug tracking system is needed <strong>to</strong> make sure that bugs are identified andissues are not dropped until they have been completely resolved. Projects typically haveseveral hundreds or thousands of bugs. It is imperative <strong>to</strong> have a robust bug trackingsystem in place <strong>to</strong> address these issues.The bug tracking software <str<strong>on</strong>g>for</str<strong>on</strong>g> the project was selected during the Planning Phase. Usingthis software from the beginning of testing allows all bugs identified through the life cycleof the soluti<strong>on</strong> <strong>to</strong> be tracked in <strong>on</strong>e locati<strong>on</strong>. This testing his<strong>to</strong>ry can also be a usefulreference <str<strong>on</strong>g>for</str<strong>on</strong>g> future releases after the soluti<strong>on</strong> has been deployed.Bug categorizati<strong>on</strong> is an important c<strong>on</strong>siderati<strong>on</strong> during the c<strong>on</strong>figurati<strong>on</strong> process of thebug tracking soluti<strong>on</strong>. Variables required by the categorizati<strong>on</strong> may affect thec<strong>on</strong>figurati<strong>on</strong> of new and existing bug tracking soluti<strong>on</strong>s. These variables include:● Repeatability. This is a variable that measures how repeatable the issue or bug is.Repeatability is the percentage of the time the issue or bug manifests itself.● Visibility. This is a variable that measures the situati<strong>on</strong> or envir<strong>on</strong>ment that mustbe established be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the issue or bug manifests itself. For example, if the issue orbug occurs <strong>on</strong>ly when the user holds down the Shift key while right-clicking themouse and viewing the File menu, the percentage of obscurity is likely <strong>to</strong> be high.● Severity. This is a variable that measures how much impact the issue or bug willproduce in the soluti<strong>on</strong>, in the code, or <strong>to</strong> the users. For example, a bug thatcauses the applicati<strong>on</strong> <strong>to</strong> crash would rank higher than situati<strong>on</strong>s that allow theapplicati<strong>on</strong> <strong>to</strong> recover.These three variables are estimated and assigned <strong>to</strong> each issue or bug by the projectteam and are used <strong>to</strong> derive the issue or bug priority.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 301Note The priority of a bug can be calculated by using the following <str<strong>on</strong>g>for</str<strong>on</strong>g>mula:(repeatability + visibility) * severity = priorityTypes of TestingOften, the test envir<strong>on</strong>ment is the first place that all of the separate comp<strong>on</strong>ents (thathave been unit tested in the Development Phase) are combined in<strong>to</strong> a fully functi<strong>on</strong>alversi<strong>on</strong> of the soluti<strong>on</strong>. The first task is <strong>to</strong> ensure that the disparate comp<strong>on</strong>ents of thesoluti<strong>on</strong> integrate properly. Next, ensure that the soluti<strong>on</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ms as expected. The nextseries of tests check <strong>to</strong> ensure that the soluti<strong>on</strong> will work properly under heavyworkloads. The final set of tests check the soluti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> operati<strong>on</strong>al aspects.The following types of testing are useful in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> migrati<strong>on</strong>:● Integrati<strong>on</strong> testing. Does the soluti<strong>on</strong> work as a cohesive unit?● Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testing. Does the soluti<strong>on</strong> meet the baseline requirements?● Stress testing. How does the soluti<strong>on</strong> react <strong>to</strong> stresses and workloads?● Scalability testing. How far will the soluti<strong>on</strong> scale? Can the system handleincreased load by adding new hardware as required?● Operati<strong>on</strong>al testing. Do the operati<strong>on</strong>al aspects of the system per<str<strong>on</strong>g>for</str<strong>on</strong>g>m asexpected?Each of these testing types is described under the following headings.Integrati<strong>on</strong> TestingThe first level of testing in the Stabilizing Phase is integrati<strong>on</strong> testing, an iterative processin which separate comp<strong>on</strong>ents are combined in<strong>to</strong> larger soluti<strong>on</strong>s until the system iscomplete. In integrati<strong>on</strong> testing, the focus is <strong>on</strong> the interfaces between comp<strong>on</strong>ents.Integrati<strong>on</strong> testing proves that all areas of the system interface with each other correctlyand that there are no gaps in communicati<strong>on</strong>. The final integrati<strong>on</strong> test proves that theenti re system works as an integrated unit.Integrati<strong>on</strong> testing will also reveal any issues with shared resources. For instance, ifPretty Good Privacy (PGP) encrypti<strong>on</strong> is used by more than <strong>on</strong>e applicati<strong>on</strong>, instead ofhaving a separate key <str<strong>on</strong>g>for</str<strong>on</strong>g> each applicati<strong>on</strong>, multiple applicati<strong>on</strong>s could potentially share asingle key.If server c<strong>on</strong>solidati<strong>on</strong> is a business goal <str<strong>on</strong>g>for</str<strong>on</strong>g> this soluti<strong>on</strong>, then it has <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med atthis stage. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> server c<strong>on</strong>solidati<strong>on</strong>, refer <strong>to</strong>ht tp://www.microsoft.com/downloads/details.aspx?FamilyId=0F70695E-5D0B-4781-8966-84BE43216F9E&displaylang=en.Resolving Integrati<strong>on</strong> IssuesThe major reas<strong>on</strong>s issues arise during integrati<strong>on</strong> testing are incompatibilities orinc<strong>on</strong>sistencies in the design or implementati<strong>on</strong> of the interfaces between comp<strong>on</strong>ents. Ina migrati<strong>on</strong> project, such issues are bound <strong>to</strong> occur because of interoperati<strong>on</strong> betweenapplicati<strong>on</strong>s, changes in command usage, and differences in pro<strong>to</strong>cols between the twoplat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms. Such issues should be logged and <str<strong>on</strong>g>for</str<strong>on</strong>g>warded <strong>to</strong> the development team <str<strong>on</strong>g>for</str<strong>on</strong>g>resoluti<strong>on</strong>. Another comm<strong>on</strong>ly encountered issue is resource shortage because severalcomp<strong>on</strong>ents are being assembled <str<strong>on</strong>g>for</str<strong>on</strong>g> the first time. Additi<strong>on</strong>al resources, such asprocessor, memory, and s<strong>to</strong>rage, should be made available <strong>to</strong> complete the testing.


302 Stabilizing PhasePer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance TestingPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testing involves evaluating how well the soluti<strong>on</strong> meets the expectedcriteria. Testing <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance can be further defined by two sub-types:● Applicati<strong>on</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testing● Hardware utilizati<strong>on</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testingApplicati<strong>on</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testing in a migrati<strong>on</strong> focuses <strong>on</strong> comparing various speed andefficiency fac<strong>to</strong>rs between the existing soluti<strong>on</strong> and the migrated soluti<strong>on</strong>. This ensuresthat the migrated soluti<strong>on</strong> complies with the expected level of per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.These key speed and efficiency fac<strong>to</strong>rs include:● Throughput. Database throughput measures the <strong>to</strong>tal number of transacti<strong>on</strong>s thatthe server can handle in a given time frame. Baseline figures from the existingsoluti<strong>on</strong> are needed <str<strong>on</strong>g>for</str<strong>on</strong>g> comparis<strong>on</strong>. Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testing must be executed usinga workload that represents the type of operati<strong>on</strong>s that are most frequentlyper<str<strong>on</strong>g>for</str<strong>on</strong>g>med in the producti<strong>on</strong> envir<strong>on</strong>ment.Note For a detailed discussi<strong>on</strong> of baselines, see Appendix C, "Baselining."●Resp<strong>on</strong>se time. Resp<strong>on</strong>se time measures the length of time required <strong>to</strong> return thefirst row of the result set.The following resources can be used <strong>to</strong> c<strong>on</strong>duct per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance testing:● Checklist: <strong>SQL</strong> <strong>Server</strong> Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancehttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetcheck08.asp.● Windows 2003 Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and Scalabilityhttp://www.microsoft.com/windowsserver2003/evaluati<strong>on</strong>/per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance/perfscaling.mspx● Testing <strong>to</strong>olshttp://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_perfm<strong>on</strong>_1qgj.asp.● CPU M<strong>on</strong>i<strong>to</strong>rhttp://www.sysinternals.com/ntw2k/freeware/cpum<strong>on</strong>.shtml● Disk M<strong>on</strong>i<strong>to</strong>rhttp://www.sysinternals.com/ntw2k/freeware/diskm<strong>on</strong>.shtmlTesting hardware per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance in a cross-plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m migrati<strong>on</strong> is recommended becauseadditi<strong>on</strong>al adjustments may need <strong>to</strong> be made <strong>to</strong> the proposed soluti<strong>on</strong>. There are noreliable benchmarks that can provide equivalency per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance statistics between the<strong>UNIX</strong> and Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m. The results of benchmarks of the popular Transacti<strong>on</strong>Processing Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Council (http://www.tpc.org/) can be used as a guideline. Youshould ask the assistance of the vendors in per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming lab testing of your soluti<strong>on</strong> <strong>to</strong> getmore accurate numbers <strong>on</strong> the proposed hardware. This testing validates the hardwarerequirements <str<strong>on</strong>g>for</str<strong>on</strong>g> the soluti<strong>on</strong>.While c<strong>on</strong>ducting per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance tests, capture data regarding the utilizati<strong>on</strong> of resourcessuch as CPU, memory, disk I/O, and network bandwidth. This is important because ifyour testing envir<strong>on</strong>ment is not the same scale as the producti<strong>on</strong> load, then bottlenecksin these resources may not be discovered until deployment. Resource utilizati<strong>on</strong> data,captured at various load levels, can be used <strong>to</strong> draw c<strong>on</strong>clusi<strong>on</strong>s about resourcerequirements at producti<strong>on</strong> loads.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 303●●<strong>Net</strong>work M<strong>on</strong>i<strong>to</strong>rhttp://msdn.microsoft.com/library/default.asp?url=/library/enus/netm<strong>on</strong>/netm<strong>on</strong>/about_network_m<strong>on</strong>i<strong>to</strong>r_2_0.aspFile M<strong>on</strong>i<strong>to</strong>rhttp://www.sysinternals.com/ntw2K/source/filem<strong>on</strong>.shtmlResolving Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance IssuesPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance problems can occur because of several reas<strong>on</strong>s: applicati<strong>on</strong> code,database implementati<strong>on</strong>, hardware c<strong>on</strong>figurati<strong>on</strong>, software c<strong>on</strong>figurati<strong>on</strong>, or resourceavailability. The testing team should be able <strong>to</strong> solve c<strong>on</strong>figurati<strong>on</strong> and resourceproblems themselves, while issues with the applicati<strong>on</strong> and database should be loggedand <str<strong>on</strong>g>for</str<strong>on</strong>g>warded <strong>to</strong> the development team, al<strong>on</strong>g with any analysis and supportingevidence <str<strong>on</strong>g>for</str<strong>on</strong>g> resoluti<strong>on</strong>. Additi<strong>on</strong>al resources may have <strong>to</strong> be procured <strong>to</strong> solve resource-related hardware issues.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance tuning can be an <strong>on</strong>going series of refinements and improvements. A largeamount of in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> regarding per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance tuning is available. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>,refer <strong>to</strong> the following resources:● The Data Tier: An Approach <strong>to</strong> Database Optimizati<strong>on</strong>http://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/enus/part10/c3361.mspx● Improving <strong>SQL</strong> <strong>Server</strong> Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance includes schemas, queries, indexes,transacti<strong>on</strong>s, s<strong>to</strong>red procedures, executi<strong>on</strong> plans and tuning <strong>to</strong>pics.http://msdn.microsoft.com/sql/default.aspx?pull=/library/en-us/dnpag/html/scalenetchapt14.asp● How To: Optimize <strong>SQL</strong> Querieshttp://msdn.microsoft.com/sql/default.aspx?pull=/library/enus/dnpag/html/scalenethow<strong>to</strong>04.asp● How To: Optimize <strong>SQL</strong> Indexeshttp://msdn.microsoft.com/sql/default.aspx?pull=/library/enus/dnpag/html/scalenethow<strong>to</strong>03.asp● Microsoft <strong>SQL</strong> <strong>Server</strong> 2000 Index Defragmentati<strong>on</strong> Best Practiceshttp://www.microsoft. com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx● Using Views with a View <strong>on</strong> Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancehttp://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/en-us/part10/c3661.mspx● Microsoft S<strong>to</strong>rage <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s — The Right S<strong>to</strong>rage and Productivity <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>http://www.microsoft.com/windowsserversystem/s<strong>to</strong>rage/soluti<strong>on</strong>s/rightsoluti<strong>on</strong>/rightsoluti<strong>on</strong>.mspxStress TestingStress testing is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> determine the load at which the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance isunacceptable or the system fails. This involves loading the system bey<strong>on</strong>d the use it wasdesigned <str<strong>on</strong>g>for</str<strong>on</strong>g> and checking <str<strong>on</strong>g>for</str<strong>on</strong>g> issues. Whenper<str<strong>on</strong>g>for</str<strong>on</strong>g>ming stress tests, new bugs or issuesoften may surface because of the high stress and load levels. At a minimum, stresstesting should load the system as defined in the business goals.If the test envir<strong>on</strong>ment is scaled down in relati<strong>on</strong> <strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment, thelimitati<strong>on</strong>s of the testing envir<strong>on</strong>ment in relati<strong>on</strong> <strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment should bec<strong>on</strong>sidered in the results.


304 Stabilizing PhaseFor example, with respect <strong>to</strong> applicati<strong>on</strong>s, there may be a failure when the number ofsimultaneous c<strong>on</strong>necti<strong>on</strong>s hit 100. This could be because of the limitati<strong>on</strong> of somevariable associated with the code segment related <strong>to</strong> c<strong>on</strong>necti<strong>on</strong> handling. Similarproblems may be encountered <strong>on</strong>ly during stress testing because there will bedifferences in resource c<strong>on</strong>sumpti<strong>on</strong> and low-level implementati<strong>on</strong> of the same functi<strong>on</strong>sbetween the <strong>UNIX</strong> and Windows plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.Resolving Stress IssuesStress testing should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>on</strong>ly after all issues encountered during per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancetesting have been fixed. Bugs encountered during stress testing can be because of theapplicati<strong>on</strong>, the hardware c<strong>on</strong>figurati<strong>on</strong>, or resource availability. Issues or bugs found withthe applicati<strong>on</strong> have <strong>to</strong> be sent <strong>to</strong> the development team with any pertinent in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. Ifthe issues relate directly <strong>to</strong> hardware or hardware resources, they can be solved byc<strong>on</strong>figurati<strong>on</strong> or adding additi<strong>on</strong>al resources.For example, <strong>SQL</strong> <strong>Server</strong> is not c<strong>on</strong>figured <strong>to</strong> take advantage of memory more than 2 GBby default. If your hardware c<strong>on</strong>tains additi<strong>on</strong>al memory, this issue can be resolved bycorrectly c<strong>on</strong>figuring <strong>SQL</strong> <strong>Server</strong> <strong>to</strong> take advantage of the server's available memory.Microsoft offers two utilities, Read80Trace and OSTRESS, <strong>to</strong> assist in stress testing<strong>SQL</strong> <strong>Server</strong>. To learn more or download these utilities, refer <strong>to</strong>http://support.microsoft.com/?kbid=887057.For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> scalability, refer <strong>to</strong> the following resources:● Scaling out <strong>on</strong> <strong>SQL</strong> <strong>Server</strong>http://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/en-us/part10/c3861.mspx.● <strong>SQL</strong> <strong>Server</strong> Scalability FAQhttp://www.microsoft.com/sql/techinfo/administrati<strong>on</strong>/2000/scalabilityfaq.asp.● Microsoft <strong>SQL</strong> <strong>Server</strong> 2000 Scalability Project — <strong>Server</strong> C<strong>on</strong>solidati<strong>on</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/dnsql2k/html/sql_asphosting.asp.● Windows 2003 Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and Scalabilityhttp://www.microsoft.com/windowsserver2003/evaluati<strong>on</strong>/per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance/perfscaling.mspx.Scalability TestingScalability testing is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> determine if the soluti<strong>on</strong> scales <strong>to</strong> handle an increasingworkload. The workload may be increased size, as in Very Large Databases (VLDB), ormore activity, such as transacti<strong>on</strong>s. Activity scalability is measured in number of userc<strong>on</strong>necti<strong>on</strong>s, requests, reports, <str<strong>on</strong>g>for</str<strong>on</strong>g> example. The overall scalability is also dependent <strong>on</strong>the hardware and the applicati<strong>on</strong>. The applicati<strong>on</strong>'s throughput change as the load isincreased is a measure of its scalability. Also, the throughput may be measured withincreased resources al<strong>on</strong>g with the increased load.Scalability testing, while similar <strong>to</strong> stress testing, provides additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>to</strong> assistin future soluti<strong>on</strong> expansi<strong>on</strong> plans. Scalability testing is c<strong>on</strong>ducted <strong>to</strong> record how well themigrated soluti<strong>on</strong> will scale or increase throughput as the user workload increases. Itdiffers from stress testing because scalability testing will generally load the soluti<strong>on</strong> farpast the minimum load levels defined in the Planning Phase.If additi<strong>on</strong>al hardware is available, it is worthwhile <strong>to</strong> determine whether exceeding thelimits of the current soluti<strong>on</strong> requires a simple additi<strong>on</strong> of hardware or a completeredesign of the system.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 305Resolving Scalability IssuesIssues of scaling should be documented as c<strong>on</strong>straints of the system. If it is imperativethat the entire system scale <strong>to</strong> a certain point based <strong>on</strong> business goals, but the soluti<strong>on</strong>does not meet these goals, then the resources (mostly hardware) have <strong>to</strong> be reevaluatedby experts. In most cases, vendors can provide support and in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in thisarea.Operati<strong>on</strong>al TestingOperati<strong>on</strong>al testing is required <strong>to</strong> ensure that day-<strong>to</strong>-day functi<strong>on</strong>ality and maintainabilityis developed and tested. This type of testing includes items such as:● Backup routines● Database maintenance tasks and schedules● Documentati<strong>on</strong> and processes developed <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>on</strong>going support● Alert and m<strong>on</strong>i<strong>to</strong>ring processes● Disaster recovery plansIf the soluti<strong>on</strong> is not going <strong>to</strong> be piloted, operati<strong>on</strong>al testing can be expanded <strong>to</strong> ensurethat the operati<strong>on</strong>s team is com<str<strong>on</strong>g>for</str<strong>on</strong>g>table with the processes and procedures needed <strong>to</strong>maintain the system.Resolving Operati<strong>on</strong>al IssuesIssues during operati<strong>on</strong>al testing are normally because of incomplete documentati<strong>on</strong> ofthe system requirements and c<strong>on</strong>figurati<strong>on</strong> with respect <strong>to</strong> comp<strong>on</strong>ents that are found<strong>on</strong>ly in the producti<strong>on</strong> envir<strong>on</strong>ment. In most cases, the issues will have <strong>to</strong> be handled bythe operati<strong>on</strong>s staff who may seek in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> and expertise from the project team.Bug Tracking and ReportingThere are several important interim milest<strong>on</strong>es in the iterative process of testing andrefining the soluti<strong>on</strong> be<str<strong>on</strong>g>for</str<strong>on</strong>g>e release. The interim milest<strong>on</strong>es guide the tracking and testingprocess. These milest<strong>on</strong>es include:● Bug c<strong>on</strong>vergence● Zero bug bounce● Release candidates● Golden releaseThese milest<strong>on</strong>es are discussed under the following headings.Bug C<strong>on</strong>vergenceBug c<strong>on</strong>vergence is the point at which the team makes visible progress against the activebug count. It is the point at which the rate of bugs that are resolved exceeds the rate ofbugs that are found.Figure 18.1 illustrates bug c<strong>on</strong>vergence.


306 Stabilizing PhaseFigure 18.1Bug c<strong>on</strong>vergence graphBecause the bug rate will still vary — even after it starts its overall decline — bugc<strong>on</strong>vergence usually manifests itself as a trend instead of a fixed point in time. After bugc<strong>on</strong>vergence, the number of bugs should c<strong>on</strong>tinue <strong>to</strong> decrease until the zero bug bounce.Zero Bug BounceZero bug bounce (ZBB) is the point in the project when development resolves all thebugs raised by the Test role and there are no active bugs — <str<strong>on</strong>g>for</str<strong>on</strong>g> the moment. Figure 18. 2illustrates ZBB.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 307Figure 18.2Zero bug bounceAfter ZBB, the bug peaks should become noticeably smaller and should c<strong>on</strong>tinue <strong>to</strong>decrease until the product is stable enough <strong>to</strong> release.Careful bug prioritizati<strong>on</strong> is vital because every bug that is fixed creates the risk ofcreating a new bug or regressi<strong>on</strong> issue. Achieving ZBB is a clear sign that the team is inthe final stage as it progresses <strong>to</strong>ward a stable product.Note New bugs will certainly be found after this milest<strong>on</strong>e is reached. But it does markthe first time that the team can h<strong>on</strong>estly report that there are no active bugs — even if itis <strong>on</strong>ly temporary. This can help the team maintain focus <strong>on</strong> a zero-defect mindset.Release CandidatesAfter the first achievement of zero bug bounce, a series of release candidates areprepared <str<strong>on</strong>g>for</str<strong>on</strong>g> release <strong>to</strong> the pilot group. Each of these releases is marked as an interimmilest<strong>on</strong>e. The release candidates are made available <strong>to</strong> the pilot group so they can testit. The users provide feedback <strong>to</strong> the project team, and the project team in turn c<strong>on</strong>tinues<strong>to</strong> improve the product and resolve bugs that appear during the pilot. As each newrelease candidate is built, there should be fewer bugs <strong>to</strong> report, prioritize, and resolve.The pilot group is discussed in m ore detail in the "Piloting the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>" secti<strong>on</strong> later inthis chapterGolden ReleaseGolden release is the release of the product <strong>to</strong> producti<strong>on</strong>. Golden release is a milest<strong>on</strong>ein the Stabilizing Phase that is identified by the combinati<strong>on</strong> of zero-defect and successcriteria metrics. At golden release, the team must select the release candidate that theywill release <strong>to</strong> producti<strong>on</strong>. The team uses the testing data that is measured against thezero-defect and success criteria metrics <strong>to</strong> make this selecti<strong>on</strong>.


308 Stabilizing PhaseUser Acceptance Testing and SignoffUser acceptance testing (UAT) is an additi<strong>on</strong>al testing process <strong>to</strong> determine if thesoluti<strong>on</strong> meets the cus<strong>to</strong>mer acceptance criteria. Because this is a migrati<strong>on</strong> project, thedatabase and the existing soluti<strong>on</strong> have already passed these criteria. In most cases,<strong>on</strong>ly the soluti<strong>on</strong>'s operating envir<strong>on</strong>ment has changed.In migrati<strong>on</strong> projects, UAT should test whether the new soluti<strong>on</strong> produces the sameresults from use cases as the existing soluti<strong>on</strong>. Whenever possible, use acceptance testsfrom the existing soluti<strong>on</strong> as a base.UAT can also affect the database. Part of testing should ensure that the <strong>SQL</strong> <strong>Server</strong>database can be accessed by the client applicati<strong>on</strong>s.User signoff is obtained when the users agree that the soluti<strong>on</strong> meets the needs of theend user. The user signoff is proof that the soluti<strong>on</strong> meets the user acceptance criteria inrelati<strong>on</strong> <strong>to</strong> their business requirements. The user signoff indicates that the soluti<strong>on</strong>c<strong>on</strong><str<strong>on</strong>g>for</str<strong>on</strong>g>ms <strong>to</strong> the requirements of the end-user (functi<strong>on</strong>ality) and the enterprise(per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance), and that the soluti<strong>on</strong> is ready <strong>to</strong> be deployed in<strong>to</strong> producti<strong>on</strong>.Piloting the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>A pilot program is a test of the soluti<strong>on</strong> in the producti<strong>on</strong> envir<strong>on</strong>ment, and a trial of thesoluti<strong>on</strong> by installers, systems support staff, and end users. The primary purposes of apilot are <strong>to</strong> dem<strong>on</strong>strate that the design works in the producti<strong>on</strong> envir<strong>on</strong>ment as expectedand that it meets the organizati<strong>on</strong>'s business requirements. Pilot deployments are oftencharacterized by a reduced but key feature set of the system or a smaller end-usergroup.The pilot is the last major step be<str<strong>on</strong>g>for</str<strong>on</strong>g>e a full-scale deployment. Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the pilot, all testingmust be completed. This provides the opportunity <strong>to</strong> integrate and test other pieces of theproducti<strong>on</strong> envir<strong>on</strong>ment that do not have any equivalent in the test envir<strong>on</strong>ment.The pilot also provides an opportunity <str<strong>on</strong>g>for</str<strong>on</strong>g> users <strong>to</strong> provide feedback about how thesoluti<strong>on</strong> works. This feedback must be used <strong>to</strong> resolve any issues or <strong>to</strong> create ac<strong>on</strong>tingency plan. The feedback can help the team determine the level of support thatthey are likely <strong>to</strong> need after full deployment. Some of the feedback can also c<strong>on</strong>tribute <strong>to</strong>the next versi<strong>on</strong> of the applicati<strong>on</strong>.Note The success of the pilot c<strong>on</strong>tributes heavily <strong>to</strong> the deployment schedule. Issuesdiscovered during the pilot can delay deployment until the problems are resolved.Every migrati<strong>on</strong> situati<strong>on</strong> is unique, and some scenarios may not require a pilot program.The pilot helps minimize the risks involved with the Deployment Phase. For instance, ifthe migrati<strong>on</strong> involves a Perl applicati<strong>on</strong> that is ported <strong>to</strong> run natively <strong>on</strong> the Windowsplat<str<strong>on</strong>g>for</str<strong>on</strong>g>m, the differences within the applicati<strong>on</strong> could be minimal and, depending <strong>on</strong> othermitigating fac<strong>to</strong>rs, a decisi<strong>on</strong> may be made not <strong>to</strong> pilot the soluti<strong>on</strong>.A pilot program is highly recommended in situati<strong>on</strong>s where any of the following instancesapply:● The deployment plan is highly complex and the deployment team requires theexperience of the pilot deployment.● The soluti<strong>on</strong> is prominent or critical <strong>to</strong> the organizati<strong>on</strong>. If the rollout must goexactly as planned, a pilot will provide additi<strong>on</strong>al assurance.● There is a large difference between the producti<strong>on</strong> and test envir<strong>on</strong>ments.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 309●There are elements in the producti<strong>on</strong> envir<strong>on</strong>ment that cannot be adequatelyverified in the test envir<strong>on</strong>ment.Preparing <str<strong>on</strong>g>for</str<strong>on</strong>g> the PilotA pilot deployment needs <strong>to</strong> be rehearsed <strong>to</strong> minimize the risk of disrupti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the pilotgroup. At this stage, the development team is per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming last-minute checks andensuring that nothing has changed since pre-producti<strong>on</strong> testing. The following tasks need<strong>to</strong> be completed be<str<strong>on</strong>g>for</str<strong>on</strong>g>e starting the pilot:● The development team and the pilot participants must clearly agree <strong>on</strong> the successcriteria <str<strong>on</strong>g>for</str<strong>on</strong>g> the pilot. In a migrati<strong>on</strong> project, the main success criteri<strong>on</strong> is that thenew soluti<strong>on</strong> effectively replaces the existing soluti<strong>on</strong>.● A support structure and issue resoluti<strong>on</strong> process must be in place. This processmay require that the support staff be trained. The procedures used <str<strong>on</strong>g>for</str<strong>on</strong>g> resoluti<strong>on</strong>during a pilot can vary significantly from those used during the deployment andwhen in full producti<strong>on</strong>.● To identify any issues and c<strong>on</strong>firm that the deployment process will work, it isnecessary <strong>to</strong> implement a trial run or a rehearsal of all the elements of thedeployment.● It is necessary <strong>to</strong> obtain cus<strong>to</strong>mer approval of the pilot plan. Work <strong>on</strong> the pilot planstarts early during the Planning Phase so that the communicati<strong>on</strong> channels are inplace and the participants are prepared by the time the test team is ready <strong>to</strong> deploythe pilot.● Ensure that the plan effectively mirrors the deployment process. For instance, if themigrati<strong>on</strong> soluti<strong>on</strong> is scheduled <strong>to</strong> be deployed in phases, the entire processshould be replicated <str<strong>on</strong>g>for</str<strong>on</strong>g> the pilot.Note It is important <strong>to</strong> remember that a pilot program tests and validates thedeployment process as well as the soluti<strong>on</strong>.A pilot plan should include the following:● Scope and objectives● Participating users, locati<strong>on</strong>s, and c<strong>on</strong>tact in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>● Training plan <str<strong>on</strong>g>for</str<strong>on</strong>g> pilot users● Support plan <str<strong>on</strong>g>for</str<strong>on</strong>g> the pilot● Known risks and c<strong>on</strong>tingency plans● Rollback plan● Schedule <str<strong>on</strong>g>for</str<strong>on</strong>g> deploying and c<strong>on</strong>ducting the pilotC<strong>on</strong>ducting the PilotC<strong>on</strong>ducting the pilot involves deploying the applicati<strong>on</strong>s and databases that have beenchosen <strong>to</strong> be part of the pilot. The golden release of the soluti<strong>on</strong> is used <str<strong>on</strong>g>for</str<strong>on</strong>g> pilot testingagainst an audience c<strong>on</strong>sisting of actual users using real-world scenarios. When the pilotis c<strong>on</strong>ducted in a producti<strong>on</strong> envir<strong>on</strong>ment, care has <strong>to</strong> be taken <strong>to</strong> ensure that the existingapplicati<strong>on</strong> and databases are not jeopardized. Hence, adequate support has <strong>to</strong> beprovided while c<strong>on</strong>ducting the pilot <strong>to</strong> m<strong>on</strong>i<strong>to</strong>r and fix any issues that arise.C<strong>on</strong>ducting a pilot also includes testing the accuracy of supporting documentati<strong>on</strong>,training and other n<strong>on</strong>-code elements, such as cu<strong>to</strong>ver and fallback procedures. Any


310 Stabilizing Phasechanges made <strong>to</strong> these documents during the pilot have <strong>to</strong> be noted and thedocumentati<strong>on</strong> updated accordingly.Note Ultimately, the pilot leads <strong>to</strong> a decisi<strong>on</strong> <strong>to</strong> either proceed with a full deploymen<strong>to</strong>r <strong>to</strong> delay deployment so that issues can be resolved.Evaluating the PilotAt the end of the pilot, its success is evaluated <strong>to</strong> determine whether deployment shouldbegin. The project team then needs <strong>to</strong> decide whether <strong>to</strong> c<strong>on</strong>tinue the project bey<strong>on</strong>d thepilot.It is important <strong>to</strong> obtain in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about both the design process and the deploymentprocess. Review what worked and what did not work so that it is possible <strong>to</strong> revise andrefine the plan be<str<strong>on</strong>g>for</str<strong>on</strong>g>e deployment. Examples of in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>to</strong> be gathered include:● Training required <str<strong>on</strong>g>for</str<strong>on</strong>g> using the soluti<strong>on</strong>● Rollout process● Support required <str<strong>on</strong>g>for</str<strong>on</strong>g> the soluti<strong>on</strong>● Communicati<strong>on</strong>s● Problems encountered● Suggesti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> improvementsThe feedback is used <strong>to</strong> validate that the delivered design meets the design specificati<strong>on</strong>,and the business requirements. After the data is evaluated, the team must make adecisi<strong>on</strong>. The team can select <strong>on</strong>e of following strategies:● Stagger <str<strong>on</strong>g>for</str<strong>on</strong>g>ward. Prepare another release candidate and release it <strong>to</strong> the originalpilot group, then <strong>to</strong> additi<strong>on</strong>al groups. The release <strong>to</strong> more than <strong>on</strong>e group mighthave been part of the original plan or might have been a c<strong>on</strong>tingency triggered byan unacceptable first pilot.● Roll back. Return the pilot group <strong>to</strong> their pre-pilot state.● Suspend the pilot. Put the soluti<strong>on</strong> <strong>on</strong> hold or cancel it.● Patch and c<strong>on</strong>tinue. Fix the build that the pilot is running and c<strong>on</strong>tinue.● Proceed <strong>to</strong> the Deploying Phase. Move <str<strong>on</strong>g>for</str<strong>on</strong>g>ward <strong>to</strong> deploy the pilot build <strong>to</strong> the fulllive producti<strong>on</strong> envir<strong>on</strong>ment.Finalizing the ReleaseThe Stabilizing Phase culminates in the Release Readiness Approved Milest<strong>on</strong>e. Thismilest<strong>on</strong>e occurs when the team has addressed all outstanding issues and has releasedthe soluti<strong>on</strong> and made it available <str<strong>on</strong>g>for</str<strong>on</strong>g> full deployment. This milest<strong>on</strong>e is the opportunity<str<strong>on</strong>g>for</str<strong>on</strong>g> cus<strong>to</strong>mers and users, operati<strong>on</strong>s and support pers<strong>on</strong>nel, and key project stakeholders<strong>to</strong> evaluate the soluti<strong>on</strong> and identify any remaining issues they need <strong>to</strong> address be<str<strong>on</strong>g>for</str<strong>on</strong>g>ebeginning the transiti<strong>on</strong> <strong>to</strong> deployment and, ultimately, release.After all of the stabilizati<strong>on</strong> tasks are complete, the team must <str<strong>on</strong>g>for</str<strong>on</strong>g>mally agree that theproject has reached the milest<strong>on</strong>e of release readiness. As the team progresses from therelease milest<strong>on</strong>e <strong>to</strong> the next phase of deploying, resp<strong>on</strong>sibility <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>on</strong>-going managementand support of the soluti<strong>on</strong> officially transfers from the project team <strong>to</strong> the operati<strong>on</strong>s andsupport teams. By agreeing, team members signify that they are satisfied with the workthat is per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in their areas of resp<strong>on</strong>sibility.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 311Project teams usually mark the completi<strong>on</strong> of a milest<strong>on</strong>e with a <str<strong>on</strong>g>for</str<strong>on</strong>g>mal sign-off. Keystakeholders, typically representatives of each team role and any important cus<strong>to</strong>merrepresentatives who are not <strong>on</strong> the project team, signal their approval of the milest<strong>on</strong>e bysigning or initialing a document stating that the milest<strong>on</strong>e is complete. The sign-offdocument becomesa project deliverable and is archived <str<strong>on</strong>g>for</str<strong>on</strong>g> future reference.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 31319Deploying PhaseIntroducti<strong>on</strong> and GoalsAfter envisi<strong>on</strong>ing, planning, developing, and stabilizing, the soluti<strong>on</strong> is ready <strong>to</strong> bedeployed. The Deploying Phase implements the tested soluti<strong>on</strong> in the producti<strong>on</strong>env ir<strong>on</strong>ment. The migrati<strong>on</strong> project Release Management team deploying the soluti<strong>on</strong>works with the operati<strong>on</strong>s team <strong>to</strong> successfully deploy and stabilize the soluti<strong>on</strong>. At theclose of the Deploying Phase, cus<strong>to</strong>mer approval <str<strong>on</strong>g>for</str<strong>on</strong>g> the migrati<strong>on</strong> is obtained, and thesoluti<strong>on</strong> is transferred <strong>to</strong> the operati<strong>on</strong>s team. It is also possible that the operati<strong>on</strong>s teamhandles the deployment with the aid of the project team. Irrespective of which team doesthe deployment, the key goal of the Deploying Phase is <strong>to</strong> successfully migrate the newsolu ti<strong>on</strong> in<strong>to</strong> the producti<strong>on</strong> envir<strong>on</strong>ment as smoothly as possible, and with the leastamount of disrupti<strong>on</strong> <strong>to</strong> the business envir<strong>on</strong>ment or the end users.The deployment rollout should be c<strong>on</strong>ducted as a series of activities. Though you canabbreviate or combine some of these activities, you cannot skip any of them completelywith out increasing risk <strong>to</strong> the project's success.Nearly all of these activities are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med in c<strong>on</strong>juncti<strong>on</strong> between the project team andthe operati<strong>on</strong>s team. Coordinati<strong>on</strong> between the two teams is now a critical successfact or. All decisi<strong>on</strong>s should be agreed up<strong>on</strong> by both of the teams <strong>to</strong> minimize risk. Bothteam s are involved with completing the tasks and producing the deliverables shown inTable 19.1.Table 19.1: Major Tasks and Deliverables <str<strong>on</strong>g>for</str<strong>on</strong>g> the Deploying PhaseTasks Deliverables Resp<strong>on</strong>sible RolesDeploy the soluti<strong>on</strong> Deployment Checklist Release ManagementStabilize the deployment Deployment Checklist Release ManagementObtain the soluti<strong>on</strong> signoff Cus<strong>to</strong>mer Sign Off Product ManagementTransfer ownership Project Documents Program ManagementDeploying the <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>At the close of the Stabilizing Phase, the database and applicati<strong>on</strong>s (server side andclient side) are fully tested and are ready <str<strong>on</strong>g>for</str<strong>on</strong>g> deployment. The release versi<strong>on</strong>s of thesource code, executables, scripts, and other installati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> are complete anddelivered <strong>to</strong> the deployment team.


314 Deploying PhaseWhile deployment is often discussed and planned singularly, there are actually threeseparate comp<strong>on</strong>ents and technologies that must be deployed in<strong>to</strong> the producti<strong>on</strong>envir<strong>on</strong>ment. These soluti<strong>on</strong> comp<strong>on</strong>ents are:● Database server● <strong>Server</strong> side applicati<strong>on</strong>(s)● Client side applicati<strong>on</strong>(s)Each of these comp<strong>on</strong>ents is discussed in this secti<strong>on</strong>. Each of these <strong>to</strong>pics is dividedin<strong>to</strong> two sub<strong>to</strong>pics: process and technology. The process sub<strong>to</strong>pics provide an overviewof the intricacies involved with the deployment of each of the soluti<strong>on</strong> comp<strong>on</strong>ents. Thetechnology sub<strong>to</strong>pics include in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> software <strong>to</strong>ols that can assist with thedeployments of the soluti<strong>on</strong> comp<strong>on</strong>ents.Deploying the Database <strong>Server</strong>The database should be deployed first because the server side and client sideapplicati<strong>on</strong>s are dependent <strong>on</strong> it. The process and technology required <str<strong>on</strong>g>for</str<strong>on</strong>g> setting updatabase server and implementing databases are discussed under the followingheadings.ProcessDuring the Planning Phase of the migrati<strong>on</strong>, all hardware needs are evaluated and anyrequired new equipment is acquired. During the Deploying Phase, the server must be setup and c<strong>on</strong>figured <str<strong>on</strong>g>for</str<strong>on</strong>g> the Windows <strong>Server</strong> 2003 envir<strong>on</strong>ment. The following proceduredescribes the steps <str<strong>on</strong>g>for</str<strong>on</strong>g> deploying the database and its server:1. The server should be built and delivered by your hardware vendor based <strong>on</strong>specificati<strong>on</strong>s defined during the Planning Phase. If the server will be built fromexisting equipment, ensure that the server is available and has the requiredcapacity <strong>to</strong> host the soluti<strong>on</strong>.2. Install any necessary hardware. Comm<strong>on</strong>ly, items such as additi<strong>on</strong>al memory,interface cards, additi<strong>on</strong>al s<strong>to</strong>rage, tape drives, or FDDA gigabit switches will need<strong>to</strong> be installed <strong>to</strong> meet operati<strong>on</strong>al specificati<strong>on</strong>s.3. Install the operating system, including any necessary service packs and patches.This step can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med manually or by using imaging software. This <strong>to</strong>pic isdiscussed in greater detail in the technology porti<strong>on</strong> of this secti<strong>on</strong>.4. C<strong>on</strong>figure any additi<strong>on</strong>al hardware that was installed. For instance, if NIC cards areinstalled, they must be c<strong>on</strong>figured <strong>to</strong> match the settings of the network switch theywill c<strong>on</strong>nect <strong>to</strong>.5. Install any additi<strong>on</strong>al applicati<strong>on</strong>s needed <str<strong>on</strong>g>for</str<strong>on</strong>g> the server, such as m<strong>on</strong>i<strong>to</strong>ringapplicati<strong>on</strong>s, backup software, asset management software, and software deliveryapplicati<strong>on</strong>s.6. Select the deployment mechanism <str<strong>on</strong>g>for</str<strong>on</strong>g> the database. Some possible opti<strong>on</strong>sinclude:● Use au<strong>to</strong>mated processes, such as installati<strong>on</strong> and c<strong>on</strong>figurati<strong>on</strong> scripts,where possible.● Use manual processes <str<strong>on</strong>g>for</str<strong>on</strong>g> some installati<strong>on</strong> and c<strong>on</strong>figurati<strong>on</strong>. These musthave detailed, step-by-step instructi<strong>on</strong>s.7. Create the database deployment package by putting <strong>to</strong>gether the following:● Microsoft® <strong>SQL</strong> <strong>Server</strong> installati<strong>on</strong> and c<strong>on</strong>figurati<strong>on</strong> scripts.● Databaseadministrati<strong>on</strong> <strong>to</strong>ols and utilities.a


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 315●●●●●●Database administrati<strong>on</strong> scripts and a scripting language such as Perl.User database migrati<strong>on</strong> scripts.Database administrati<strong>on</strong> tasks and packages, such as a maintenance plan,jobs, and backup and res<strong>to</strong>re procedures.Windows® domain user accounts c<strong>on</strong>figurati<strong>on</strong> scripts.Scripts <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>figuring ODBC data sources, ADO, and OLE DB c<strong>on</strong>necti<strong>on</strong>strings.Scripts <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>figuring COM+ comp<strong>on</strong>ents <str<strong>on</strong>g>for</str<strong>on</strong>g> database c<strong>on</strong>necti<strong>on</strong>.8. Create rollback scripts <strong>to</strong> undo or remove changes introduced by the deployment.If a parallel cu<strong>to</strong>ver strategy is being employed, the scripts should disable thereplicati<strong>on</strong>. Not every aspect of the fallback can be scripted. A checklist of taskswith detailed instructi<strong>on</strong>s should be prepared.9. Add the deployment package <strong>to</strong> the c<strong>on</strong>figurati<strong>on</strong> management database (CMDB).Maintain change c<strong>on</strong>trol of the release. Where a CMDB does not exist, a simplified<strong>on</strong>e should be created <str<strong>on</strong>g>for</str<strong>on</strong>g> release-tracking. The purpose of updating the CMDB is<strong>to</strong> ensure that accurate knowledge is s<strong>to</strong>red regarding all of the comp<strong>on</strong>ents orc<strong>on</strong>figurati<strong>on</strong> items that make up the releases.10. Execute deployment package <str<strong>on</strong>g>for</str<strong>on</strong>g> the databases being migrated as per the phase-12. If a straight cu<strong>to</strong>ver strategy is used, shut down the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases. If a parallelout strategy.11. Execute the scripts <strong>to</strong> create the database and its objects. The serial cu<strong>to</strong>verstrategy will dictate the order in which the databases are migrated.cu<strong>to</strong>ver is used, the databases may not be shut down. However, a quiet period isrequired <strong>to</strong> enable the replicati<strong>on</strong> and ensure that the replicati<strong>on</strong> mechanism isworking properly. Start migrating the data.13. M<strong>on</strong>i<strong>to</strong>r the data migrati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> errors. If the migrati<strong>on</strong> has <strong>to</strong> be aborted, therollback scripts and other fallback steps should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <str<strong>on</strong>g>for</str<strong>on</strong>g> each of thedatabases affected by the failure (if the databases are related and have <strong>to</strong> bemigrated <strong>to</strong>gether).Note If you must deviate from these scripts in the producti<strong>on</strong> envir<strong>on</strong>ment, makesure <strong>to</strong> alter the scripts <strong>to</strong> reflect the change and enter a note in the script ordocumentati<strong>on</strong> regarding what was altered, why, and whether you noticed anyissues afterward.TechnologySetting up and c<strong>on</strong>figuring servers can be time-c<strong>on</strong>suming, especially if additi<strong>on</strong>alapplicati<strong>on</strong>s are needed <str<strong>on</strong>g>for</str<strong>on</strong>g> operati<strong>on</strong>s, m<strong>on</strong>i<strong>to</strong>ring, reporting, or other purposes. Based<strong>on</strong> the needs of the deployment, there are two ways <strong>to</strong> deploy the server: manualdeployment and au<strong>to</strong>mated deployment using imaging <strong>to</strong>ols. Imaging <strong>to</strong>ols allow <str<strong>on</strong>g>for</str<strong>on</strong>g>applicati<strong>on</strong>s, operating systems, c<strong>on</strong>figurati<strong>on</strong>s, or drivers <strong>to</strong> be installed in <strong>on</strong>e package,instead of as individual installati<strong>on</strong>s. However, imaging can <strong>on</strong>ly be useful when settingup identical servers usingidentical hardware, as in a clustered set.Manual DeploymentIf a manual deployment is a c<strong>on</strong>siderati<strong>on</strong>, a few guidelines should be noted. Often,hardware vendors will provide cus<strong>to</strong>mized installati<strong>on</strong> CDs that c<strong>on</strong>tain specific driversand software needed <str<strong>on</strong>g>for</str<strong>on</strong>g> the c<strong>on</strong>figurati<strong>on</strong>. Using these installati<strong>on</strong> discs can reduce thetime needed <str<strong>on</strong>g>for</str<strong>on</strong>g> installati<strong>on</strong>.


316 Deploying PhaseFor the detailed manual installati<strong>on</strong> procedure and c<strong>on</strong>figurati<strong>on</strong> ofWindows® 2000 Professi<strong>on</strong>al, Windows® XP, Windows <strong>Server</strong> 2000 Advanced<strong>Server</strong>, and Windows 2003 <strong>Server</strong> Enterprise Editi<strong>on</strong>, refer <strong>to</strong> the help documentati<strong>on</strong>provided with the Windows operating system CD.Note Manual installati<strong>on</strong>s of the operating system can be partially au<strong>to</strong>mated using ananswer file. This file provides the input that the setup needs <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m the installati<strong>on</strong>and reduces the amount of user interacti<strong>on</strong> needed during the installati<strong>on</strong> process. Fordetails about creating an answer file and the opti<strong>on</strong>s available in an answer file, refer <strong>to</strong>http://www.microsoft.com/resources/documentati<strong>on</strong>/windows/2000/server/reskit/enus/deploy/dghn_ans_wten.asp.Another <strong>to</strong>ol that can be utilized <strong>to</strong> assist in manual deployments is Microsoft RemoteInstallati<strong>on</strong> Services (RIS). RIS enables you <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m system installati<strong>on</strong>s across anetwork using an Active Direc<strong>to</strong>ry service. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> RIS, refer <strong>to</strong>http://www.microsoft.com/windows2000/techinfo/planning/management/remote steps.asp.The RDBMS should be installed manually using the Microsoft <strong>SQL</strong> <strong>Server</strong> SoftwareDistributi<strong>on</strong> CD or a network installati<strong>on</strong> <strong>to</strong>ol such as RIS. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> theinstallati<strong>on</strong> process <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> 2000, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/instsql/in_overview_0v3l.asp.Creati<strong>on</strong> of the databases and database objects can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med using Data Definiti<strong>on</strong>Language (DDL) scripts that have been generated from the test envir<strong>on</strong>ment. Thisin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> can also be recreated manually using the Enterprise Manager GUI, but inmost instances the large number of objects that need <strong>to</strong> be created would make thisef<str<strong>on</strong>g>for</str<strong>on</strong>g>t <strong>to</strong>o time-c<strong>on</strong>suming.To create a database using the CREATE DATABASE command, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/tsqlref/ts_create_1up1.asp.To create a database using the Create Database Wizard in Enterprise Manager, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/how<strong>to</strong>sql/ht_7_design_4g8p.asp.DDL scripts can be run using Query Analyzer, a utility installed as part of <strong>SQL</strong> <strong>Server</strong>.Third-party <strong>SQL</strong> <strong>Server</strong> <strong>to</strong>ols can also be used. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> Query Analyzer,refe r <strong>to</strong> Appendix B.Au<strong>to</strong>mated DeploymentImagin g is an alternate method of deploying the operating system and all applicati<strong>on</strong>sand c<strong>on</strong>figurati<strong>on</strong>s simultaneously. Imaging captures a snapshot of the entire system,including the operating system, applicati<strong>on</strong>s, desk<strong>to</strong>p settings, and user preferences.Imagin g <strong>to</strong>ols should be a serious c<strong>on</strong>siderati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> deployments that c<strong>on</strong>sist of multipleserv ers that require the same c<strong>on</strong>figurati<strong>on</strong>. Creating images can greatly reduce the timeneeded <strong>to</strong> prepare servers <str<strong>on</strong>g>for</str<strong>on</strong>g> deployment and also ensure c<strong>on</strong>sistent c<strong>on</strong>figurati<strong>on</strong>.To create an image, a master system must be manually c<strong>on</strong>figured with all necessarysoftware. After the server has been properly c<strong>on</strong>figured, the image is created usingimaging software. Finally, the image can be deployed <strong>to</strong> as many servers as required.Each will be a cl<strong>on</strong>e of the master system.The major benefits of using the imaging <strong>to</strong>ols include:● Deployments can be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med simultaneously. All systems can be running in ashort time.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 317●All applicati<strong>on</strong>s are bundled in<strong>to</strong> the image.The major drawback of imaging is that each type of hardware c<strong>on</strong>figurati<strong>on</strong> requires aseparate image. You can <strong>on</strong>ly install images <strong>on</strong> target computers that have a compatiblehardware abstracti<strong>on</strong> layer (HAL) <strong>to</strong> the reference computer. For instance, if a serverc<strong>on</strong>tains a different graphics card, it would require a separate image.There are many different <strong>to</strong>ols and utilities available that provide the capability <strong>to</strong> recordand deploy images. Here is a listing of some of these <strong>to</strong>ols:● Symantec Ghost (also called Nort<strong>on</strong> Ghost) captures a complete system image <str<strong>on</strong>g>for</str<strong>on</strong>g>redistributi<strong>on</strong>. For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> using Symantec Ghost, refer <strong>to</strong>http://service1.symantec.com/SUPPORT/ghost.nsf/pfdocs/.● Au<strong>to</strong>mated Deployment Services (ADS) is designed <strong>to</strong> deploy Microsoft Windows2000 <strong>Server</strong>, Advanced <strong>Server</strong> and Datacenter <strong>Server</strong>, andWindows <strong>Server</strong> 2003 (all 32-bit editi<strong>on</strong>s). Other operating systems are notcurrently supported. For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> how <strong>to</strong> use ADS, refer <strong>to</strong>http://www.microsoft.com/windowsserver2003/technologies/management/ads/default.mspx.Deploying the <strong>Server</strong> Side Applicati<strong>on</strong>sThe steps <str<strong>on</strong>g>for</str<strong>on</strong>g> building the servers described in the previous secti<strong>on</strong> can also be used <strong>to</strong>prepare the servers <str<strong>on</strong>g>for</str<strong>on</strong>g> the server-side applicati<strong>on</strong>s. Detailed guidance <str<strong>on</strong>g>for</str<strong>on</strong>g> setting up theserver-side applicati<strong>on</strong>s is discussed under the following headings.ProcessThough the server will be set up <strong>to</strong> meet the needs of your specific applicati<strong>on</strong>s,additi<strong>on</strong>al steps may be needed <strong>to</strong> prepare the hardware <str<strong>on</strong>g>for</str<strong>on</strong>g> deployment. To deploy server-side applicati<strong>on</strong>s, follow these steps:1. Install the operating system and third-party comp<strong>on</strong>ents <strong>on</strong> the server as requiredby the applicati<strong>on</strong>.2. C<strong>on</strong>figure the server-side applicati<strong>on</strong> comp<strong>on</strong>ents.3. Install the server-side comp<strong>on</strong>ents <strong>on</strong> the server.4. Add all c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in<strong>to</strong> the c<strong>on</strong>figurati<strong>on</strong> management database(CMDB) and maintain change c<strong>on</strong>trol of the release. If a CMDB does not exist, asimplified <strong>on</strong>e should be created <str<strong>on</strong>g>for</str<strong>on</strong>g> release-tracking. Updating the CMDB ensuresthat accurate knowledge is s<strong>to</strong>red regarding all of the comp<strong>on</strong>ents or c<strong>on</strong>figurati<strong>on</strong>items that make up the releases.5. Deploy the applicati<strong>on</strong>s in c<strong>on</strong>juncti<strong>on</strong> with the deployment strategy beingemployed <str<strong>on</strong>g>for</str<strong>on</strong>g> the databases.6. After the database migrati<strong>on</strong> has been c<strong>on</strong>firmed, per<str<strong>on</strong>g>for</str<strong>on</strong>g>m c<strong>on</strong>figurati<strong>on</strong> changes <strong>to</strong>the envir<strong>on</strong>ment <strong>to</strong> activate the applicati<strong>on</strong>.7. If a fallback is required, then the applicati<strong>on</strong> should be shut down and the originalc<strong>on</strong>figurati<strong>on</strong> that points all users back <strong>to</strong> the original applicati<strong>on</strong> should beres<strong>to</strong>red.


318 Deploying PhaseTechnologyThe server side applicati<strong>on</strong> comp<strong>on</strong>ents can be either deployed manually or by usingimaging as discussed in the "Au<strong>to</strong>mated Deployment" secti<strong>on</strong>.Manual DeploymentIf manual deployment is chosen, each of the comp<strong>on</strong>ents of the server-side applicati<strong>on</strong>should be individually installed. First, install the language envir<strong>on</strong>ments (such as Perl andPHP) and any third-party utilities using the vendor's software distributi<strong>on</strong>. Then install theserver-side applicati<strong>on</strong> using the golden versi<strong>on</strong> of the source code from the projectteam.Au<strong>to</strong>mated DeploymentThe deployment of the server-side applicati<strong>on</strong>s can be au<strong>to</strong>mated by bundling it in<strong>to</strong> theimage. The technology is the same as discussed <str<strong>on</strong>g>for</str<strong>on</strong>g> deploying the database.Deploying the Client Applicati<strong>on</strong>After the server-side applicati<strong>on</strong>s and databases have been deployed <strong>to</strong> producti<strong>on</strong> andtested, the client applicati<strong>on</strong> should be released. Often, this stage of the deployment canbe complex because of the number of users and comp<strong>on</strong>ents involved.This is usually the point in the deployment process where the end users are affected. Inmany cases, this is the first time that they are involved in the migrati<strong>on</strong> process. Whilethis guidance focuses <strong>on</strong> the applicati<strong>on</strong> and database aspects of the migrati<strong>on</strong>, keep inmind that there are many other items <strong>to</strong> c<strong>on</strong>sider. For instance, documentati<strong>on</strong>, training,and help desk support also need <strong>to</strong> be in place at the time of this deployment.It is quite likely that the client computers are already in use. If not, build the hardware <str<strong>on</strong>g>for</str<strong>on</strong>g>the client computers and deploy the required software.ProcessAs with the other stages of deployment, the client applicati<strong>on</strong> can be deployed manuallyor through the use of au<strong>to</strong>mated <strong>to</strong>ols. C<strong>on</strong>sider the following steps when deploying theclient applicati<strong>on</strong>.1. Create the deployment package, which can include the following:● The complete applicati<strong>on</strong>, including the binary installati<strong>on</strong> files and anyau<strong>to</strong>mati<strong>on</strong> files.● Client c<strong>on</strong>figurati<strong>on</strong> and support files.● Windows domain user accounts c<strong>on</strong>figurati<strong>on</strong> scripts.● Scripts <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>figuring ODBC data sources, ADO, or OLE DB c<strong>on</strong>necti<strong>on</strong>strings.● Scripts <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>figuring COM+ comp<strong>on</strong>ents <str<strong>on</strong>g>for</str<strong>on</strong>g> database c<strong>on</strong>necti<strong>on</strong>.● Acceptance test scripts and packages.2. Create rollback scripts <strong>to</strong> remove changes introduced by the deployment. Rollbackscripts provide an alternate opti<strong>on</strong> if an uncorrectable issue arises during theserver, database, or applicati<strong>on</strong> deployments.3. Add the deployment package <strong>to</strong> the c<strong>on</strong>figurati<strong>on</strong> management database (CMDB).Maintain change c<strong>on</strong>trol of the release. Where a CMDB does not exist, a simplified<strong>on</strong>e should becreated <str<strong>on</strong>g>for</str<strong>on</strong>g> release-tracking.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 3194. When the database and applicati<strong>on</strong> migrati<strong>on</strong> are completed successfully, deploythe client applicati<strong>on</strong>. In additi<strong>on</strong> <strong>to</strong> the database and applicati<strong>on</strong> deploymentstrategy, a horiz<strong>on</strong>tal phase-out strategy may be employed <str<strong>on</strong>g>for</str<strong>on</strong>g> client applicati<strong>on</strong>s.5. If a fallback is required, then the applicati<strong>on</strong> should be rolled back <strong>to</strong> the previous<strong>on</strong>e and the original c<strong>on</strong>figurati<strong>on</strong> that points all clients back <strong>to</strong> the originalapplicati<strong>on</strong> should be res<strong>to</strong>red. If the fallback is due <strong>to</strong> an applicati<strong>on</strong> issue, then ahoriz<strong>on</strong>tal phase-out strategy reduces the rollback ef<str<strong>on</strong>g>for</str<strong>on</strong>g>t.TechnologyWhen deploying the client applicati<strong>on</strong>, additi<strong>on</strong>al <strong>to</strong>ols may be required <strong>to</strong> efficientlymanage the deployment. Some comm<strong>on</strong> <strong>to</strong>ols used <str<strong>on</strong>g>for</str<strong>on</strong>g> packaging applicati<strong>on</strong>s andutilizing distributi<strong>on</strong> channels include:● MSI (or Windows Installer) is a Microsoft soluti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong> packages. Thisinstaller provides additi<strong>on</strong>al functi<strong>on</strong>ality and integrati<strong>on</strong> with the Windowsenvir<strong>on</strong>ment, including elevated privileges <str<strong>on</strong>g>for</str<strong>on</strong>g> installati<strong>on</strong> and deployment acrossan Active Direc<strong>to</strong>ry. To download Windows Installer or learn more about it, refer <strong>to</strong>http://www.microsoft.com/downloads/details.aspx?FamilyID=5fbc5470-b259-4733-a914-a956122e08e8&DisplayLang=en.● Visual Studio Installer creates setups based <strong>on</strong> the Microsoft Windows Installertechnology in the Visual Studio IDE. For detailed step-by-step instructi<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g>Visual Studio Installer, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsinstal/html/vehowvisualstudioinstallerquickstart.asp.● WinINSTALL LE creates packages by recording a snapshot of a systemsenvir<strong>on</strong>ment be<str<strong>on</strong>g>for</str<strong>on</strong>g>e and after an applicati<strong>on</strong> is installed, then records all of thechanges between snapshots <strong>to</strong> generate the installati<strong>on</strong> package. For morein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about WinINSTALL LE, refer <strong>to</strong>http://www.<strong>on</strong>demandsoftware.com/FREELE2003 /.● Wise Package Studio is a <strong>to</strong>ol used <str<strong>on</strong>g>for</str<strong>on</strong>g> packaging/repackaging applicati<strong>on</strong>s usingWise script or an MSI file. Scripts, checks, and c<strong>on</strong>diti<strong>on</strong>s can be embedded in<strong>to</strong>the package, which also helps in deploying or distributing the package. For morein<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> Wise Package Studio, refer <strong>to</strong>http://www.wise.com/wps.asp?bhcp=1.● InstallShield AdminStudio can also create a scripted package file or an MSIpackage. The repackaging methodology is same as that of Wise Package Studio.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about InstallShield, refer <strong>to</strong>http://www.installshield.com/downloads/isas/evalguide/AdminStudio5_Evalua<strong>to</strong>r_<str<strong>on</strong>g>Guide</str<strong>on</strong>g>.pdf.● IntelliMirror uses a Windows Installer server <strong>to</strong> provide distributi<strong>on</strong>s <strong>to</strong> clientcomputers. When an applicati<strong>on</strong> is launched, IntelliMirror checks <strong>to</strong> ensure that theapplicati<strong>on</strong> is loaded and up <strong>to</strong> date. If not, the needed files are downloaded andinstalled <strong>on</strong> the system. Because IntelliMirror checks <str<strong>on</strong>g>for</str<strong>on</strong>g> updated versi<strong>on</strong>ing everytime the applicati<strong>on</strong> is launched, this software can be used <strong>to</strong> manage all futurereleases of the client applicati<strong>on</strong>. For more details <strong>on</strong> IntelliMirror, refer <strong>to</strong>http://www.microsoft.com/resources/documentati<strong>on</strong>/WindowsServ/2003/standard/proddocs/enus/Default.asp?url=/resources/documentati<strong>on</strong>/windowsserv/2003/standard/proddocs/en-us/sag_imirror_<strong>to</strong>p_node.asp.● Windows Installer au<strong>to</strong>matically reads an MSI file and deploys the applicati<strong>on</strong>packaged as an MSI file. The MSI file can be cus<strong>to</strong>mized <str<strong>on</strong>g>for</str<strong>on</strong>g> the features,installati<strong>on</strong> locati<strong>on</strong>, and so <str<strong>on</strong>g>for</str<strong>on</strong>g>th. Windows Installer can also per<str<strong>on</strong>g>for</str<strong>on</strong>g>m a silent installof the MSI file when provided with that opti<strong>on</strong>. For an overview of Windows


320 Deploying Phase●●Installer, refer <strong>to</strong>http://www.microsoft.com/windows2000/en/advanced/help/default.asp?url=/windows2000/en/advanced/help/sag_WinInstall_Technology.htm?id=3991.Active Direc<strong>to</strong>ry is a core feature in the Windows server operating system whichnot <strong>on</strong>ly handles security and privileges of the domain, but also has the capability<strong>to</strong> distribute MSI files. Group Policy policy settings can be set in Active Direc<strong>to</strong>ry <strong>to</strong>distribute the required MSI file. Active Direc<strong>to</strong>ry can be used efficiently <strong>to</strong> distributethe files at off hours or weekends <strong>to</strong> avoid blocking network c<strong>on</strong>gesti<strong>on</strong>. For furtherin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about Active Direc<strong>to</strong>ry, refer <strong>to</strong>http://www.microsoft.com/windowsserver2003/technologies/direc<strong>to</strong>ry/activedirec<strong>to</strong>ry/default.mspx.Systems Management <strong>Server</strong> (SMS) is a <strong>to</strong>ol from Microsoft <str<strong>on</strong>g>for</str<strong>on</strong>g> distributingsoftware packages. SMS has various features, such as packaging, distributing,deploying applicati<strong>on</strong>s, and m<strong>on</strong>i<strong>to</strong>ring. For step-by-step procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> distributinga package using SMS, refer <strong>to</strong>http://www.microsoft.com/downloads/details.aspx?FamilyID=32f2bb4c-42f8-4b8d-844f-2553fd78049f&DisplayLang=enNote The <strong>to</strong>ols listed previously have not been tested in a lab envir<strong>on</strong>ment as part ofthis soluti<strong>on</strong>.Change ManagementChange management is the process <str<strong>on</strong>g>for</str<strong>on</strong>g> c<strong>on</strong>trolling changes <strong>to</strong> a protected envir<strong>on</strong>ment.In the Stabilizing Phase, changes are made <strong>to</strong> the test envir<strong>on</strong>ment related <strong>to</strong> bug fixesand promoting the builds. Changes made <strong>to</strong> the soluti<strong>on</strong> in the producti<strong>on</strong> envir<strong>on</strong>mentare handled more strictly because they can affect the end users of the applicati<strong>on</strong> as wellas other users of the producti<strong>on</strong> envir<strong>on</strong>ment. Any proposed changes must go throughthe change approval process <strong>to</strong> ensure that the changes will not adversely affect theproducti<strong>on</strong> envir<strong>on</strong>ment.For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> Change Management, refer <strong>to</strong>http://www.microsoft.com/technet/itsoluti<strong>on</strong>s/cits/mo/smf/smfchgmg.mspx.Stabilizing the DeploymentAfter the server-side applicati<strong>on</strong> comp<strong>on</strong>ents, database, and client-side applicati<strong>on</strong>comp<strong>on</strong>ents are deployed, every aspect of the deployment must be validated <strong>to</strong> ensurethat the migrati<strong>on</strong> has been per<str<strong>on</strong>g>for</str<strong>on</strong>g>med successfully. Comm<strong>on</strong> items <strong>to</strong> check areincluded in the deployment checklist discussed in the following secti<strong>on</strong>s.Deployment ChecklistThe product manager and the operati<strong>on</strong>s team should ensure that the soluti<strong>on</strong> meets thebusiness requirements and standards determined during the Envisi<strong>on</strong>ing Phase. Thechecklist developed during the Planning Phase should c<strong>on</strong>tain the acceptance criteriathat evaluate the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of the soluti<strong>on</strong>. It should also provide a baseline <str<strong>on</strong>g>for</str<strong>on</strong>g> thecus<strong>to</strong>mer <strong>to</strong> approve the soluti<strong>on</strong>. The following categories should be included in thechecklist <strong>to</strong> test the soluti<strong>on</strong> be<str<strong>on</strong>g>for</str<strong>on</strong>g>e signoff:● <strong>Server</strong>● Database● Applicati<strong>on</strong> (client and server side)


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 321●Additi<strong>on</strong>al c<strong>on</strong>siderati<strong>on</strong>sThese categories are discussed under the following headings.<strong>Server</strong>The following are some server-related items that should be c<strong>on</strong>sidered <str<strong>on</strong>g>for</str<strong>on</strong>g> the checklist:●●●●●●●●●●●●●●●●●●●Have all relevant service packs been loaded <strong>to</strong> the producti<strong>on</strong> servers? Are the OSand installed service pack level well known and documented? You will need thisin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> if the systems fail and manufacturer support is required.Have the settings from the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance tuning in the test envir<strong>on</strong>ment during theStabilizing Phase been transferred correctly? At the same time, ensure that anyc<strong>on</strong>figurati<strong>on</strong>s unique <strong>to</strong> the testing envir<strong>on</strong>ment have not been transferred <strong>to</strong> theproducti<strong>on</strong> envir<strong>on</strong>ment.Have backup power systems been fully tested <strong>to</strong> ensure proper operati<strong>on</strong>?Are an appropriate number of replacement hard disks <strong>on</strong> hand in case of failure inan array?Are the default client c<strong>on</strong>necti<strong>on</strong> network library settings established <strong>on</strong> the server?Are all database and applicati<strong>on</strong> server installati<strong>on</strong> settings documented (such assort orders and default language)?Has communicati<strong>on</strong> between servers been checked <strong>to</strong> assure that proper DNSresoluti<strong>on</strong> and routing is functi<strong>on</strong>ing as expected?Are alerts defined <str<strong>on</strong>g>for</str<strong>on</strong>g> key problems and c<strong>on</strong>diti<strong>on</strong>s? Who m<strong>on</strong>i<strong>to</strong>rs the e-mailaddress <strong>to</strong> which these are sent? Are pagers used? Has the alert system beentested?Has the team removed guest accounts from the system and checked <strong>to</strong> ensurethat this does not affect the applicati<strong>on</strong>?Is the appropriate level of direc<strong>to</strong>ry security set?Has security logging been implemented?Have all n<strong>on</strong>-essential services and open ports <strong>on</strong> the server been identified andclosed?Has the team tested producti<strong>on</strong> integrati<strong>on</strong> with third-party systems?Have any and all event log messages been identified and investigated?Does the OS have sufficient client access licenses <str<strong>on</strong>g>for</str<strong>on</strong>g> the expected peak trafficloads?Are sufficient client access licenses and c<strong>on</strong>necti<strong>on</strong>s installed <str<strong>on</strong>g>for</str<strong>on</strong>g> the OS? Is thisbeing m<strong>on</strong>i<strong>to</strong>red <strong>to</strong> assure that it does not reach its limit?Are system c<strong>on</strong>figurati<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> all tiers backed up? Were scripts created <strong>to</strong> resetc<strong>on</strong>figurati<strong>on</strong>s in an emergency or <strong>to</strong> bring up a new server? Are they in a wellknownlocati<strong>on</strong>?Have server backups been tested? Are procedures in place <str<strong>on</strong>g>for</str<strong>on</strong>g> proper s<strong>to</strong>rage andretrieval?Have clustering software c<strong>on</strong>figurati<strong>on</strong> and failover operati<strong>on</strong>s been tested?


322 Deploying PhaseDatabaseThe following are some database-related items that should be c<strong>on</strong>sidered <str<strong>on</strong>g>for</str<strong>on</strong>g> thechecklist:● Have all database creati<strong>on</strong> scripts been executed properly and without errors?● Were the database statistics updated be<str<strong>on</strong>g>for</str<strong>on</strong>g>e launch?● Have the database backups been tested <strong>to</strong> ensure that backup mechanisms areoperating properly? Have res<strong>to</strong>rati<strong>on</strong> procedures been tested <strong>on</strong> the soluti<strong>on</strong>server and <strong>on</strong> different hardware <strong>to</strong> test failover procedures? Are off-site backupprocedures in place?● Has database security been addressed and appropriate log<strong>on</strong> accounts created?Is the system administra<strong>to</strong>r's (SA) account password blank? Are applicati<strong>on</strong>s usingthe SA account or other account(s)?● Did the team define, test, schedule, and sign-off <strong>on</strong> maintenance plans?● Has a schedule been established <str<strong>on</strong>g>for</str<strong>on</strong>g> the transacti<strong>on</strong> log dumping that will besufficient <strong>to</strong> recover activity <strong>to</strong> the satisfacti<strong>on</strong> of the business? Has it been tested?● Are sufficient client access licenses installed <str<strong>on</strong>g>for</str<strong>on</strong>g> the database server? Are thesebeing m<strong>on</strong>i<strong>to</strong>red <strong>to</strong> assure that they do not reach their limit?● Has the latest build of the database from the development envir<strong>on</strong>ment beenmigrated, installed, tested, and verified within the producti<strong>on</strong> envir<strong>on</strong>ment?● The user databases should be checked <strong>to</strong> ensure that all the data from thedatabase is transferred from the source soluti<strong>on</strong> <strong>to</strong> the target soluti<strong>on</strong> duringdeployment.● Has the database been loaded in the producti<strong>on</strong> envir<strong>on</strong>ment with clean data, andhave initial inven<strong>to</strong>ry levels been set? Have feeds from other systems been verifiedunder load <strong>to</strong> ensure that system availability is unaffected at the time they run?● Is the database running <strong>on</strong> the default port of 1433? If so, can this be changed <strong>to</strong>another port or ports <strong>to</strong> enhance security of the applicati<strong>on</strong> without affecting properoperati<strong>on</strong>?● Are n<strong>on</strong>-essential <strong>SQL</strong> <strong>Server</strong> services running (MS Search, OLAP)? S<strong>to</strong>p them ifthey are not required.● Are n<strong>on</strong>-essential databases installed <strong>on</strong> the server? Remove databases such aspubs or Northwind, but be careful not <strong>to</strong> remove needed system databases suchas model, tempdb, or master.● Is the database correctly tuned, and does it have the proper memory usagesettings applied?● Is disk space sufficient <str<strong>on</strong>g>for</str<strong>on</strong>g> the expected size of the data 6-12 m<strong>on</strong>ths ahead?● Have clustering software c<strong>on</strong>figurati<strong>on</strong> and failover operati<strong>on</strong>s been tested with thedatabases?Applicati<strong>on</strong> (Client Side or <strong>Server</strong> Side)The following list offers some client-side or server-side applicati<strong>on</strong>-related items thatshould be c<strong>on</strong>sidered <str<strong>on</strong>g>for</str<strong>on</strong>g> the checklist:● Are the proper security settings <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong>s set and documented?● Has applicati<strong>on</strong> logging been enabled or disabled, as required?● Has the golden release of the applicati<strong>on</strong>s and other comp<strong>on</strong>ents been given arelease number, archived, then deployed? C<strong>on</strong>firm that the golden release of thesource code matches the versi<strong>on</strong> of the applicati<strong>on</strong> that was released.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 323●●●●●●●Are all required envir<strong>on</strong>mental settings <str<strong>on</strong>g>for</str<strong>on</strong>g> the applicati<strong>on</strong>s set and documented?Are all third-party software or comp<strong>on</strong>ents that are required by the system installedand documented (such as versi<strong>on</strong> numbers and vendor c<strong>on</strong>tact in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>)?Ensure that the client applicati<strong>on</strong> properly c<strong>on</strong>nects <strong>to</strong> the database. Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mcursory testing of the applicati<strong>on</strong> that is not intrusive and does not change theproducti<strong>on</strong> database. For example, running producti<strong>on</strong> reports is a good way <strong>to</strong>test database functi<strong>on</strong>ality without changing the live data.Has c<strong>on</strong>nectivity between the middle-tier system and any back-end systems beentested under load? Has c<strong>on</strong>necti<strong>on</strong> pooling been m<strong>on</strong>i<strong>to</strong>red <strong>to</strong> assure properoperati<strong>on</strong>?Are the activati<strong>on</strong> types <str<strong>on</strong>g>for</str<strong>on</strong>g> any COM+ applicati<strong>on</strong>s set properly? Has theapplicati<strong>on</strong> been tested with the c<strong>on</strong>soles logged <strong>on</strong> and logged off <strong>to</strong> assure theproper identity is used?Has the applicati<strong>on</strong> integrati<strong>on</strong> been tested with third-party systems?Have clustering software c<strong>on</strong>figurati<strong>on</strong> and failover operati<strong>on</strong>s been tested with theapplicati<strong>on</strong>s?Additi<strong>on</strong>al C<strong>on</strong>siderati<strong>on</strong>sHere are some additi<strong>on</strong>al c<strong>on</strong>siderati<strong>on</strong>s that could apply <strong>to</strong> your envir<strong>on</strong>ment. Some ofthe tasks per<str<strong>on</strong>g>for</str<strong>on</strong>g>med here are related <strong>to</strong> operati<strong>on</strong>s. Validating these tasks duringdeployment ensures operati<strong>on</strong>s is prepared <strong>to</strong> manage the soluti<strong>on</strong> and SLAs can bemet.● Are scheduler jobs defined <str<strong>on</strong>g>for</str<strong>on</strong>g> comm<strong>on</strong> tasks? Jobs such as backups and healthreporting are normally scheduled through a scheduler such as cr<strong>on</strong> in <strong>UNIX</strong>.These may have been migrated over.● Has a disaster recovery plan (DRP) been established that includes databaseprocedures?Who is the DRP team leader? Is the leader's c<strong>on</strong>tact in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> wellknown, and is a c<strong>on</strong>tingency leader appointed?● Has the team enabled change-c<strong>on</strong>trol procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> the operati<strong>on</strong>s envir<strong>on</strong>ment?● Has the team finalized the operati<strong>on</strong>al processes and guidelines?● Has the team developed, tested, and simulated disaster recovery procedures?● Was an external c<strong>on</strong>necti<strong>on</strong> used when testing the applicati<strong>on</strong> against theoperati<strong>on</strong>s system? The external c<strong>on</strong>necti<strong>on</strong> should be similar <strong>to</strong> what a cus<strong>to</strong>merwill use.● Was soluti<strong>on</strong> training delivered?● Is the processing speed acceptable?● Have the business objectives and requirements been met?● Have operati<strong>on</strong> tests been per<str<strong>on</strong>g>for</str<strong>on</strong>g>med? Steps should be taken <strong>to</strong> make sure thatthe operati<strong>on</strong>s team can properly track the servers and services with theirm<strong>on</strong>i<strong>to</strong>ring <strong>to</strong>ols.Quiet PeriodThe quiet period <str<strong>on</strong>g>for</str<strong>on</strong>g> the target envir<strong>on</strong>ment begins after stabilizing the deployed soluti<strong>on</strong>and c<strong>on</strong>tinues until the deployment is complete. It usually exists <str<strong>on</strong>g>for</str<strong>on</strong>g> a period of 15 <strong>to</strong> 30days. During this period, the operati<strong>on</strong>s team manages the deployed soluti<strong>on</strong>.No significant changes should be made <strong>to</strong> the soluti<strong>on</strong>. However, a member from theproject team may aid the operati<strong>on</strong>s team <strong>to</strong> manage and resolve problems that canaffect the working of the deployed soluti<strong>on</strong>. This enables the organizati<strong>on</strong> <strong>to</strong> estimate the


324 Deploying Phasemaintenance costs of the soluti<strong>on</strong> and prepare a budget. Changes made <strong>to</strong> the soluti<strong>on</strong>will be through the process of Change Management.During the quiet period, the efficiency of the soluti<strong>on</strong> can be ascertained by evaluating thefollowing:● <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>'s stability● <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>'s downtime● Maintenance required by the soluti<strong>on</strong>Transferring Ownership <strong>to</strong> Operati<strong>on</strong>sThe final transiti<strong>on</strong> occurs when the project team completes its tasks and transfers theinfrastructure, documentati<strong>on</strong>, and operati<strong>on</strong>s <strong>to</strong> the Operati<strong>on</strong>s team. The ownership ofthe soluti<strong>on</strong> is also transferred <strong>to</strong> the Operati<strong>on</strong>s team.The Operati<strong>on</strong>s team has <strong>to</strong> understand the functi<strong>on</strong>ing of the soluti<strong>on</strong> and manage it.The soluti<strong>on</strong>'s documentati<strong>on</strong> should supply in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> required <strong>to</strong> manage the soluti<strong>on</strong>.The Operati<strong>on</strong>s team will require the following documents <strong>to</strong> handle the soluti<strong>on</strong> aftermigrati<strong>on</strong>:● User manual. The user manual details the procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> working with thesoluti<strong>on</strong>. It also details the procedures <str<strong>on</strong>g>for</str<strong>on</strong>g> installati<strong>on</strong> and soluti<strong>on</strong> maintenance.● Hardware specificati<strong>on</strong>s. This document describes the hardware used in theproducti<strong>on</strong> envir<strong>on</strong>ment.● Software specificati<strong>on</strong>s. This document covers the different applicati<strong>on</strong>s, such asthird-party software used by the soluti<strong>on</strong> itself or used <strong>to</strong> stabilize the deployment.The software specificati<strong>on</strong>s also detail the different c<strong>on</strong>figurati<strong>on</strong>s and settingsapplied <strong>to</strong> the soluti<strong>on</strong> during or after the installati<strong>on</strong> and deployment of thesoluti<strong>on</strong>.● Support policies and procedures. This document details the updated businesspolicies and procedures that need <strong>to</strong> be followed after the migrati<strong>on</strong> is complete.Project Team TasksThe project team will examine the deployment <strong>to</strong> ensure that all areas of the deploymentare successfully completed and functi<strong>on</strong>ing as required. A final run of the tests thatcaused discrepancies can be used <strong>to</strong> check that they have been fixed. The project teamensures that:● All the procedures of the migrati<strong>on</strong> have been followed.● Backups are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med as required.● All security measures (hardware and software) are in place and operate withoutissues.● All errors and bugs are fixed.● Adequate training is provided <strong>to</strong> operati<strong>on</strong>s <strong>to</strong> manage the soluti<strong>on</strong>.● Different user accounts have been created and checked <str<strong>on</strong>g>for</str<strong>on</strong>g> their functi<strong>on</strong>ality.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 325Operati<strong>on</strong>s Team TasksThe operati<strong>on</strong>s team will check the soluti<strong>on</strong> <strong>to</strong> ensure that it c<strong>on</strong><str<strong>on</strong>g>for</str<strong>on</strong>g>ms <strong>to</strong> the businessobjectives. The operati<strong>on</strong>s team will:●●●●●C<strong>on</strong>duct a final run through of the soluti<strong>on</strong> <strong>to</strong> check its per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and stability.Ensure that the project team has completed all the tasks needed <strong>to</strong> complete thedeployment.Check that the <strong>to</strong>ols <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m routine tasks are set up.Review the documentati<strong>on</strong>.Decide the frequency <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming routine tasks.C<strong>on</strong>ducting Project Review and ClosureAfter the deployment of the soluti<strong>on</strong> is complete, the team c<strong>on</strong>ducts a review meeting <strong>to</strong>assess the migrati<strong>on</strong> project. This review covers all the phases of the migrati<strong>on</strong> project,including the Envisi<strong>on</strong>ing, Planning, Developing, Stabilizing and Deploying Phases. Bytaking the time <strong>to</strong> discuss the entire migrati<strong>on</strong> project, important less<strong>on</strong>s can be learnedand applied <strong>to</strong> future endeavors. This will also highlight the positive acti<strong>on</strong>s taken <strong>to</strong>successfully migrate the soluti<strong>on</strong>, and the less positive decisi<strong>on</strong>s or acti<strong>on</strong>s that delayedor hindered the migrati<strong>on</strong>. The project review can also compare the estimated outcome ofthe migrati<strong>on</strong> project with the actual targets achieved.The cus<strong>to</strong>mer sign-off signifies the end of the Deploying Phase. The soluti<strong>on</strong>'s keystakeholders review the migrated soluti<strong>on</strong> and documentati<strong>on</strong> and c<strong>on</strong>firm that the needsof the project have been met. After this sign-off has been received, the project team canbe disengaged. The exact terms of this sign off will depend <strong>on</strong> the migrati<strong>on</strong> requirements<str<strong>on</strong>g>for</str<strong>on</strong>g> the project.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 32720Operati<strong>on</strong>sIntroducti<strong>on</strong> and GoalsAfter the soluti<strong>on</strong> has been deployed, the operati<strong>on</strong>s staff inherits ownership of thesoluti<strong>on</strong> and is required <strong>to</strong> manage and maintain it. The operati<strong>on</strong>s team has beenprepared <str<strong>on</strong>g>for</str<strong>on</strong>g> this task by its involvement in the Deploying and Stabilizing Phases and byreviewing the documentati<strong>on</strong> prepared by the project team. Even if the Windows®envir<strong>on</strong>ment existed be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the migrati<strong>on</strong>, this project will have a great impact <strong>on</strong>operati<strong>on</strong>al tasks and resp<strong>on</strong>sibilities. This chapter provides additi<strong>on</strong>al links <strong>to</strong> guidance<strong>on</strong> how <strong>to</strong> operate the producti<strong>on</strong> infrastructure c<strong>on</strong>taining Microsoft® <strong>SQL</strong> <strong>Server</strong> andWindows technologies.Operati<strong>on</strong>al FrameworkWith the penetrati<strong>on</strong> of technology in<strong>to</strong> every aspect of modern day business, success isbased not <strong>on</strong>ly <strong>on</strong> the technology but also <strong>on</strong> the people and processes that c<strong>on</strong>trol thetechnology. The migrati<strong>on</strong> project has <strong>on</strong>ly c<strong>on</strong>tributed the technology and not theoperati<strong>on</strong>al aspects of the deployed soluti<strong>on</strong>. Microsoft Operati<strong>on</strong>s Framework (MOF) is acollecti<strong>on</strong> of best practices, principles, and models. It provides comprehensive technicalguidance <str<strong>on</strong>g>for</str<strong>on</strong>g> achieving missi<strong>on</strong>-critical producti<strong>on</strong> system reliability, availability,supportability, and manageability <str<strong>on</strong>g>for</str<strong>on</strong>g> soluti<strong>on</strong>s and services built <strong>on</strong> Microsoft productsand technologies.The following links provide in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the operati<strong>on</strong>al framework:● Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s <str<strong>on</strong>g>for</str<strong>on</strong>g> Infrastructure and Management (MSIM) provides in-depthtechnical procedural guidance <strong>on</strong> the management and operati<strong>on</strong> of Windowsbasedservers and computer data centers. More in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is available athttp://www.microsoft.com/tech net/itsoluti<strong>on</strong>s/cits/mo/default.mspx.● A brief overview of the MOF process model and c<strong>on</strong>cepts is provided in "AppendixA" of the <strong>UNIX</strong> Migrati<strong>on</strong> Project <str<strong>on</strong>g>Guide</str<strong>on</strong>g> (UMPG):http://go.microsoft.com/fwlink/?LinkId=19832.● An entire discussi<strong>on</strong> of MOF, its Service Management Functi<strong>on</strong>s (SMFs), and allthe resources that support the framework, is available athttp://www.microsoft.com/technet/itsoluti<strong>on</strong>s/techguide/mof/m ofpm.mspx.


328 Operati<strong>on</strong>sWindows Envir<strong>on</strong>ment Operati<strong>on</strong>sThis secti<strong>on</strong> provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about various aspects of a Windows <strong>Server</strong> 2003deployment in an enterprise envir<strong>on</strong>ment.System Administrati<strong>on</strong>●●For comm<strong>on</strong> administrative tasks, refer <strong>to</strong>http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/windowsserver2003/proddocs/entserver/ctasks_<strong>to</strong>pnode.asp.For <strong>to</strong>ols, refer <strong>to</strong>http://www.microsoft.com/windows server2003/downloads/<strong>to</strong>ols/default.mspx.● The Active Direc<strong>to</strong>ry Operati<strong>on</strong>s <str<strong>on</strong>g>Guide</str<strong>on</strong>g> is available athttp://www.microsoft.com/downloads/details.aspx?familyid=84dfe61e-fb7b-4673-89b8-55bcc801b431&displaylang=en.●●A technical overview of network load balancing is available athttp://www.microsoft.com/technet/prodtechnol/acs/reskit/acrkappb.mspx.Security Administrati<strong>on</strong>●●●●●●The Windows <strong>Server</strong> 2003 <str<strong>on</strong>g>Guide</str<strong>on</strong>g> is available athttp://www.microsoft.com/technet/security/prodtech/win2003/w2003hg/sgch00.mspx.A source c<strong>on</strong>taining a wide range of security <strong>to</strong>pics and technologies is available athttp://www.microsoft.com/security/guidance/default.mspx.For best practices <str<strong>on</strong>g>for</str<strong>on</strong>g> implementing a Microsoft Windows <strong>Server</strong> 2003 Public KeyInfrastructure, refer <strong>to</strong>http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/security/ws3pkibp.mspx.In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> account passwords and policies is available athttp://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/security/bpactlck.mspx.In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> certificate templates is available athttp://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/security/ws03crtm.mspx.The Security Services FAQ is available athttp://www.microsoft.com/resources/documentati<strong>on</strong>/WindowsServ/2003/standard/proddocs/enus/Default.asp?url=/resources/documentati<strong>on</strong>/windowsserv/2003/standard/proddocs/en-us/safer_how<strong>to</strong>.asp.Security checklists <str<strong>on</strong>g>for</str<strong>on</strong>g> securing Windows 2003 <strong>Server</strong> are available athttp://www.microsoft.com/security/guidance/checklists/default.mspx.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 329M<strong>on</strong>i<strong>to</strong>ring●●●In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the <strong>to</strong>ols available <str<strong>on</strong>g>for</str<strong>on</strong>g> m<strong>on</strong>i<strong>to</strong>ring is available athttp://www.microsoft.com/resources/documentati<strong>on</strong>/WindowsServ/2003/enterprise/proddocs/enus/Default.asp?url=/resources/documentati<strong>on</strong>/WindowsServ/2003/enterprise/proddocs/en-us/<strong>to</strong>ols_m<strong>on</strong>i<strong>to</strong>ring_status.asp.For m<strong>on</strong>i<strong>to</strong>ring of server per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, refer <strong>to</strong>http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/windowsserver2003/proddocs/entserver/ctasks019.asp.For m<strong>on</strong>i<strong>to</strong>ring of security-related events, refer <strong>to</strong>http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/windowsserver2003/proddocs/entserver/ctasks018.asp.Additi<strong>on</strong>al Links●●●In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> Windows <strong>Server</strong> 2003 per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and scalability is available athttp://www.microsoft.com/windowsserver2003/evaluati<strong>on</strong>/per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance/perfscaling.mspx.In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> account management <str<strong>on</strong>g>for</str<strong>on</strong>g> Windows <strong>Server</strong> 2003 is available athttp://www.microsoft.com/business/reducecosts/efficiency/manageability/account.mspx.Best practices <str<strong>on</strong>g>for</str<strong>on</strong>g> managing Windows <strong>Server</strong> 2003 are available athttp://www.microsoft.com/technet/community/events/windows2003srv/tnt1-106.mspx.<strong>SQL</strong> <strong>Server</strong> Envir<strong>on</strong>ment Operati<strong>on</strong>sThis secti<strong>on</strong> provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> various aspects of a <strong>SQL</strong> <strong>Server</strong> 2000 deploymentthat can be used <strong>to</strong> ensure optimal per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance in an enterprise envir<strong>on</strong>ment.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is also critical <strong>to</strong> scalability.Administrati<strong>on</strong>● For detailed in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> <strong>SQL</strong> <strong>Server</strong> administrati<strong>on</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_adminovw_7f3m.asp.● In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about administrati<strong>on</strong> subjects is available athttp://www.microsoft.com/sql/techinfo/administrati<strong>on</strong>/2000/default.asp.● For detailed discussi<strong>on</strong>s <strong>on</strong> <strong>to</strong>pics such as indexes, statistics, au<strong>to</strong>mati<strong>on</strong>, andmemory management, refer <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> 2000 Operati<strong>on</strong>s <str<strong>on</strong>g>Guide</str<strong>on</strong>g>: SystemAdministrati<strong>on</strong> athttp://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlops4.mspx.● In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about backup and recovery is available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_bkprst_9zcj.asp.● A discussi<strong>on</strong> <strong>on</strong> recovery models is available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/dnsqlmag2k/html/dbRecovery.asp.


330 Operati<strong>on</strong>sSecurityFor detailed discussi<strong>on</strong> <strong>on</strong> managing security, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_security_05bt.asp.M<strong>on</strong>i<strong>to</strong>ringFor m<strong>on</strong>i<strong>to</strong>ring of system per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and activity, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_m<strong>on</strong>_perf_00mr.asp.Additi<strong>on</strong>al LinksThe following links provide in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> <strong>SQL</strong> <strong>Server</strong> 2000 envir<strong>on</strong>ment operati<strong>on</strong>s:●●In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about security patch management <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> is available athttp://www.microsoft.com/business/reducecosts/efficiency/manageability/patch.mspx.The <strong>SQL</strong> <strong>Server</strong> 2000 Operati<strong>on</strong>s <str<strong>on</strong>g>Guide</str<strong>on</strong>g> is available athttp://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlops0.mspx.Also refer <strong>to</strong> Appendix B, "Getting the Best out of <strong>SQL</strong> <strong>Server</strong> 2000 and Windows," <str<strong>on</strong>g>for</str<strong>on</strong>g>links <strong>to</strong> additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance,scalability, and high availability.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 331APPENDICESAppendix A: <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Professi<strong>on</strong>alsOne of the assumpti<strong>on</strong>s of this guide has been that both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> andMicrosoft® <strong>SQL</strong> <strong>Server</strong> database administrati<strong>on</strong> experience is available in the projectteam. The success of the migrati<strong>on</strong> depends <strong>on</strong> how well the requirements of the currentenvir<strong>on</strong>ment are translated in<strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ment. The knowledge andinvolvement of the cus<strong>to</strong>dians of the current envir<strong>on</strong>ment, the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBAs, is veryimportant. A separate set of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> DBAs working <strong>on</strong> the migrati<strong>on</strong> hasthe disadvantage of possible communicati<strong>on</strong> problems and cost. Hence training the<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBAs in <strong>SQL</strong> <strong>Server</strong> will serve the purpose of per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming the migrati<strong>on</strong>, retainingDBAs with valuable knowledge of the business and the databases, and preparing them <strong>to</strong>manage the new <strong>SQL</strong> <strong>Server</strong> envir<strong>on</strong>ment.The purpose of this appendix is <strong>to</strong> provide a primer <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBAs in the workings of<strong>SQL</strong> <strong>Server</strong> and its administrati<strong>on</strong>. The transiti<strong>on</strong> from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> is eased bytheseveral similarities that exist between the two RDBMSs. Some of the keycomm<strong>on</strong>alities include:● Relati<strong>on</strong>al engine. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use an optimizer <strong>to</strong> generate anoptimal executi<strong>on</strong> plan from alternative soluti<strong>on</strong>s using statistics and access paths.The executi<strong>on</strong> plan can be influenced by optimizer hints.● Process architecture. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> have specialized processes<str<strong>on</strong>g>for</str<strong>on</strong>g> user c<strong>on</strong>necti<strong>on</strong>s (shared) and dedicated database functi<strong>on</strong>s. <strong>SQL</strong> <strong>Server</strong> usesthreads and provides CPU affinity, features that are found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> MicrosoftWindows®.● Memory architecture. In both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, memory is broken up in<strong>to</strong>buffers or caches with separate memory areas <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong>, procedural <strong>SQL</strong>, datadicti<strong>on</strong>ary, and sessi<strong>on</strong>. Database buffers or caches are manipulated in terms ofpages/blocks. Both have similar buffer replacement policies (Least Recently Usedpolicy).● S<strong>to</strong>rage architecture. In both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>, the physical database isstructured as data files, system files, transacti<strong>on</strong> logs, and c<strong>on</strong>trol files. Logicalstructures <strong>to</strong> complement the physical structures are hierarchical in nature.● Backup opti<strong>on</strong>s. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> provide various opti<strong>on</strong>s <str<strong>on</strong>g>for</str<strong>on</strong>g> backing updatabases, such as <strong>on</strong>line backups, full and partial backups, and transacti<strong>on</strong> logbackups.● Recovery model. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> use transacti<strong>on</strong> logs (redo) androllback. Recovery is possible using single file backups, transacti<strong>on</strong> logs, and so<strong>on</strong>.● Tools. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> employ Enterprise Manager, <strong>SQL</strong> clientArchitectureAn understanding of <strong>SQL</strong> <strong>Server</strong> architecture and how it compares and c<strong>on</strong>trasts with<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> is fundamental in shaping the migrati<strong>on</strong> as well as extracting the optimalper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance out of the <strong>SQL</strong> <strong>Server</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>m.


332 Appendices<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> are very similar in their architecture and internal workings.However, the same terms have different meanings in the two envir<strong>on</strong>ments. For example,in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> the term instance is used <str<strong>on</strong>g>for</str<strong>on</strong>g> the memory and processes that support an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>database. However, in <strong>SQL</strong> <strong>Server</strong>, the term instance c<strong>on</strong>tains the memory, processes,and also the user databases. Irrespective of the terminologies used, <strong>SQL</strong> <strong>Server</strong> alsouses memory and process comp<strong>on</strong>ents in a manner similar <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. In this discussi<strong>on</strong>,<strong>SQL</strong> <strong>Server</strong> is presented <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBA using an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>-like view.Database and InstanceA database, by definiti<strong>on</strong>, is the reposi<strong>to</strong>ry <str<strong>on</strong>g>for</str<strong>on</strong>g> data and metadata (data dicti<strong>on</strong>ary). Thisdefiniti<strong>on</strong> is universal in nature. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the term database is used <strong>to</strong> specifically refer<strong>to</strong> the files that are used <strong>to</strong> s<strong>to</strong>re the database's data and metadata. The term instance isused <str<strong>on</strong>g>for</str<strong>on</strong>g> the memory structures (System Global Area is the main comp<strong>on</strong>ent) andprocesses that are required <strong>to</strong> access and per<str<strong>on</strong>g>for</str<strong>on</strong>g>m work against the database. In <strong>SQL</strong><strong>Server</strong>, the instance is used collectively <str<strong>on</strong>g>for</str<strong>on</strong>g> the data files, memory, and processes. FigureA.1 illustrates the similarities between instances of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> with respect<strong>to</strong> memory and processes. Only the important comp<strong>on</strong>ents of an instance—the SGA andthe processes — are covered in the figure. Details of the <strong>SQL</strong> <strong>Server</strong> architecture can befound at http://msdn.microsoft.com/<strong>SQL</strong>/sqlarchitecture/default.aspx.Figure A.1<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> 2000 – High level comparis<strong>on</strong> of Instance and Database in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong><strong>Server</strong> <strong>to</strong> show architectural similaritiesApart from the defined meaning of the terms instance and database in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong><strong>Server</strong>, the terms are used very loosely <strong>to</strong> mean an occurrence of the database. Thephrase “multiple instances or multiple databases running <strong>on</strong> a single database server” isa typical usage of this terminology. Database administra<strong>to</strong>rs should be able <strong>to</strong> infer themeaning from the c<strong>on</strong>text.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 333What can be c<strong>on</strong>fusing with <strong>SQL</strong> <strong>Server</strong> is the presence of several system and usercreated“databases” inside a <strong>SQL</strong> <strong>Server</strong> database. Hence the term database systemhas been coined here <strong>to</strong> mean an occurrence of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> or <strong>SQL</strong> <strong>Server</strong>. MultipleDatabase Systems (Instances)In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, multiple database systems can be created <strong>on</strong> a single server and the creati<strong>on</strong>is independent of the software installati<strong>on</strong> (using the CREATE DATABASE <strong>SQL</strong>command). The same is not true with <strong>SQL</strong> <strong>Server</strong>. The initial database system (default ornamed) is created as part of the software installati<strong>on</strong>. The software distributi<strong>on</strong> is als<strong>on</strong>eeded <strong>to</strong> create additi<strong>on</strong>al database systems. For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> working with namedand multiple instances of <strong>SQL</strong> <strong>Server</strong> 2000, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/instsql/in_runsetup_2xmb.asp.The following comp<strong>on</strong>ents are shared between all of the instances running <strong>on</strong> the samecomputer:● There is <strong>on</strong>ly <strong>on</strong>e <strong>SQL</strong> <strong>Server</strong> 2000 program group (Microsoft <strong>SQL</strong> <strong>Server</strong>) <strong>on</strong> thecomputer, and <strong>on</strong>ly <strong>on</strong>e copy of the utility represented by each ic<strong>on</strong> in the programgroup. There is <strong>on</strong>ly <strong>on</strong>e copy of <strong>SQL</strong> <strong>Server</strong> Books Online.● The versi<strong>on</strong>s of the utilities in the program group are from the first versi<strong>on</strong> of <strong>SQL</strong><strong>Server</strong> installed <strong>on</strong> the computer.● There is <strong>on</strong>ly <strong>on</strong>e copy of the MSSearchService that manages full-text searchesagainst all of the instances of <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> the computer.● There is <strong>on</strong>ly <strong>on</strong>e copy each of the English Query and Microsoft <strong>SQL</strong> <strong>Server</strong> 2000Analysis Services servers.● The registry keys associated with the client software are not duplicated betweeninstances.● There is <strong>on</strong>ly <strong>on</strong>e copy of the <strong>SQL</strong> <strong>Server</strong> development libraries (include and .libfiles) and sample applicati<strong>on</strong>s.Extending out <strong>to</strong> the client tier, the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> clients and <strong>SQL</strong> <strong>Server</strong> clients c<strong>on</strong>nect <strong>to</strong>databases in similar, albeit proprietary, pro<strong>to</strong>cols: Transparent <strong>Net</strong>work Substrate (TNS)<str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and Tabular Data Stream (TDS) <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>. Figure A.2 compares theuser-instance-database interacti<strong>on</strong> paths.


334 AppendicesFigure A.2<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> 2000 — User-instance database interacti<strong>on</strong> comparedUnlike <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, <strong>SQL</strong> <strong>Server</strong> does not s<strong>to</strong>re client c<strong>on</strong>figurati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> in an operatingsystem file. <strong>SQL</strong> <strong>Server</strong> uses registry keys <strong>to</strong> s<strong>to</strong>re such in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. By default, <strong>SQL</strong><strong>Server</strong> is c<strong>on</strong>figured <strong>to</strong> listen <strong>on</strong> TCP/IP network pro<strong>to</strong>col, which should suffice <str<strong>on</strong>g>for</str<strong>on</strong>g> mostinstallati<strong>on</strong>s migrating from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. The server network utility (part of the serverinstallati<strong>on</strong>) can be used <strong>to</strong> c<strong>on</strong>figure <strong>SQL</strong> <strong>Server</strong> <strong>to</strong> listen <strong>on</strong> named pipes, multipro<strong>to</strong>col,NWLink, IPX/SPX, Banyan VINES, and Appletalk pro<strong>to</strong>cols.On the client side, the client network utility (part of the client installati<strong>on</strong>) can be used <strong>to</strong>set up alias names <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>s. The alias names can be mapped <strong>to</strong> an IP address ora named pipe address. The naming varies based <strong>on</strong> the type of installati<strong>on</strong>. Clients canc<strong>on</strong>nect <strong>to</strong>:● A default instance by specifying the servername.● A named instance by specifying the servername\instancename.The proper instance naming will have <strong>to</strong> be used while defining Data Source Names(DSN) in the c<strong>on</strong>necti<strong>on</strong> string of ODBC, ADO, DBI::DBD, Enterprise Manager, QueryAnalyzer, and isql utility.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 335Database ArchitectureA database has <strong>on</strong>e or more physical data files that c<strong>on</strong>tain all the database data. Thisfact has not changed from the early days of data reposi<strong>to</strong>ries, such as Sequential AccessMethods (SAM), Indexed Sequential Access Method (ISAM), and Virtual S<strong>to</strong>rage AccessMethod (VSAM), <strong>to</strong> the modern day relati<strong>on</strong>al database management systems (RDBMS).Though hardware throughput has improved in the past several years, the improvement indata access rates is not purely hardware-related, but also in part <strong>to</strong> the evoluti<strong>on</strong> of thedatabase s<strong>to</strong>rage architectures.Physical S<strong>to</strong>rage ArchitectureThe physical architecture is made up of files that c<strong>on</strong>tain the system (or catalog) andapplicati<strong>on</strong> data. As with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, <strong>SQL</strong> <strong>Server</strong> also has support <str<strong>on</strong>g>for</str<strong>on</strong>g> raw devices. Thephysical architecture is used <strong>to</strong> provide separati<strong>on</strong> of data based <strong>on</strong> its type, such asmetadata from user data; heap data from index data; user data from DBMS data(including transacti<strong>on</strong> logs), and permanent data from temporary data.The <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> physical architecture is made up of data files, redo log files, and c<strong>on</strong>trol files.<strong>SQL</strong> <strong>Server</strong> database systems have four system databases (master, model, tempdb,and msdb) and <strong>on</strong>e or more user databases. Each of these databases has <strong>on</strong>e or morefiles. Each database has its own transacti<strong>on</strong> log files, which are separate from the datafiles.Logical S<strong>to</strong>rage ArchitectureFor the c<strong>on</strong>venience of administrati<strong>on</strong> and efficiency of use, the physical s<strong>to</strong>rage isbroken down in<strong>to</strong> smaller logical structures. By dividing each physical data file in<strong>to</strong>several logical structures, and allocating space <strong>to</strong> each database object in increments ofthese smaller logical structures, access <strong>to</strong> the database objects can be insulated from thephysical file s<strong>to</strong>rage <strong>on</strong> the operating system. <strong>SQL</strong> <strong>Server</strong> has a s<strong>to</strong>rage hierarchy whichis similar <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>’s block-extent-segment-tablespace implementati<strong>on</strong>.This enables you <strong>to</strong> load smaller chunks of data in<strong>to</strong> memory <str<strong>on</strong>g>for</str<strong>on</strong>g> faster data access andalso enables you <strong>to</strong> move the physical locati<strong>on</strong> of a data file in the file system,transparent <strong>to</strong> the database objects or the applicati<strong>on</strong>s that access them. Figure A.3shows the hierarchy of s<strong>to</strong>rage structures available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Figure A.3Physical and Logical s<strong>to</strong>rage structure hierarchies in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>


336 AppendicesIn <strong>SQL</strong> <strong>Server</strong>, the term page is used instead of blocks. The data files are <str<strong>on</strong>g>for</str<strong>on</strong>g>matted in<strong>to</strong>blocks (pages) of the same size (8 KB). The unit of transfer <str<strong>on</strong>g>for</str<strong>on</strong>g> data between s<strong>to</strong>rage anddatabase memory is a block or page. The compositi<strong>on</strong> of the <strong>SQL</strong> <strong>Server</strong> page is similar<strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> block and is made up of page header, data rows and row offset array (rowdirec<strong>to</strong>ry). Free and used space is also tracked and managed similarly. <strong>SQL</strong> <strong>Server</strong> doesnot allow rows larger than 8060 bytes. This restricti<strong>on</strong>, however, does not apply <strong>to</strong> rowsc<strong>on</strong>taining large data types such as text, image, and so <strong>on</strong>, which can be s<strong>to</strong>redseparately.Although the data is s<strong>to</strong>red in blocks, the block is <strong>to</strong>o small a unit <str<strong>on</strong>g>for</str<strong>on</strong>g> allocati<strong>on</strong> <strong>to</strong> thedatabase objects. A bigger unit called extent, which corresp<strong>on</strong>ds <strong>to</strong> a specific number ofc<strong>on</strong>tiguous data blocks, is used <str<strong>on</strong>g>for</str<strong>on</strong>g> this purpose. <strong>SQL</strong> <strong>Server</strong> <strong>on</strong>ly supports fixed sizeextents of 64 KB (8 pages).For more details <strong>on</strong> the two types of extents and how they are used, refer <strong>to</strong> the “Pagesand Extents” article at http://msdn.microsoft.com/librar y/default.asp?url= /library/en-us/architec/8_ar_da2_4iu r.asp.Also refer <strong>to</strong> the “Managing Extent Alloc ati<strong>on</strong>s and Free Space” article athttp://msdn.mic rosoft.com/library/d efault.asp? url=/library/en-us/architec/8_ar_da2_4lgl. asp.The <strong>SQL</strong> <strong>Server</strong> equivalen t of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> tables pace is called the filegroup. Each <strong>SQL</strong><strong>Server</strong> database is created with a primary file bel<strong>on</strong>ging <strong>to</strong> the default primary filegroup.Opti<strong>on</strong>ally, sec<strong>on</strong>dary datafiles can be added <strong>to</strong> the primary filegroup or additi<strong>on</strong>alfilegroups can be created. Files and filegroups in <strong>SQL</strong> <strong>Server</strong> are implemented al<strong>on</strong>g thesame lines as datafiles and table spaces in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>.Instance ArchitectureThis secti<strong>on</strong> covers the two comp<strong>on</strong>ents that make up an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> instance: memory andprocesses and its <strong>SQL</strong> <strong>Server</strong> equivalents.Memory ArchitectureThe design of database m emory architecture in both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> Ser ver are based<strong>on</strong> the same objective. This objective is <strong>to</strong> acquire memory from the syste m and make itavailable <strong>to</strong> the RDBMS <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>m its work. Because the available memory is a verysmall percentage of the database size, the c<strong>on</strong>figurati<strong>on</strong> of memory is very important <strong>to</strong>the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of the database system. The memory per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance has <strong>to</strong> be optimizednot <strong>on</strong>ly <str<strong>on</strong>g>for</str<strong>on</strong>g> applicati<strong>on</strong> data, but also the data dicti<strong>on</strong>ary and the needs of the relati<strong>on</strong>alengine. For <strong>SQL</strong> this includes procedures, executi<strong>on</strong> plan, cursors, temporary objects,and sorting.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 337The <strong>SQL</strong> <strong>Server</strong> memory address space is illustrated in Figure A.4:Figure A.4<strong>SQL</strong> <strong>Server</strong> Address SpaceA 32-bit process is normally limited <strong>to</strong> addressing 2 GB of memory, or 3 GB if the systemwas booted using the /3G boot switch in boot.ini, even if there is more physical memoryavailable. However, both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> can use the MS Windows 2000Address Windowing Extensi<strong>on</strong>s (AWE) API <strong>to</strong> support up <strong>to</strong> a maximum of 64 GB ofphysical memory. The specific amount of memory is dependent <strong>on</strong> the hardware andoperating system versi<strong>on</strong>s. The AWE-enabled server c<strong>on</strong>figurati<strong>on</strong> parameter is availablein <strong>SQL</strong> <strong>Server</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the purpose. The Microsoft Knowledge Base Article 274750, "How <strong>to</strong>c<strong>on</strong>figure memory <str<strong>on</strong>g>for</str<strong>on</strong>g> more than 2 GB in <strong>SQL</strong> <strong>Server</strong>," is available athttp://support.microsoft.com/default.aspx?scid=kb;en-us;274750. It provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong><strong>on</strong> the maximum amount of memory that various Microsoft Windows Operating Systemversi<strong>on</strong>s can support and how <strong>to</strong> c<strong>on</strong>figure memory opti<strong>on</strong>s.An overview of the internals of memory management facilities of <strong>SQL</strong> <strong>Server</strong> 2000 isavailable at http://msdn.microsoft.com/sql/default.aspx?pull=/library/enus/dnsqldev/html/sqldev_01262004.asp.The <strong>SQL</strong> <strong>Server</strong> 2000 memory manager uses different algorithms <strong>to</strong> manage memory <strong>on</strong>different versi<strong>on</strong>s of Windows. While memory allocati<strong>on</strong> <strong>to</strong> the RDBMS has been rigidlyc<strong>on</strong>trolled in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> by the c<strong>on</strong>figurati<strong>on</strong> (initializati<strong>on</strong>) parameters, the sizes of thecomp<strong>on</strong>ents in <strong>SQL</strong> <strong>Server</strong> 2000 address space are au<strong>to</strong>-tuned dynamically incooperati<strong>on</strong> between the RDBMS and the operating system. All memory areas within thememory pool are also dynamically adjusted by the <strong>SQL</strong> <strong>Server</strong> code <strong>to</strong> optimizeper<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and do not need any administra<strong>to</strong>r input.The Memory Pool is the <strong>SQL</strong> <strong>Server</strong> equivalent of the SGA. The compositi<strong>on</strong> of thememory pool can be found athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/architec/8_ar_sa_1zu4.asp.


338 AppendicesProcess/Thread ArchitectureThe process architecture identifies the various database related processes and theirfuncti<strong>on</strong>ality. As is true with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> Windows, <strong>SQL</strong> <strong>Server</strong> also uses a thread-basedarchitecture. <strong>SQL</strong> <strong>Server</strong> does not differ significantly from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> in its use of pools ofprocesses (threads) <str<strong>on</strong>g>for</str<strong>on</strong>g> system functi<strong>on</strong>s and user requests. Table A.1 compares <strong>SQL</strong><strong>Server</strong> functi<strong>on</strong>ality with respect <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> background processes.Table A.1: Mapping of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> Background Processes<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Process(Required Status)*<str<strong>on</strong>g>Oracle</str<strong>on</strong>g>IdentifierMin / Max<strong>SQL</strong> <strong>Server</strong> Process(Required Status)*Min / MaxProcess M<strong>on</strong>i<strong>to</strong>r (M) PMON 1 / 1 Open Data Services (M) 1 / 1System M<strong>on</strong>i<strong>to</strong>r (M) SMON 1 / 1 Database cleanup / 1 / 1shrinking (M)Database Writers (M) DBWn 1 / 20 Lazywriter (M) 1 / 1Checkpoint Process (M) CKPT 1 / 1 Database checkpoint (M) 1 / 1Recoverer (O) RECO 0 / 1 MS DTC (O) 0 / 1Log Writer (M) LGWR 1 / 1 Logwriter (M) 1 / 1Archive Processes (O) ARCn 0 / 10 N/AJob Queue Processes Jnnn 0 / 1000 <strong>SQL</strong> Agent (O) 0 / 1(O)Job Queue Coordina<strong>to</strong>rs CJQn 0 / 1 <strong>SQL</strong> Agent (O)0 / 1(O)Queue M<strong>on</strong>i<strong>to</strong>rQMNn 0 / 10 <strong>SQL</strong> Agent (O) 0 / 1Processes (O)Parallel Query Slave Pnnn 0 / 3600 Worker threads (M) 32 / 32767Processes (O)Dispatcher (O) Dnnn 0 / 5 <strong>Net</strong>work thread (M) 1 / 1Shared <strong>Server</strong>s (O) Snnn 0 / OS Worker threads (M) 32 / 32767<strong>SQL</strong> <strong>Server</strong> employs sophisticated shared server architecture. On startup, <strong>SQL</strong> <strong>Server</strong>creates a User Mode Scheduler (UMS) o bject <str<strong>on</strong>g>for</str<strong>on</strong>g> each processor using the affinity masksetting. A pool of worker threads is created by Open Data Services (ODS) <strong>to</strong> handle usercommands, and their c<strong>on</strong>trol is distributed am<strong>on</strong>g the UMS schedulers. This architecturemimics the shared server-dispatcher c<strong>on</strong>cept in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. While in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> the shared serverprocesses are schedule d by the operating system, <strong>SQL</strong> <strong>Server</strong> uses the UMS <strong>to</strong>schedule worker threads.The internal workings of the User Mode Scheduler are available at:http://msdn.microsoft.com/<strong>SQL</strong>/sqlarchitectu re /default.aspx?pull=/library/en-us/dnsqldev/html/sqldev_02252004.asp?frame=true.Additi<strong>on</strong>al references <strong>on</strong> <strong>to</strong>pics related <strong>to</strong> process architecture include:● <strong>Server</strong> Memory Opti<strong>on</strong>s (Administrating <strong>SQL</strong> <strong>Server</strong>):http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_c<strong>on</strong>fig_9zfy.asp.● <strong>SQL</strong> <strong>Server</strong> Memory Usage: http://support.microsoft.com/default.aspx?scid=kb;enus;321363.● 64-bit Overview: http://www.microsoft.com/sql/64bit/productinfo/overview.asp.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 339●IO Affinity: http://support.microsoft.com/default.aspx?scid=kb;[LN];298402.● Allocating threads <strong>to</strong> a CPU:http://msdn.microsoft.com/library/default.asp?url=/library/enus/architec/8_ar_sa_8agl.asp.Relati<strong>on</strong>al Engine ArchitectureThe Relati<strong>on</strong>al Engine is the part of the RDBMS that is resp<strong>on</strong>sible <str<strong>on</strong>g>for</str<strong>on</strong>g> parsing,optimizing, and executing the <strong>SQL</strong> statements received from end users and returningresults (also known as fetching) <strong>to</strong> the end users.Figure A.5 illustrates the comp<strong>on</strong>ents of <strong>SQL</strong> <strong>Server</strong> relati<strong>on</strong>al engine.Figure A.5Comp<strong>on</strong>ents of <strong>SQL</strong> <strong>Server</strong> Relati<strong>on</strong>al EngineFigue A.5 illustrates the main comp<strong>on</strong>ents of the relati<strong>on</strong>al engine porti<strong>on</strong> of <strong>SQL</strong> <strong>Server</strong>.The illustrated comp<strong>on</strong>ents can be organized in<strong>to</strong> three groupings of subsystems:Compilati<strong>on</strong>, Executi<strong>on</strong>, and <strong>SQL</strong> Manager. The comp<strong>on</strong>ents parser, T-<strong>SQL</strong> compiler,normalizer, and query optimizer bel<strong>on</strong>g <strong>to</strong> the compilati<strong>on</strong> subsystem, which processesthe <strong>SQL</strong> statements. These statements typically come in as TDS messages. The <strong>SQL</strong>Manager, in the middle of the figure, <str<strong>on</strong>g>for</str<strong>on</strong>g>ms the sec<strong>on</strong>d subsystem, which c<strong>on</strong>trols theflow of everything inside the <strong>SQL</strong> <strong>Server</strong>. Remote Procedure Call (RPC) messages arehandled directly by the <strong>SQL</strong> Manager. T-<strong>SQL</strong> executi<strong>on</strong>, query executi<strong>on</strong>, and expressi<strong>on</strong>service <str<strong>on</strong>g>for</str<strong>on</strong>g>m the executi<strong>on</strong> subsystem. The query results come out of the expressi<strong>on</strong>service and are sent back out by ODS, after <str<strong>on</strong>g>for</str<strong>on</strong>g>matting the results in<strong>to</strong> TDS messages.The expressi<strong>on</strong> services library per<str<strong>on</strong>g>for</str<strong>on</strong>g>ms data c<strong>on</strong>versi<strong>on</strong>, predicate evaluati<strong>on</strong> orfiltering, and arithmetic calculati<strong>on</strong>s.The catalog services comp<strong>on</strong>ent handles data definiti<strong>on</strong> statements (DDL). The UMS is ascheduler internal <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> that handles the threads and fibers. The system-s<strong>to</strong>redprocedures are self evident.For a more detailed discussi<strong>on</strong> of the relati<strong>on</strong>al engine, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/dnsql7/html/sqlquerproc.asp.The c<strong>on</strong>cepts of executi<strong>on</strong> plan, cost based optimizati<strong>on</strong>, and hints are comm<strong>on</strong> <strong>to</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.A white paper <strong>on</strong> query optimizer and statistics is available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/dnsql2k/html/statquery.asp.


340 AppendicesTransacti<strong>on</strong> ArchitectureUsers and applicati<strong>on</strong>s interact with the database using transacti<strong>on</strong>s. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and<strong>SQL</strong> <strong>Server</strong> offer both optimistic and pessimistic c<strong>on</strong>currency c<strong>on</strong>trol. Pessimistic lockingis the default <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>. Microsoft <strong>SQL</strong> <strong>Server</strong> supports all four levels of isolati<strong>on</strong>:read uncommitted, read committed, repeatable read, and serializati<strong>on</strong>. Read committedis the default level of isolati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>.Like most RDBMSs, <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> achieve isolati<strong>on</strong> by c<strong>on</strong>trolling c<strong>on</strong>currentaccess <strong>to</strong> shared resources (such as schema objects) and their subcomp<strong>on</strong>ents (such asdata rows), and internal database structures using locks. Transacti<strong>on</strong>s acquire locks atdifferent levels of granularity. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the granularities are row and table, while in <strong>SQL</strong><strong>Server</strong> the granularities are row (RID and rowid), key (row lock within an index), page,exte nt, table, and database. A major difference between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> in theiruse of locks is that <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> does not escalate locks, while <strong>SQL</strong> <strong>Server</strong> escalates locks <strong>to</strong>reduce the system overhead of maintaining a large number of finer-grained locks. <strong>SQL</strong><strong>Server</strong> au<strong>to</strong>matically escalates row locks and page locks in<strong>to</strong> table locks when atransacti<strong>on</strong> exceeds its escalati<strong>on</strong> threshold.Table A.2 compares the types of locking available in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.Table A.2: Comparis<strong>on</strong> of the Modes of Locking in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong><str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> PurposeShare (S) Shared (S) Used <str<strong>on</strong>g>for</str<strong>on</strong>g> operati<strong>on</strong>s that do not changedata, such as SELECT statementsRow Share (RS) Update (U) Used <strong>on</strong> resources that can be updated,such as SELECT … FOR UPDATE in<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and SELECT statements withthe UPDLOCK lock hint in <strong>SQL</strong> <strong>Server</strong>Row Exclusive (RX) Exclusive (X) Used <str<strong>on</strong>g>for</str<strong>on</strong>g> data modificati<strong>on</strong> operati<strong>on</strong>s,such as INSERT, UPDATE, DELETEShare Row Exclusive N/A Only allows n<strong>on</strong>-update S and RS locks(SRX)Exclusive (X) Exclusive (X) Disables all other updatesN/A Intent Shared (IS) Indicates intenti<strong>on</strong> <strong>to</strong> read someresources lower in the hierarchyN/A Intent Exclusive (IX) Indicates intenti<strong>on</strong> <strong>to</strong> modify someresources lower in the hierarchyN/A Shared with IntentExclusive (SIX)Indicates intenti<strong>on</strong> <strong>to</strong> read all resourcesat a lower level and modify some ofthem using IX locksExclusive DDL Schema Modificati<strong>on</strong> For per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming DDL(Sch-M)Breakable Parse Schema Stability For compiling queries(Sch-S)N/ABulk Update (BU) For bulk copying data in<strong>to</strong> a table<strong>SQL</strong> <strong>Server</strong> Books Online has very useful in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> lock modes, lock hints, lockcompatibility, and deadlocks. More in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> is available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/architec/8_ar_sa2_2sit.asp.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 341Security ArchitectureThe database has security mechanisms such as logins, privileges, and roles <strong>to</strong> providec<strong>on</strong>trol over privileges <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> the database, access schema objects, andmanipulate their structure and data. Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> utilize a layeredapp roach <strong>to</strong> security, from logins <strong>to</strong> roles <strong>to</strong> system (statement) and object privileges.LoginsBoth <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> provide logins <str<strong>on</strong>g>for</str<strong>on</strong>g> authorized users <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> thedatabase. In <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, the login is called user or username, and in <strong>SQL</strong> <strong>Server</strong>, it is calledlogin identifier or simply login. Any operati<strong>on</strong> the user can per<str<strong>on</strong>g>for</str<strong>on</strong>g>m is c<strong>on</strong>trolled by theprivileges granted <strong>to</strong> the login.Authenticati<strong>on</strong>Both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> allow authenticati<strong>on</strong> by the operating system or by thedatabase (server). In <strong>SQL</strong> <strong>Server</strong>, the operating system mode is called WindowsAuthenticati<strong>on</strong> Mode and the database mode is called <strong>SQL</strong> <strong>Server</strong> Authenticati<strong>on</strong> Mode.<strong>SQL</strong> <strong>Server</strong> can operate in either Windows authenticati<strong>on</strong> mode or Windows and <strong>SQL</strong><strong>Server</strong> authenticati<strong>on</strong> mode.PasswordsThe features and functi<strong>on</strong>ality related <strong>to</strong> passwords, such as complexity, aging, or lockout, that exist with <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> logins, can <strong>on</strong>ly be found in Windows logins and not <strong>SQL</strong><strong>Server</strong> authenticated logins.Privileges<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> have a similar model <strong>to</strong> secure schema objects and applicati<strong>on</strong>data and system objects and metadata from unauthorized users. This is achieved bycreating two sets of privileges: system (statement) privileges (permissi<strong>on</strong>s) and objectprivileges (permissi<strong>on</strong>s). Privileges can be assigned <strong>to</strong> users and roles using the GRANTstatement and removed using the REVOKE statement. Roles are used <strong>to</strong> grant privileges<strong>to</strong> users, but indirectly, are discussed next.Roles<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> provides predefined roles, the most familiar being CONNECT, RESOURCE, DBA,and so <strong>on</strong>. Similarly, <strong>SQL</strong> <strong>Server</strong> has several predefined roles with specific permissi<strong>on</strong>s.There are two types of predefined roles: fixed server roles and fixed database roles. Both<str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer user-defined roles.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the privileges available in <strong>SQL</strong> <strong>Server</strong> and their management,refer <strong>to</strong> http://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_security_94dv.asp.For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> creating user-defined roles in <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_security_6x5x.asp.Microsoft <strong>SQL</strong> <strong>Server</strong> 2000 SP3 Security Features and Best Practices is available at:http://www.microsoft.com/sql/techinfo/administrati<strong>on</strong>/2000/security/securityWP.asp. Itprovides a detailed account of <strong>SQL</strong> <strong>Server</strong> security model and best practices.


342 AppendicesData Dicti<strong>on</strong>aryThe data dicti<strong>on</strong>ary, referred <strong>to</strong> in <strong>SQL</strong> <strong>Server</strong> as the system catalog, is broken up in<strong>to</strong> asystem-level comp<strong>on</strong>ent in the master database and individual database-levelcomp<strong>on</strong>ents in each of the other databases. It has the following characteristics:● Each of the databases c<strong>on</strong>tains tables <strong>to</strong> maintain its own database objects(tables, indexes, c<strong>on</strong>straints, users, privileges, replicati<strong>on</strong> definiti<strong>on</strong>) and othersystem structures (filegroups, files).● The centralized system catalog in the master database c<strong>on</strong>tains in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> whichis a combinati<strong>on</strong> of <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> c<strong>on</strong>trol files and data dicti<strong>on</strong>ary, such as individualdatabase names and primary file locati<strong>on</strong>, server level logins, system messages,c<strong>on</strong>figurati<strong>on</strong> (initializati<strong>on</strong> parameter) values, remote servers, linked servers,system procedures (such as the DBMS_ <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> s<strong>to</strong>red programs), and so <strong>on</strong>.The features of the data dicti<strong>on</strong>ary that an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> DBA is familiar with — system tables,views, functi<strong>on</strong>s, and procedures — can also be found in <strong>SQL</strong> <strong>Server</strong> in the following<str<strong>on</strong>g>for</str<strong>on</strong>g>ms:● System tablesThese serve the same functi<strong>on</strong> as <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>’s data dicti<strong>on</strong>ary tables. The systemtables should be used <str<strong>on</strong>g>for</str<strong>on</strong>g> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong>ly.System tables available under the master database s<strong>to</strong>re server-level systemin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>. For example:● master..syslogins — Available login accounts● master..sysdatabases — Available databasesThe following tables s<strong>to</strong>re database-level system in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> the respectivedatabase:● sy susers — Available user accounts with privileg es <strong>on</strong> database● sysobjects — Available objects in database● sysindexes — Available indexes in databaseFor a complete listing of system tables and their use, refer <strong>to</strong>http:// msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sys_00_690z.asp.● In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> schema views<strong>SQL</strong> <strong>Server</strong> offers in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> schema views which are equivalent <strong>to</strong> the ALL_views found in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>. In<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> can be retrieved from these views by queryingthe corresp<strong>on</strong>ding INFORMATION_SCHEMA.view_name. For example, the viewsthat are visible <strong>to</strong> a user can be verified by usingINFORMATION_SCHEMA.VIEWS. Below is a list of comm<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> schemaviews.● in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>_schema.tables — Available tables in a database● in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>_schema.columns — Available columns in a database● in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>_schema.table_privileges — Available privileges <strong>on</strong> tables in adatabaseThe in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> schema views <strong>to</strong>pic is discussed athttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_iaiz_4pbn.asp.● System functi<strong>on</strong>s


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 343●Equivalents <str<strong>on</strong>g>for</str<strong>on</strong>g> built-in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> functi<strong>on</strong>s can be found in <strong>SQL</strong> <strong>Server</strong> under theSystem functi<strong>on</strong>s heading. Some comm<strong>on</strong>ly used functi<strong>on</strong>s include:● User_name(id)● getdate()● system_user()For a list of all available <strong>SQL</strong> <strong>Server</strong> system functi<strong>on</strong>s, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fafz_79f7.asp.System s<strong>to</strong>red proceduresThe system s<strong>to</strong>red procedures aid the administra<strong>to</strong>r in per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming comm<strong>on</strong>functi<strong>on</strong>s by supplementing the DDL. They also provide in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> from systemtables, prepackaged <strong>to</strong> save the administra<strong>to</strong>r from writing his or her own queriesand views. The system s<strong>to</strong>red procedures can be c<strong>on</strong>sidered <strong>to</strong> be the equivalen<strong>to</strong>f <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s DBMS and UTL packages. These procedures are designed <strong>to</strong> becomprehensive and remove the burden of having <strong>to</strong> remember DDL syntax andsystem table names.For a complete listing of system s<strong>to</strong>red procedures, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_00_519s.aspAdministrati<strong>on</strong>This secti<strong>on</strong> provides brief introducti<strong>on</strong>s <strong>to</strong> <strong>to</strong>pics such as export, import, backup,recovery, and m<strong>on</strong>i<strong>to</strong>ring.Export/ImportIn <strong>SQL</strong> <strong>Server</strong>, data can be imported and exported using the Data Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>Services (DTS) <strong>to</strong>ol, Transact-<strong>SQL</strong> statements (INSERT INTO and BULK INSERT), andBulk Copy utility (bcp), which provides the same functi<strong>on</strong>ality as <strong>SQL</strong>*Loader.Export<strong>SQL</strong> <strong>Server</strong> does not have an equivalent of the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> export utility <strong>to</strong> move data in<strong>to</strong> abinary <str<strong>on</strong>g>for</str<strong>on</strong>g>mat file. Individual schema objects can be backed up <strong>to</strong> text-based flat files inany of the several available file <str<strong>on</strong>g>for</str<strong>on</strong>g>mats, or they can be exported <strong>to</strong> any of the severalOLE DB destinati<strong>on</strong>s and res<strong>to</strong>red using <strong>to</strong>ols and utilities.One of the following methods can be used <strong>to</strong> extract or spool data in<strong>to</strong> flat files:● Using the <strong>to</strong>ol osql.exe is similar <strong>to</strong> <strong>SQL</strong>*Plus in the way the users can runcommands at the prompt.● Using bcp, the bulk copy utility● Using the D ata Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> Services (DTS) <strong>to</strong>olImport<strong>SQL</strong> <strong>Server</strong> does have an equivalent <strong>to</strong> the <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> import utility, but as menti<strong>on</strong>ed in theprevious secti<strong>on</strong>, individual schema objects that have been exported <strong>to</strong> flat files with anyof the several supported file <str<strong>on</strong>g>for</str<strong>on</strong>g>mats or <strong>to</strong> any OLE DB destinati<strong>on</strong> can be imported in<strong>to</strong> adatabase using <strong>on</strong>e of the many <strong>to</strong>ols and utilities.Three ways that data can be imported in<strong>to</strong> <strong>SQL</strong> <strong>Server</strong> include:


344 Appendices●●●Using the BULK INSERT command, which acts as an interface <strong>to</strong> the bcp utility.The structure of the BULK INSERT command is similar <strong>to</strong> the structure of thec<strong>on</strong>trol file used in <strong>SQL</strong>*Loader.Using bcp, the bulk copy utility.Using the Data Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> Services (DTS) <strong>to</strong>ol.The functi<strong>on</strong>ality and use of bcp, BULK INSERT, and DTS <str<strong>on</strong>g>for</str<strong>on</strong>g> moving data from <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>int o <strong>SQL</strong> <strong>Server</strong> have been dem<strong>on</strong>strated in Chapter 8. DTS has also been discussed inmore detail in Appendix B: "Getting the Best out of <strong>SQL</strong> <strong>Server</strong> 2000 and Windows."Some additi<strong>on</strong>al references <strong>on</strong> these utilities are:●●●the "DTS Package Development, Deployment and Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance" article availableat http://support.microsoft.com/default.aspx?scid=kb;en-us;242391&sd=tech.For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> different switches available with BULK INSERT, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_babz_4fec.asp.For tips <strong>on</strong> optimizing bulk copy read, refer <strong>to</strong>http: //www.databasejournal.com/features/mssql/article.php/3095511.BackupIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, backup methods can be categorized at a high level as physical and logicalbackups. Comparable methods <str<strong>on</strong>g>for</str<strong>on</strong>g> backing up the database can be found in <strong>SQL</strong> <strong>Server</strong>.Table A.3 provides a comparis<strong>on</strong> of the available methods:Table A.3: Backup Methods in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>Backup Method <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong>Logical Export bcp or DTSPhysical Cold ColdPhysical Online FullPhysical Incremental Transacti<strong>on</strong> log orDifferentialPhysical Archive log Transacti<strong>on</strong> logLogical BackupsThe goal of a logical backup is <strong>to</strong> be able <strong>to</strong> recover at the individual schema object level.Although <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>'s export and import utilities are designed <str<strong>on</strong>g>for</str<strong>on</strong>g> moving <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> data, theycan be used as a supplemental method of protecting data in an <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> database. It is notrecommended <strong>to</strong> use logical backups as the sole method of data backup.<strong>SQL</strong> <strong>Server</strong> does not support logical backups <strong>to</strong> proprietary binary <str<strong>on</strong>g>for</str<strong>on</strong>g>mat files. Individualschema objects, however, can be backed up <strong>to</strong> flat files in any of the several supportedfile <str<strong>on</strong>g>for</str<strong>on</strong>g>mats and res<strong>to</strong>red using <strong>to</strong>ols such as the bcp utility and DTS <strong>to</strong>ols.Physical BackupsIn <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>, a physical backup involves making copies of database files including datafiles,c<strong>on</strong>trol files, and, if the database is in ARCHIVELOG MODE, archived redo log files. Thesame is true in <strong>SQL</strong> <strong>Server</strong>, though a backup is viewed <strong>to</strong> be at the database level.Larger databases can utilize filegroup backups <strong>to</strong> back up secti<strong>on</strong>s of a database. Thephysical backups available are:● Cold (offline) backups. A cold backup or a closed backup can be described as abackup of <strong>on</strong>e or more database files taken while the databaseis closed and is not


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 345available <str<strong>on</strong>g>for</str<strong>on</strong>g> user access. Even though the term cold backup is not menti<strong>on</strong>ed inthe documentati<strong>on</strong>, the method can be applied <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming backups in <strong>SQL</strong><strong>Server</strong>.● Online backups. A backup is termed as an <strong>on</strong>line backup or a hot backup if it istaken while the database is open and is accessible <strong>to</strong> users. <strong>SQL</strong> <strong>Server</strong> fullbackup backs up a complete database and includes transacti<strong>on</strong> log entries. Fileand filegroup backups can be made using the BACKUP DATABASE statement orthrough Enterprise Manager ->Backup Database -> File and filegroup.Transacti<strong>on</strong> logs can be backed up separately as well.Incremental BackupsPhysical incremental backups are per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <strong>to</strong> capture <strong>on</strong>ly the changed blocks, therebyreducing the time and space needed <str<strong>on</strong>g>for</str<strong>on</strong>g> the backups. Incremental backups areper<str<strong>on</strong>g>for</str<strong>on</strong>g>med after an initial complete backup has been per<str<strong>on</strong>g>for</str<strong>on</strong>g>med. In <strong>SQL</strong> <strong>Server</strong>,differential backups c<strong>on</strong>tain <strong>on</strong>ly data that has changed since a last full backup.Differential database backups can be made using the BACKUP DATABASE statement orthrough Enterprise Manager -> Backup Database -> Database — differential.RecoveryThe three recovery models offered by <strong>SQL</strong> <strong>Server</strong>—Full, Bulk-logged, and Simple—arediscussed below.● Full recovery model. This is used when the data is critical and must berecoverable <strong>to</strong> point of failure. All recovery opti<strong>on</strong>s are available in this recoverymodel. This is equivalent <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>’s ARCHIVELOG mode (when theNOLOGGING opti<strong>on</strong> is not specified at any level), where all transacti<strong>on</strong>s arelogged and logs are archived <str<strong>on</strong>g>for</str<strong>on</strong>g> full recoverability.● Bulk-logged recovery model. This is the mid-level recovery model available <str<strong>on</strong>g>for</str<strong>on</strong>g>bulk operati<strong>on</strong>s such as bulk copy, SELECT INTO, and text processing. Thisrecovery model does not provide point-in-time recovery past the beginning of anybulk operati<strong>on</strong>. This is similar <strong>to</strong> setting the NOLOGGING opti<strong>on</strong> at the tablespace,object level, or <str<strong>on</strong>g>for</str<strong>on</strong>g> individual commands <strong>to</strong> avoid logging of bulk operati<strong>on</strong>s.● Simple recovery model. This is used when it is not important <strong>to</strong> completelyrecover the database or the lost data can be recreated. This recovery model hasthe lowest logging overhead. This is equivalent <strong>to</strong> running the database inNOARCHIVELOG mode.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the backup and recovery architecture of <strong>SQL</strong> <strong>Server</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/en-us/architec/8_ar_aa_9iw5.asp.A detailed account of the backup and recovery opti<strong>on</strong>s and techniques, as well asguidance <str<strong>on</strong>g>for</str<strong>on</strong>g> per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming these administrative tasks, is available athttp://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlops4.mspx.M<strong>on</strong>i<strong>to</strong>ringM<strong>on</strong>i<strong>to</strong>ring should be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med <str<strong>on</strong>g>for</str<strong>on</strong>g> availability, errors, and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.


346 AppendicesAvailabilityAvailability should cover the server(s), node(s), database services, and database.●●●<strong>Server</strong>. M<strong>on</strong>i<strong>to</strong>ring of the server should also include the network access path fromthe applicati<strong>on</strong> or client <strong>to</strong> the server. The most comm<strong>on</strong> method <strong>to</strong> achieve this isa ping test.Database Services. A comm<strong>on</strong> mode of m<strong>on</strong>i<strong>to</strong>ring <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> databases is <strong>to</strong> check<strong>on</strong> the instance-specific processes such as SMON or PMON. Because <strong>SQL</strong> <strong>Server</strong>uses thread architecture, <strong>on</strong>ly the main process (sqlservr.exe) can be m<strong>on</strong>i<strong>to</strong>red.Database. Even when the services are running, c<strong>on</strong>necting <strong>to</strong> a database may faildue <strong>to</strong> some errors. A sec<strong>on</strong>d level m<strong>on</strong>i<strong>to</strong>ring involving c<strong>on</strong>necting <strong>to</strong> thedatabase and per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming some simple tasks should expose such errors.The command line utility scm (Service C<strong>on</strong>trol Manager) can be used <strong>to</strong> check the healthof a <strong>SQL</strong> <strong>Server</strong> instance. Scripts can also be executed using <strong>SQL</strong> <strong>Server</strong> command lineutilities such as isql or osql.ErrorsIn a database envir<strong>on</strong>ment, errors, failures, or faults can occur in a number of areas.Erro rs have <strong>to</strong> be m<strong>on</strong>i<strong>to</strong>red by viewing (or mining) the error logs. The server event logsand the database instance logs are a good source <str<strong>on</strong>g>for</str<strong>on</strong>g> errors and violati<strong>on</strong>s.The event log, which c<strong>on</strong>tains entries <str<strong>on</strong>g>for</str<strong>on</strong>g> all database server instances and otherapp licati<strong>on</strong>s running <strong>on</strong> the server, can be accessed through the Microsoft WindowsEve nt Viewer utility. This can be accessed through Start -> Program -> AdministrativeTools -> Event Viewer. The events in the event log can be filtered by type, source, daterange, and so <strong>on</strong>.<strong>SQL</strong><strong>Server</strong> has predefined error codes and error messages (see master..sysmessages<str<strong>on</strong>g>for</str<strong>on</strong>g> a complete list) that give in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> such as unique error number, severity level, errorstate number, and error message <strong>on</strong> all errors.The <strong>SQL</strong> <strong>Server</strong> error logs provide complete in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> regarding all events, auditingmessages, errors, and so <strong>on</strong>, that have occurred against an instance. The error logs canbe viewed using a text edi<strong>to</strong>r or through Enterprise Manager. In Enterprise Manager, thelogs can be found using <strong>SQL</strong> <strong>Server</strong> Group -> <strong>Server</strong> Instance -> Management -><strong>SQL</strong> <strong>Server</strong> Logs.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mancePer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r and Task Manager are two of the several <strong>to</strong>ols that can be used <strong>to</strong>m<strong>on</strong>i<strong>to</strong>r resource usage at the server level as well as the <strong>SQL</strong> <strong>Server</strong> instance level. Thefollowing is a listing of the methods by which various server and database resources canbe m<strong>on</strong>i<strong>to</strong>red:● CPU. Task Manager: Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r: Processor● Memory. Task Manager: Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r: Memory● Process. Task Manager: Processes, Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r: Process● Virtual Memory. Task Manager: Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r: Paging File● <strong>Net</strong>work. Task Manager: <strong>Net</strong>working, Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r: <strong>Net</strong>work Interface● I/O. Task Manager: Processes, Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r: LogicalDisk and Pe<str<strong>on</strong>g>for</str<strong>on</strong>g>manceM<strong>on</strong>i<strong>to</strong>r: PhysicalDisk● S<strong>to</strong>rage.My Computer, Windows ExplorerSome references <strong>on</strong> m<strong>on</strong>i<strong>to</strong>ring <strong>SQL</strong> <strong>Server</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance are:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 347●●●●●●"Job <strong>to</strong> M<strong>on</strong>i<strong>to</strong>r <strong>SQL</strong> <strong>Server</strong> 2000 Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Activity" is available athttp://support .microsoft.com/default.aspx?scid=kb;EN-US;283696."How <strong>to</strong> m<strong>on</strong>i<strong>to</strong>r <strong>SQL</strong> <strong>Server</strong> 2000 blocking" is available athttp://support.microsoft.com/default.aspx?scid=kb;en-us;271509&Product=sql2k."How <strong>to</strong> View <strong>SQL</strong> <strong>Server</strong> 2000 Activity Data" is available athttp://support.microsoft.com/default.aspx?scid=kb;en-us;283784&Product=sql2k."How <strong>to</strong> View <strong>SQL</strong> <strong>Server</strong> 2000 Blocking Data" is available athttp://support.microsoft.com/default.aspx?scid=kb;en-us;283725&Product=sql2k."How To: View <strong>SQL</strong> <strong>Server</strong> 2000 Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Data" is available athttp://support.microsoft.com/default.aspx?scid=kb;en-us;283886&Product=sql2k.Tools and functi<strong>on</strong>s <strong>to</strong> au<strong>to</strong>mate administrati<strong>on</strong> is available athttp://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlops4.mspx.


348 AppendicesThe per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of a <strong>SQL</strong> <strong>Server</strong> installati<strong>on</strong> is dependent <strong>on</strong> several fac<strong>to</strong>rs coveringdatabase design, applicati<strong>on</strong> design, query design, access methods (indexing schemesand views), hardware, and software resources. The following references cover the entirebreadth of <strong>to</strong>pics that are critical <strong>to</strong> getting the best per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance out of <strong>SQL</strong> <strong>Server</strong>.● "The Data Tier: An Approach <strong>to</strong> Database Optimizati<strong>on</strong>" is available athttp://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/ en-us/part10/c3361.mspx.● "Improving <strong>SQL</strong> <strong>Server</strong> Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance" includes schemas, queries, indexes,transacti<strong>on</strong>s, s<strong>to</strong>red procedures, executi<strong>on</strong> plans, and tuning <strong>to</strong>pics:http://msdn.microsoft.com/sql/default.aspx?pull=/library/enus/dnpag/html/scalenetchapt14.asp.● "How To: Optimize <strong>SQL</strong> Queries" is available athttp://msdn.microsoft.com/sql/default.aspx?pull=/library/enus/dnpag/html/scalenethow<strong>to</strong>04.asp.● "How To: Optimize <strong>SQL</strong> Indexes" is available athttp://msdn.microsoft.com/sql/default.aspx?pull=/library/enus/dnpag/html/scalenethow<strong>to</strong>03.asp.● "Microsoft <strong>SQL</strong> <strong>Server</strong> 2000 Index Defragmentati<strong>on</strong> Best Practices" is available athttp://www.microsoft.com/technet/prodtechnol/sql/2000/ma intain/ss2kidbp.mspx.● "Using Views with a View <strong>on</strong> Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance" is available athttp://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/enus/part10/c3661.mspx.● "Checklist: <strong>SQL</strong> <strong>Server</strong> Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance" is available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/dnpag/html/scalenetcheck08.asp.● <strong>SQL</strong> <strong>Server</strong> 2000 Operati<strong>on</strong>s <str<strong>on</strong>g>Guide</str<strong>on</strong>g>: System Administrati<strong>on</strong> has very detaileddiscussi<strong>on</strong>s <strong>on</strong> <strong>to</strong>pics such as indexes, statistics, au<strong>to</strong>mati<strong>on</strong>, and memorymanagement:http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sq lops4.mspx.● "Microsoft S<strong>to</strong>rage <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s – The Right S<strong>to</strong>rage and Productivity <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>" isavailable athttp://www.microsoft.com/windowsserversystem/s<strong>to</strong>rage/soluti<strong>on</strong>s/rightsoluti<strong>on</strong>/rightsoluti<strong>on</strong>.mspx.● "Windows 2003 Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance and Scalability" is available athttp://www.microsoft.com/windowsserver2003/evaluati<strong>on</strong>/per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance/perfscaling.mspx.Appendix B: Getting the Best Out of <strong>SQL</strong> <strong>Server</strong> 2000and WindowsThis appendix provides references <strong>on</strong> various aspects of a <strong>SQL</strong> <strong>Server</strong> 2000 deploymentthat can be exploited <strong>to</strong> ensure optimal per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance in an enterprise envir<strong>on</strong>ment.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance is also critical <strong>to</strong> scalability.Several of the links provided here have been referenced elsewhere in this guidance, butthey are repeated here <str<strong>on</strong>g>for</str<strong>on</strong>g> your c<strong>on</strong>venience.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 349ScalabilityScalability is the capability <strong>to</strong> handle increased volume of data of Very Large Databases(VLDBs) and activity. The size of the VLDBs may be due <strong>to</strong> a few large tables, or a largenumber of smaller tables, or a combinati<strong>on</strong> of both. Activity scalability is measured in thenumber of user c<strong>on</strong>necti<strong>on</strong>s, resp<strong>on</strong>se time, throughput, and so <strong>on</strong>. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong><strong>Server</strong> are c<strong>on</strong>tinually working <strong>on</strong> adding features and functi<strong>on</strong>ality which are directed atimproving their respective products <strong>to</strong> meet these demands. While some of thesefeatures, such as clustering, replicati<strong>on</strong>, and parallelism, are highlighted in specificati<strong>on</strong>sheets and documentati<strong>on</strong>, much of the scalability is built in at the lower levels of thearchitecture, such as use of bitmaps instead of lists <strong>to</strong> represent s<strong>to</strong>rage, in-row versusout-of-row data s<strong>to</strong>rage, and so <strong>on</strong>. The overall scalability is, however, dependent not<strong>on</strong>ly <strong>on</strong> the RDBMS, but also <strong>on</strong> the hardware and the applicati<strong>on</strong>. The followingreferences answer questi<strong>on</strong>s about scalability related <strong>to</strong> scaling out, scaling up, datapartiti<strong>on</strong>ing, 64-bit architecture, s<strong>to</strong>rage technology, operating system, and other related<strong>to</strong>pics.● "Scaling Out <strong>on</strong> <strong>SQL</strong> <strong>Server</strong>" is available athttp://www.microsoft.com/resources/documentati<strong>on</strong>/sql/2000/all/reskit/enus/part10/c3861.mspx.● "<strong>SQL</strong> <strong>Server</strong> Scalability FAQ" is available athttp://www.microsoft.com/sql/techinfo/administrati<strong>on</strong>/2000/scalabilityfaq.asp.● "Microsoft <strong>SQL</strong> <strong>Server</strong> 2000 Scalability Project — <strong>Server</strong> C<strong>on</strong>solidati<strong>on</strong>" is availableat http://msdn.microsoft.com/library/default.asp?url=/library/enus/dnsql2k/html/sql_asphosting.asp.High AvailabilityAvailability refers <strong>to</strong> the ability <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> and per<str<strong>on</strong>g>for</str<strong>on</strong>g>m acti<strong>on</strong>s against the databaseserver, the database, and the data. The features in <strong>SQL</strong> <strong>Server</strong> that c<strong>on</strong>tribute <strong>to</strong>availability are discussed here."<strong>SQL</strong> <strong>Server</strong> 2000 High Availability Series" provides the most complete set of whitepapers <strong>on</strong> planning and deploying a highly available envir<strong>on</strong>ment c<strong>on</strong>taining <strong>SQL</strong> <strong>Server</strong>.This series is available at:http://www.microsoft.com/technet/prodtechnol/sql/2000/deploy/harag01.mspx.Also refer <strong>to</strong> Microsoft <strong>SQL</strong> <strong>Server</strong> 2000 High Availability (Microsoft Press, 2003).Apart from covering the hardware technologies, the three <strong>SQL</strong> <strong>Server</strong> technologiescovered in this series are:● Clustering● Standby database or log shipping● Replicati<strong>on</strong>These <strong>to</strong>pics are discussed under the following headings.ClusteringBoth <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer high availability support through the use of clusters ofservers. The two DBMSs depend <strong>on</strong> the underlying hardware and system software <strong>to</strong>provide cluster management <strong>to</strong> detect and manage failures. <strong>SQL</strong> <strong>Server</strong> can be run in anActive-Passive or Active-Active c<strong>on</strong>figurati<strong>on</strong> using the Microsoft ClusterServices(MSCS).


350 AppendicesIn<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> Windows clustering and <strong>SQL</strong> <strong>Server</strong> failover clustering is available athttp://www.microsoft.c om/technet/prodtechnol/sql/2000/maintain/failclus.mspx.Standby Database or Log ShippingBoth <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> offer the standby database capability where a copy(sec<strong>on</strong>dary) of the entire (primary) database is maintained in a separate locati<strong>on</strong> <strong>to</strong>provide recovery from server node and database failures as well as catastrophicdisasters. Changes made <strong>to</strong> the primary are captured in redo or transacti<strong>on</strong> logs, shipped<strong>to</strong> the sec<strong>on</strong>dary site, and applied <strong>to</strong> the standby database. The applicati<strong>on</strong> of the logs <strong>to</strong>the standby database can be c<strong>on</strong>trolled <strong>to</strong> be near-synchr<strong>on</strong>ous, or lag behind theprimary <strong>to</strong> suit recovery needs.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about <strong>SQL</strong> <strong>Server</strong> log shipping, refer <strong>to</strong>:● The overview <strong>on</strong> log shipping available athttp://msdn.microsoft.com/library/default.asp?url=/library/enus/adminsql/ad_1_server_8elj.asp.● The FAQ available at http://support.microsoft.com/default.aspx?scid=kb;enus;314515&sd=tech.● "Microsoft <strong>SQL</strong> <strong>Server</strong> 2000 How <strong>to</strong> Setup Log Shipping" available athttp://support.microsoft.com/default.aspx?scid=%2fsupport%2fsql%2fc<strong>on</strong>tent%2f2000papers%2fLogShippingFinal.asp.Replicati<strong>on</strong>Replicati<strong>on</strong> is a set of technologies <str<strong>on</strong>g>for</str<strong>on</strong>g> copying and distributing data and databaseobjects from <strong>on</strong>e database <strong>to</strong> another and synchr<strong>on</strong>izing the data between them <str<strong>on</strong>g>for</str<strong>on</strong>g>c<strong>on</strong>sistency. Replicati<strong>on</strong> is based <strong>on</strong> the master-slave technique (called publishersubscriberin <strong>SQL</strong> <strong>Server</strong>) in both <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>. Replicati<strong>on</strong> is popularly used<strong>to</strong> provide high availability of shared data over a WAN.<strong>SQL</strong> <strong>Server</strong> offers the following <str<strong>on</strong>g>for</str<strong>on</strong>g>ms of replicati<strong>on</strong>:● Snapshot Replicati<strong>on</strong>. This is a materialized view (indexed view in <strong>SQL</strong> <strong>Server</strong>)c<strong>on</strong>taining a snapshot of data at a particular point in time.● Transacti<strong>on</strong>al Replicati<strong>on</strong>. This is a progressi<strong>on</strong> from the snapshot, with changessent <strong>to</strong> the subscriber at the transacti<strong>on</strong> level. This enables data modificati<strong>on</strong>smade at the publisher <strong>to</strong> be propagated <strong>to</strong> the subscribers and also enablessubscribers <strong>to</strong> make occasi<strong>on</strong>al updates back <strong>to</strong> the publisher.● Merge Replicati<strong>on</strong>. Merge replicati<strong>on</strong> is similar <strong>to</strong> the multimaster replicati<strong>on</strong>technique in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> that allows several instances of the object available at several<strong>SQL</strong> <strong>Server</strong> sites.For an overview, planning, <strong>to</strong>ols, implementati<strong>on</strong>, and other details of replicati<strong>on</strong>, refer <strong>to</strong>http://msdn.microsoft.com/library/default.asp?url=/library/enus/replsql/replover_694n.asp.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 351Features and ToolsA brief overview of some of the <strong>to</strong>ols that are very valuable in managing a <strong>SQL</strong> <strong>Server</strong>envir<strong>on</strong>ment is provided under the following headings.Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>rPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r is the most important <strong>to</strong>ol in m<strong>on</strong>i<strong>to</strong>ring <strong>SQL</strong> <strong>Server</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.When <strong>SQL</strong> <strong>Server</strong> is installed <strong>on</strong> a server, it adds a set of measuring and m<strong>on</strong>i<strong>to</strong>ringcounters <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>SQL</strong> <strong>Server</strong> instances.In additi<strong>on</strong> <strong>to</strong> visually m<strong>on</strong>i<strong>to</strong>ring per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance counters, the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of <strong>SQL</strong> <strong>Server</strong>can be logged using counter logs. All counters available <str<strong>on</strong>g>for</str<strong>on</strong>g> m<strong>on</strong>i<strong>to</strong>ring are also available<str<strong>on</strong>g>for</str<strong>on</strong>g> logging whose set up is separate from the m<strong>on</strong>i<strong>to</strong>ring.Similar <strong>to</strong> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> Enterprise Manager, where events can be set up <strong>to</strong> track space,resources, availability, per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance, and faults, alerts can be set up <strong>to</strong> track <strong>SQL</strong> <strong>Server</strong>activity using per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance m<strong>on</strong>i<strong>to</strong>r alerts and <strong>SQL</strong> <strong>Server</strong> Agent.The "M<strong>on</strong>i<strong>to</strong>ring <strong>SQL</strong> <strong>Server</strong> Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance" chapter in <strong>SQL</strong> <strong>Server</strong> 2000 Administra<strong>to</strong>r’sPocket C<strong>on</strong>sultant (Stanek, 2000) is a good reference <str<strong>on</strong>g>for</str<strong>on</strong>g> using Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r. Itis available athttp://www.microsoft.com/technet/prodtechnol/sql/2000/books/c10ppcsq.mspx.ProfilerThe <strong>SQL</strong> Profiler utility can be used <strong>to</strong> m<strong>on</strong>i<strong>to</strong>r the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance of instance comp<strong>on</strong>ents,Transact-<strong>SQL</strong> statements, s<strong>to</strong>red procedures, and auditing activity. This utility provides arobust set of functi<strong>on</strong>ality that allows you <strong>to</strong> opti<strong>on</strong>ally include a variety of events, reportin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> (data columns), and filtering capabilities.The article "How To: Use <strong>SQL</strong> Profiler" provides in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> how <strong>to</strong> track l<strong>on</strong>g runningqueries and heavily used s<strong>to</strong>red procedures. It is available athttp://msdn.microsoft.com/sql/default.aspx?pull=/library/en-us/dnpag/html/scalenethow<strong>to</strong>15.asp.<strong>SQL</strong> <strong>Server</strong> Health and His<strong>to</strong>ry Tool (<strong>SQL</strong>H2)This <strong>to</strong>ol allows collecti<strong>on</strong> of data from a running instance of <strong>SQL</strong> <strong>Server</strong> which can thenbe reviewed and reported <strong>on</strong>. For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> <strong>SQL</strong>H2, refer <strong>to</strong>http://www.microsoft.com/downloads/details.aspx?FamilyID=eedd10d6-75f7-4763-86de-d2347b8b5f89&DisplayLang=en.The <strong>to</strong>ol is especially useful <str<strong>on</strong>g>for</str<strong>on</strong>g> measuring service uptime and per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance trends.DTSData Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> Services (DTS) offer import and export of data by providing a set of<strong>to</strong>ols that let you extract, trans<str<strong>on</strong>g>for</str<strong>on</strong>g>m, and c<strong>on</strong>solidate data from disparate sources in<strong>to</strong>single or multiple destinati<strong>on</strong>s supported by DTS c<strong>on</strong>nectivity. By using DTS <strong>to</strong>ols <strong>to</strong>graphically build DTS packages, or by programming a package with the DTS objectmodel, you can create cus<strong>to</strong>m data movement soluti<strong>on</strong>s tailored <strong>to</strong> the specialized datatransfer needs.For more in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> DTS, refer <strong>to</strong> the "Data Trans<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> Services (DTS) inMicrosoft <strong>SQL</strong> <strong>Server</strong>" white paper available athttp://msdn.microsoft.com/<strong>SQL</strong>/sqlwarehouse/DTS/default.aspx.


352 AppendicesQuery AnalyzerT he <strong>SQL</strong> Query Analyzer is a graphical <strong>to</strong>ol that can be used <strong>to</strong> execute queries directlya gainst the database. It also has the functi<strong>on</strong>ality <strong>to</strong> debug query per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance problemssuch as Show Executi<strong>on</strong> Plan, Show <strong>Server</strong> Trace, Show Client Statistics and IndexTuning Wizard.An overview of Query Analyzer is available athttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/qryanlzr/qryanlzr_1zqq.asp.For an overview of some of the important features of query analyzer, refer <strong>to</strong>http://www.sql-server-per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.com/query_analyzer_tips.asp.Index Tuning WizardThe Index Tuning Wizard allows you <strong>to</strong> select and create an optimal set of indexes andstatistics based <strong>on</strong> input from Query Analyzer or a <strong>SQL</strong> Profiler log <str<strong>on</strong>g>for</str<strong>on</strong>g> a <strong>SQL</strong> <strong>Server</strong>database without requiring an expert understanding of the structure of the database, thew orkload, or the internals of <strong>SQL</strong> <strong>Server</strong>.For in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> the features and use of the Index Tuning Wizard, refer <strong>to</strong> "IndexTuning Wizard <str<strong>on</strong>g>for</str<strong>on</strong>g> Microsoft <strong>SQL</strong> <strong>Server</strong> 2000" athttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/itw<str<strong>on</strong>g>for</str<strong>on</strong>g>sql.asp.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 353Appendix C: BaseliningThis appendix is c<strong>on</strong>cerned with creating baselines, capturing statistics, and comparingand reporting results.Creating BaselinesB aselines are a collecti<strong>on</strong> of facts and figures that reflect the state of a system. Mostcomm<strong>on</strong>ly, the term baseline is used with respect <strong>to</strong> per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance. In the StabilizingPhase, this term is used <strong>to</strong> refer <strong>to</strong> a snapshot of the entire system specificati<strong>on</strong>.Unlike a new development pr oject where there is no reference point, the state of thecurrent soluti<strong>on</strong> can be captured in a migrati<strong>on</strong> project. This can be used as a baselinef or comparis<strong>on</strong> with the migrated soluti<strong>on</strong> being tested.After every successfulcycle of testing, it is recommended that all elements, such asscripts, applicati<strong>on</strong>s, applicati<strong>on</strong> c<strong>on</strong>figurati<strong>on</strong>, database c<strong>on</strong>figurati<strong>on</strong>, and databases,a re backed up and are baselined with appropriate tags <str<strong>on</strong>g>for</str<strong>on</strong>g> identificati<strong>on</strong>. Baselines fromeach cycle of testing can be compared with each other <strong>to</strong> see the progressi<strong>on</strong> <strong>to</strong>wards asoluti<strong>on</strong> that can be packaged <str<strong>on</strong>g>for</str<strong>on</strong>g> producti<strong>on</strong>.You should create a baseline during the Stabilizing Phase. These baseline values can beused later while troubleshooting per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance problems and also <str<strong>on</strong>g>for</str<strong>on</strong>g> proactive m<strong>on</strong>i<strong>to</strong>ring.The Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r, also known as System M<strong>on</strong>i<strong>to</strong>r <strong>to</strong>ol, can be used <strong>to</strong> m<strong>on</strong>i<strong>to</strong>rkey system resources (CPU, memory, Disk I/O, network, as well as <strong>SQL</strong> <strong>Server</strong>counters) while you run the Stabilizing Phase tests.The following tables (A.4 through A.8) list some of the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance m<strong>on</strong>i<strong>to</strong>r counters thatyou can use <str<strong>on</strong>g>for</str<strong>on</strong>g> creating a baseline. These counters can also be used <str<strong>on</strong>g>for</str<strong>on</strong>g> generalm<strong>on</strong>i<strong>to</strong>ring of the soluti<strong>on</strong> after deployment.Table A.4: Memory ManagementPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Descripti<strong>on</strong>M<strong>on</strong>i<strong>to</strong>r Counters\Memory\Available Available MBytes is the amount of physical memory availableMbytes<strong>to</strong> processes running <strong>on</strong> the computer, in Megabytes. Lack ofmemory puts pressure <strong>on</strong> the CPU and Disk I/O.\Memory\Pages/sec Pages/sec is the rate at which pages are read from or written<strong>to</strong> disk<strong>to</strong> resolve hard page faults. Hard page faults occurwhena process requires code or data that is not in its workingset or elsewhere in physical memory and must be retrievedfrom disk. Note that some paging will usually be presentbecause of the way the operating system works, but theoptimal level <str<strong>on</strong>g>for</str<strong>on</strong>g> averagepages/sec should be close <strong>to</strong> 0.


354 AppendicesTable A.5: <strong>Net</strong>work AnalysisPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Descripti<strong>on</strong>M<strong>on</strong>i<strong>to</strong>r Counters\<strong>Net</strong>work Interface Bytes Total/sec is the rate at which bytes are sent and(<strong>Net</strong>work card)\Bytes received over each network adapter, including framingTotal/seccharacters. Average value should be less than 50% of NICcapacity.\<strong>Net</strong>work Segment\ % The percentage of network bandwidth in use <strong>on</strong> a network<strong>Net</strong> Utilizati<strong>on</strong>segment. <strong>Net</strong>work M<strong>on</strong>i<strong>to</strong>r Driver can be installed and used <strong>to</strong>m<strong>on</strong>i<strong>to</strong>r the network utilizati<strong>on</strong>. The threshold value variesbased <strong>on</strong> the network c<strong>on</strong>figurati<strong>on</strong>.Table A.6: CPU M<strong>on</strong>i<strong>to</strong>ringPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>rCounters\Processor% ProcessorTime\Processor\% PrivilegedTime and \Processor\%User Time\System\C<strong>on</strong>textswitches/sec\System\Processor QueueLengthDescripti<strong>on</strong>This counter is the primary indica<strong>to</strong>r of processor activity,and it displays the average percentage of busy timeobserved during the sample interval. It is calculated bym<strong>on</strong>i<strong>to</strong>ring the time that the service is inactive andsubtracting that value from 100%.* Privileged Time is the percentage of elapsed time that theprocess threads spent executing code in privileged mode.Average values above 10% indicate possible CPU pressure.* User Time is the percentage of elapsed time the processorspends in the user mode.* Privileged Time should be about 15% less than the <strong>to</strong>talUser Time.This counter indicates the combined rate at which all theprocessors are switched from <strong>on</strong>e thread <strong>to</strong> another. Thepressure <strong>on</strong> memory can cause page faults, which cancause an increase in c<strong>on</strong>text switch/sec value, and adecrease in the overall per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.This counter indicates the number of threads in theprocessor queue. There is a single queue <str<strong>on</strong>g>for</str<strong>on</strong>g> processortime, even <strong>on</strong> computers with multiple processors. Asustained processor queue length of less than 10 threadsper processor is normally acceptable, dependent <strong>on</strong> theworkload. In other words, there are more threads ready <strong>to</strong>run than the current number of processors can service in anoptimal way.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 355Table A.7: Disk I/O M<strong>on</strong>i<strong>to</strong>ringPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>rCounters\PhysicalDisk\Avg. DiskQueue Length\PhysicalDisk\Current DiskQueue Length\PhysicalDisk\Avg. Disksec/Read\PhysicalDisk\Avg. Disksec/WriteDescripti<strong>on</strong>* Avg. Disk Queue Length is the average number ofrequests (both read and write) that were queued <str<strong>on</strong>g>for</str<strong>on</strong>g> theselected disk during the sample interval.* Current Disk Queue Length is the number of requestsoutstanding <strong>on</strong> the disk at the time the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance datais collected. These numbers should be less than two perusable physical disk in the RAID array, and may be higher<strong>on</strong> the SAN systems.Average time in sec<strong>on</strong>ds <strong>to</strong> read/write data <strong>to</strong> the disk.Table A.8: M<strong>on</strong>i<strong>to</strong>ring <strong>SQL</strong> <strong>Server</strong> M<strong>on</strong>i<strong>to</strong>ringPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>rCounters\<strong>SQL</strong><strong>Server</strong>:AccessMethods\Free SpaceScans/sec\<strong>SQL</strong><strong>Server</strong>:AccessMethods\Full Scans/sec\<strong>SQL</strong><strong>Server</strong>:Latches\TotalLatch Wait Time (ms)\<strong>SQL</strong><strong>Server</strong>:Locks(Total)\LockTimeouts/sec and Lock WaitTime (ms)\<strong>SQL</strong><strong>Server</strong>:Locks(Total)\Number of Deadlocks/sec\<strong>SQL</strong><strong>Server</strong>:Databases\Transacti<strong>on</strong>s/sec\<strong>SQL</strong><strong>Server</strong>:BufferManager\Buffer cache hit ratioDescripti<strong>on</strong>Number of scans initiated <strong>to</strong> search <str<strong>on</strong>g>for</str<strong>on</strong>g> free space <strong>to</strong>insert a new record fragment. Inserts <strong>on</strong> a heap withclustered index will impact per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance as against aheap with no clustered indexes.Tables with missing indexes, or when <strong>to</strong>o many rowsare requested, end up with unrestricted full scans of thebase table or indexes. This baseline counter can be anindica<strong>to</strong>r of an increase in the use of temporary tablesbecause they do not tend <strong>to</strong> have indexes.<strong>SQL</strong> <strong>Server</strong> uses latches <strong>to</strong> protect the integrity ofinternal structures. This counter m<strong>on</strong>i<strong>to</strong>rs the <strong>to</strong>tal waittime <str<strong>on</strong>g>for</str<strong>on</strong>g> latch requests that had <strong>to</strong> wait in the lastsec<strong>on</strong>d.Lock Timeouts counter indicates the number of lockrequests that timed out. This includes internal requests<str<strong>on</strong>g>for</str<strong>on</strong>g> NOWAIT locks. Lock Wait Time (ms) indicates the<strong>to</strong>tal wait time (in millisec<strong>on</strong>ds) <str<strong>on</strong>g>for</str<strong>on</strong>g> locks in the lastsec<strong>on</strong>d. Lock Timeouts should be low and Wait Timeshould be zero.Number of lock requests that resulted in a deadlock.Should be zero.Number of transacti<strong>on</strong>s started <str<strong>on</strong>g>for</str<strong>on</strong>g> the database. It is anexcellent indica<strong>to</strong>r of growth related <strong>to</strong> transacti<strong>on</strong> load.Percentage of pages that were found in the buffer poolwithout having <strong>to</strong> incur a read from disk. The higher thevalue of the buffer cache hit ratio the better. In atransacti<strong>on</strong> processing system where a set user base is


356 AppendicesPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>rCountersDescripti<strong>on</strong>operating against the database, this value may reach98-99 percent. If this value is small, then addingmemory <strong>to</strong> the <strong>SQL</strong> <strong>Server</strong> may help. This should belooked at with table scan frequency and might indicatethat indexes/partiti<strong>on</strong>ing would improve per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.\<strong>SQL</strong><strong>Server</strong>:<strong>SQL</strong> Recompilati<strong>on</strong> adds overhead <strong>on</strong> the processor.Statistics\<strong>SQL</strong> Re-Compilati<strong>on</strong>s/sec\<strong>SQL</strong><strong>Server</strong>:BatchRequests/sec and\<strong>SQL</strong><strong>Server</strong>:GeneralStatistics\User C<strong>on</strong>necti<strong>on</strong>s\<strong>SQL</strong><strong>Server</strong>:MemoryManager\Memory GrantsPending\<strong>SQL</strong><strong>Server</strong>:MemoryManager\Target <strong>Server</strong>Memory (KB)\<strong>SQL</strong><strong>Server</strong>:MemoryManager\Total <strong>Server</strong> Memory(KB)C<strong>on</strong>sistent high values <str<strong>on</strong>g>for</str<strong>on</strong>g> this counter should beinvestigated.These counters, al<strong>on</strong>g with Transacti<strong>on</strong>s/sec, are agood indica<strong>to</strong>r of load <strong>on</strong> the server.Current number of processes waiting <str<strong>on</strong>g>for</str<strong>on</strong>g> a workspacememory grant. This value should remain around 0.The <strong>to</strong>tal amount of dynamic memory the server iswilling <strong>to</strong> c<strong>on</strong>sume. On a dedicated server, this valueshould remain close <strong>to</strong> the actual physical memory size.The <strong>to</strong>tal amount of dynamic memory the server iscurrently c<strong>on</strong>suming. On a dedicated server, this valueshould remain close <strong>to</strong> the actual physical memory size.You must determine which server you will use <strong>to</strong> m<strong>on</strong>i<strong>to</strong>r <strong>SQL</strong> <strong>Server</strong>. If you runPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r <strong>on</strong> the same machine as the <strong>SQL</strong> <strong>Server</strong>, it should not add majoroverhead, except some disk I/O and disk space requirement <str<strong>on</strong>g>for</str<strong>on</strong>g> the per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance log files,depending <strong>on</strong> counters that you are m<strong>on</strong>i<strong>to</strong>ring and the interval. A large number ofcounters with a short sampling interval might require a lot of disk space; however, largerintervals will produce less accurate results. If you run Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r <strong>on</strong> a differentmachine, be aware that it might c<strong>on</strong>gest traffic <strong>on</strong> your network.For the purpose of creating the baseline, if you have disk space available <strong>on</strong> the <strong>SQL</strong><strong>Server</strong> machine, it is recommended you run the Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance M<strong>on</strong>i<strong>to</strong>r <strong>on</strong> the samemachine, add as many counters as desired, and use the short sampling interval. Onceyou have established the baseline, <str<strong>on</strong>g>for</str<strong>on</strong>g> proactive m<strong>on</strong>i<strong>to</strong>ring you can m<strong>on</strong>i<strong>to</strong>r just thecounters absolutely required and increase the interval. To create the baseline chart, follow these steps:1. Click Start, then All Programs, then Administrative Tools, and thenPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance.2. Expand Per<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Logs and Alerts node in the tree in the left pane.3. Right-click Counter Logs and select New Log Settings.4. Provide a name, click OK, add the counters, verify the details <strong>on</strong> the Log Filesand Schedule tab, and click OK.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 357Capturing StatisticsSome of the points <strong>to</strong> be c<strong>on</strong>sidered <str<strong>on</strong>g>for</str<strong>on</strong>g> capturing statistics are:●●●●Types of data. The type of data being captured — qualitative or quantitative.Characte ristic. The statistic must be relevant <strong>to</strong> the test being per<str<strong>on</strong>g>for</str<strong>on</strong>g>med. It mustsuit the comparis<strong>on</strong>s being made or analysis <strong>to</strong> be per<str<strong>on</strong>g>for</str<strong>on</strong>g>med. CPU usagemeasurement is an example of a statistic that is relevant <strong>to</strong> testing.Unit of measurement. The unit of measurement would be dependent <strong>on</strong> themagnitude of the measured characteristic. An example is measuring andcomparing memory: the unit <strong>to</strong> be used is bytes or Mbytes.Frequency. The frequency of measurement of a statistic can be a critical decisi<strong>on</strong>.Too much data can be cumbersome and <strong>to</strong>o little could be harmful.Some examples of resources <strong>on</strong> which statistics can be captured are:● Memory usage of the system● Memory usage of the database● CPU usage● Disk I/O rate● Number of user c<strong>on</strong>necti<strong>on</strong>s <strong>to</strong> the database● Procedure cache usage● Number of transacti<strong>on</strong>s executed per sec<strong>on</strong>d● Data cache usage● <strong>Net</strong>work bandwidth usageComparing and Reporting ResultsTest results have <strong>on</strong>ly as much value as the inferences that can be drawn from them.Test results can have either a qualitative value or a quantitative value. In a developmentproj ect, the expected behavior of the soluti<strong>on</strong> is based solely <strong>on</strong> business requirements.For a migrati<strong>on</strong>, measurements from the existing soluti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g>m the expected result.During the testing, the data from the migrated soluti<strong>on</strong> is compared with the expectedresults. Deviati<strong>on</strong>s from expected results cannot be c<strong>on</strong>strued as defects. As a result,analyzing and reporting results is a <strong>to</strong>pic of serious c<strong>on</strong>sequence. A thorough analysis ofthe results has <strong>to</strong> be made and c<strong>on</strong>clusi<strong>on</strong>s drawn based <strong>on</strong> several measurable andn<strong>on</strong>-measurable fac<strong>to</strong>rs (assumpti<strong>on</strong>s). The capabilities of the systems available <str<strong>on</strong>g>for</str<strong>on</strong>g>per<str<strong>on</strong>g>for</str<strong>on</strong>g>ming stabilizati<strong>on</strong> tests may be <strong>on</strong>e such fac<strong>to</strong>r.


358 AppendicesAppendix D: Installing Comm<strong>on</strong> Drivers andApplicati<strong>on</strong>sThis appendix c<strong>on</strong>tains installati<strong>on</strong> in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> FreeTDS, unixODBC, and ActiveStatePerl:● FreeTDS provides an implementati<strong>on</strong> of the Tabular Data Stream (TDS) pro<strong>to</strong>col,emulating the different versi<strong>on</strong>s of TDS that are used by <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong>.● unixODBC is an implementati<strong>on</strong> of the ODBC pro<strong>to</strong>col and API <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong>; theunixODBC library allows applicati<strong>on</strong>s r unning under <strong>UNIX</strong> <strong>to</strong> communicate withdatabase servers, such as <strong>SQL</strong> <strong>Server</strong>, usin g ODBC. Applicati<strong>on</strong>s developedusing unixODBC can execute under <strong>UNIX</strong> and SFU.● ActiveState Perl is the industry-standard Perl distributi<strong>on</strong>. This Perl distributi<strong>on</strong> canbe used from within the Window envir<strong>on</strong>ment.Installing FreeTDSA precompiled and directly installable versi<strong>on</strong> of FreeTDS (currently versi<strong>on</strong> 0.62.3) isavailable at http://interopsystems.com/<strong>to</strong>ols. This can be installed under SFU 3.5 usingthe pkg_add command. The package ca n be downloaded fromC<strong>on</strong>figuring FreeTDSWhen FreeTDS is installed, you should c<strong>on</strong>figure it <strong>to</strong> c<strong>on</strong>nect <strong>to</strong> your <strong>SQL</strong> <strong>Server</strong>databases using the following procedure: To c<strong>on</strong>figure FreeTDS c<strong>on</strong>nectivity, follow these steps:1. Move <strong>to</strong> the /usr/local/etc direc<strong>to</strong>ry and edit the freetds.c<strong>on</strong>f file. This file c<strong>on</strong>tainsin<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> about the Sybase and <strong>SQL</strong> <strong>Server</strong> database servers it can access andthe versi<strong>on</strong>s of T DS <strong>to</strong> use.2. Add the following entries <strong>to</strong> the end of the file. Replace aa. aa.aa.aa with the IPaddress or DNS name of the <strong>UNIX</strong> computer running <strong>SQL</strong> <strong>Server</strong> (DNS name isrecommended), and bbbb with the port that <strong>SQL</strong> <strong>Server</strong> is listening <strong>to</strong> <strong>on</strong> thiscomputer (<strong>SQL</strong> <strong>Server</strong> usually listens <strong>on</strong> port 1433) .[<strong>SQL</strong><strong>Server</strong>]host = servernameport = bbbbtds versi<strong>on</strong> = 8.0Note The name, <strong>SQL</strong><strong>Server</strong>, does not have <strong>to</strong> be the same as the name of thecomputer running <strong>SQL</strong> <strong>Server</strong> — it is an identifier used by the FreeTDS libraryfuncti<strong>on</strong>s <strong>to</strong> locate the entry in this file. It is a name that uniquely identifies thisentry in the c<strong>on</strong>figurati<strong>on</strong> file, and is used wi th the -S opti<strong>on</strong> <str<strong>on</strong>g>for</str<strong>on</strong>g> most of the scripts.3. Save the file.Testing the FreeTDS C<strong>on</strong>figurati<strong>on</strong>You can test the FreeTDS c<strong>on</strong>figurati<strong>on</strong> using tsql, a <strong>to</strong>ol provided with FreeTDS, byfollowing this procedure:


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 359 To test the installati<strong>on</strong> of FreeTDS, follow these steps:1. At a shell prompt, type the following command. Replace server with the entry infreetds.c<strong>on</strong>f that you want <strong>to</strong> test (<strong>SQL</strong><strong>Server</strong>), and password with the sa password<str<strong>on</strong>g>for</str<strong>on</strong>g> the selected server:–U sa –P passwordWindows NT Authenticati<strong>on</strong>, called "integrated security," is not supported byFreeTDS.2. At the 1> prompt, type the following commands. The result should be a list ofdatabases available <strong>on</strong> the selected server:SELECT name FROM sysdatabases4.tsql –S serverGo3. At the 1> prompt, type the following commands. The result should be a list ofc<strong>on</strong>necti<strong>on</strong>s currently established <strong>to</strong> the selected server:EXEC sp_whoGoAt the 1> prompt, type the following command <strong>to</strong> leave tsql.exitInstalling unixODBCunixODBC is available in source <str<strong>on</strong>g>for</str<strong>on</strong>g>m (in the file unixODBC-2.2.6.tar.gz) from theunixODBC Web site at http://www.unixodbc.com. This guide uses unixODBC versi<strong>on</strong>2.2.6. The procedures assume you have already downloaded the file unixODBC-2.2.6.tar.gz. To install unixODBC in <strong>UNIX</strong>, follow these steps:1. Log in <strong>to</strong> <strong>UNIX</strong> as the root user.2. At a shell prompt, access the direc<strong>to</strong>ry where the downloaded unixODBC sourcecode is located (default/usr/local/unixODBC), and then type the following command<strong>to</strong> unzip the file unixODBC-2.2.6.tar.gz <strong>to</strong> the file unixODBC-2.2.6.tar.gunzip unixODBC-2.2.6.tar.gz3. Type the following command <strong>to</strong> unpack the file unixODBC-2.2.6.tar in<strong>to</strong> thedirec<strong>to</strong>ry unixODBC-2.2.6:tar xvf unixODBC-2.2.6.tar4. Move <strong>to</strong> the unixODBC-2.2.6 direc<strong>to</strong>ry and type the following command <strong>to</strong>generate the files needed <strong>to</strong> build unixODBC. This command will generate anumber of messages <strong>on</strong> the screen as it examines your <strong>UNIX</strong> c<strong>on</strong>figurati<strong>on</strong> andgenerates the appropriate make files../c<strong>on</strong>figureNote The c<strong>on</strong>figure script uses a number of well-known tricks <strong>to</strong> ascertain which<strong>to</strong>ols and libraries are available that it can use <strong>to</strong> compile unixODBC. If thec<strong>on</strong>figure script fails, it is usually because the script cannot find a particular <strong>to</strong>ol,file, or library. You can run the script supplying parameters <strong>to</strong> help it analyze yourenvir<strong>on</strong>ment. Execute ./c<strong>on</strong>figure -h <str<strong>on</strong>g>for</str<strong>on</strong>g> more details.5. Type the following command <strong>to</strong> build unixODBC. As be<str<strong>on</strong>g>for</str<strong>on</strong>g>e, you will see a largenumber of messages as the build process progresses:make6. Type the following command <strong>to</strong> install unixODBC:make install


360 Appendices7. Type the following command <strong>to</strong> check that unixODBC was installed successfully:/usr/local/bin/isqlIf unixODBC is installed correctly, you will see the following message:*********************************************** unixODBC - isql************************************************ Syntax**** isql DSN [UID [PWD]] [opti<strong>on</strong>s] ** ** Opti<strong>on</strong>s *** -b batch.(no prompting etc)*** -dx delimit columns with x ** -x0xXX delimit columns with XX, where *** -wx is in hex, ie 0x09 is tabwrap results in an HTML table*** -c column names <strong>on</strong> first row. ** (<strong>on</strong>ly used when -d) ** -mn limit column display width <strong>to</strong> n ** -v verbose. ** --versi<strong>on</strong> versi<strong>on</strong> ** ** Notes** isql supports redirecti<strong>on</strong> and piping**** <str<strong>on</strong>g>for</str<strong>on</strong>g>*batch processing. *** Examples **** cat My.sql | isql WebDB MyID MyPWD -w ** ** Each line in My.sql must c<strong>on</strong>tain ** exactly 1 <strong>SQL</strong> command except <str<strong>on</strong>g>for</str<strong>on</strong>g> the ** last line which must be blank. ** ** Please visit; ** ** http://www.unixodbc.org ** pharvey@codebydesign.com ** nick@easysoft.com ***********************************************Installing ActiveState PerlActiveState Perl can be downloaded from the ActiveState Web site athttp://www.activestate.com. ActiveState Perl is available in prebuilt binary <str<strong>on</strong>g>for</str<strong>on</strong>g>m <str<strong>on</strong>g>for</str<strong>on</strong>g> Linux,Solaris, and Windows, but the source code is also available and can be used <strong>to</strong> buildActiveState Perl <strong>on</strong> other <strong>UNIX</strong> plat<str<strong>on</strong>g>for</str<strong>on</strong>g>ms.


<str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> <str<strong>on</strong>g>for</str<strong>on</strong>g> <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>on</strong> <strong>UNIX</strong> <strong>to</strong> <strong>SQL</strong> <strong>Server</strong> <strong>on</strong> Windows 361This secti<strong>on</strong> describes how <strong>to</strong> install ActiveState Perl using the prebuilt Microsoft Installer(MSI) package ActivePerl-5.6.1.635-MSWin32-x86.msi. To install ActiveState Perl under Windows, follow these steps:1. Execute the file ActivePerl-5.6.1.635-MSWin32-x86.msi. Windows Installer startsthe installati<strong>on</strong>.2. In the ActivePerl 5.6.1 Build 635 Setup screen, click Next.3. In the ActivePerl 5.6.1 Build 635 License Agreement screen, select I accept theterms in the License Agreement and click Next.4. In the Cus<strong>to</strong>m Setup screen, make sure all features are selected <strong>to</strong> be installed(the default) and click Next.5. In the New features in PPM screen, clear the checkbox <str<strong>on</strong>g>for</str<strong>on</strong>g> Enable PPM3 <strong>to</strong> sendprofile info <strong>to</strong> ASPN and click Next.6. In the Choose Setup Opti<strong>on</strong>s screen, check all four opti<strong>on</strong>s and click Next.7. In the Ready <strong>to</strong> Install screen, click Install. The Installing ActivePerl 5.6.1 Build635 screen will appear and indicate the progress of the installati<strong>on</strong> process.8. In the Completing the ActivePerl 5.6.1 Build 635 Setup Wizard screen, removethe check mark from Display the release notes and click Finish.


362 AppendicesAppendix E: Reference ResourcesFor detailed discussi<strong>on</strong> of the c<strong>on</strong>cepts and practices presented in this guide, you shouldrefer <strong>to</strong> the following resources.● For additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> migrati<strong>on</strong>, refer <strong>to</strong> the <strong>UNIX</strong> Migrati<strong>on</strong> Project <str<strong>on</strong>g>Guide</str<strong>on</strong>g>(UMPG) atHTUhttp://www.microsoft.com/technet/itsoluti<strong>on</strong>s/migrati<strong>on</strong>/unix/umpg/default.mspxUTH.● Details about Windows Services <str<strong>on</strong>g>for</str<strong>on</strong>g> <strong>UNIX</strong> (SFU) are available atHTUhttp://www.microsoft.com/windows/sfu/productinfo/overview/default.aspUTH.● Microsoft <str<strong>on</strong>g>Soluti<strong>on</strong></str<strong>on</strong>g>s Framework (MSF) models and disciplines are available atHTUhttp://www.microsoft.com/msfUTH.● For guidance <strong>on</strong> the structure of operati<strong>on</strong>s, refer the Microsoft Operati<strong>on</strong>sFramework (MOF) available at HTUhttp://www.microsoft.com/mofUTH.● For additi<strong>on</strong>al in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong> <strong>on</strong> migrating <strong>UNIX</strong> applicati<strong>on</strong>s <strong>to</strong> Microsoft Windows,see the <strong>UNIX</strong> Applicati<strong>on</strong> Migrati<strong>on</strong> <str<strong>on</strong>g>Guide</str<strong>on</strong>g> atHTUhttp://go.microsoft.com/fwlink/?LinkId=30832UTH●●●Specific guidance <strong>on</strong> the Microsoft Operati<strong>on</strong>s Framework (MOF) quadrants isavailable in the "Process Model <str<strong>on</strong>g>for</str<strong>on</strong>g> Operati<strong>on</strong>s" white paper atHTUhttp://www.microsoft.com/technet/itsoluti<strong>on</strong>s/techguide/mof/mofpm.mspxUTH.For specific guidance <strong>on</strong> operating the soluti<strong>on</strong>, download the <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> HighPer<str<strong>on</strong>g>for</str<strong>on</strong>g>mance Computing (HPC) Applicati<strong>on</strong>s from <strong>UNIX</strong> <strong>to</strong> Windows guide atHTUhttp://go.microsoft.com/fwlink/?LinkID=23112UTH.For m<strong>on</strong>i<strong>to</strong>ring the deployed soluti<strong>on</strong>, refer <strong>to</strong>HTUhttp://www.microsoft.com/business/reducecosts/efficiency/manageability/default.mspxUTH.● For best practices regarding m<strong>on</strong>i<strong>to</strong>ring, refer <strong>to</strong>HTUhttp://www.microsoft.com/business/reducecosts/efficiency/manageability/bestpractices.mspxUTH.● For planning a <strong>SQL</strong> <strong>Server</strong> 2000 installati<strong>on</strong>, refer <strong>to</strong> the Microsoft Web site atHTUhttp://www.microsoft.com/sql/techinfo/planning/default.aspUTH.● For programming <strong>SQL</strong> <strong>Server</strong> 2000, refer the developer <strong>to</strong>pics atHTUhttp://www.microsoft.com/sql/techinfo/development/2000/default.aspUTH.● <strong>SQL</strong> <strong>Server</strong> Books Online is available at HTUhttp://msdn.microsoft.com/library/enus/startsql/getstart_4fht.aspUTH.● For <strong>SQL</strong> <strong>Server</strong> 2000 Resource Kit in<str<strong>on</strong>g>for</str<strong>on</strong>g>mati<strong>on</strong>, refer the Microsoft Web site atHTUhttp://www.microsoft.com/sql/techinfo/reskit/default.aspUTH.● For managing and maintaining <strong>SQL</strong> <strong>Server</strong> 2000, refer the <strong>SQL</strong> <strong>Server</strong> 2000Operati<strong>on</strong>s <str<strong>on</strong>g>Guide</str<strong>on</strong>g> atHTUhttp://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/sql/maintain/operate/opsguide/default.aspUTH.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!