Query DIFF Utility Comparing the data In 2 tables (or queries) -- show the differences -- MDCFUG December 10, 2002 Joan Falcão

Slides:



Advertisements
Similar presentations
CC SQL Utilities.
Advertisements

With Microsoft Access 2010© 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access.
Introduction to Structured Query Language (SQL)
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Week 5 IBS 520. ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own.
Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Introduction to Structured Query Language (SQL)
Access Lecture 1 Database Overview and Creating Tables Create an Employee Table.
15. User Authentication, Form Validation, Paging. M. Udin Harun Al Rasyid, S.Kom, Ph.D
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
MySql In Action Step by step method to create your own database.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL.
With Microsoft Access 2007 Volume 1© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access 2007 Volume 1 Chapter.
Database testing Prepared by Saurabh sinha. Database testing mainly focus on: Data integrity test Data integrity test Stored procedures test Stored procedures.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Analyzing Data For Effective Decision Making Chapter 3.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Module 9 Designing and Implementing Stored Procedures.
Programming using C# Joins SQL Injection Stored Procedures
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Using Client-Side Scripts to Enhance Web Applications 1.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Introduction to Exception Handling and Defensive Programming.
Improving Database Performance Derrick Rapley
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Data Driven Designs 99% of enterprise applications operate on database data or at least interface databases. Most common DBMS are Microsoft SQL Server,
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Database Basics BCIS 3680 Enterprise Programming.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Visual Basic for Application - Microsoft Access 2003 Finishing the application.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Stored Procedures / Session 4/ 1 of 41 Session 4 Module 7: Introducing stored procedures Module 8: More about stored procedures.
IT420: Database Management and Organization Triggers and Stored Procedures 24 February 2006 Adina Crăiniceanu
Thinking in Sets and SQL Query Logical Processing.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 CONACT UC:  Magnific training   
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
Databases & SQL Basics Kurtis D. Leatham
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
Dynamic SQL: Writing Efficient Queries on the Fly
Database Systems: Design, Implementation, and Management Tenth Edition
PHP: Security issues FdSc Module 109 Server side scripting and
Dynamic SQL: Writing Efficient Queries on the Fly
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Presentation transcript:

Query DIFF Utility Comparing the data In 2 tables (or queries) -- show the differences -- MDCFUG December 10, 2002 Joan Falcão

“Why would you want to do that?” Specifically – verify that data transferred from one system to another is identical before deleting it at the source. Generally – have a quality-assurance tool to analyze data differences: Verify expected matches Report on expected differences Identify surprise differences and matches

Applications Find Differences in 2 similar tables See how a table has changed over the week QA for data entry effort (before and after) Verify expected changes due to code mods Compare the column names from MS-SQL and Oracle schemas Or compare length of text columns Analyze whether duplicate keys are duplicate rows (heavy hand on the “submit” button?) See the results of modifying a query Inner join vs outer join Null predicate

More Applications: QA for Ported Systems or Regression Testing data conversion routine old system update new system update updated ported dbms data conversion routine updated dbms ported dbms ported updated dbms Difference?

Reinventing the wheel? Cf_Venn: Remember Venn diagrams from school? This Custom Tag compares two lists, performing any or all of these operations: Union, Intersection, and Differences. TDataSourceCompare: Compares all tables, columns, datatypes of 2 MS SQL database objects that are registered as datasources on your server. Used for checking your Production database and Development database to make sure your columns all match before a critical launch. DB1 First Datasource name. DB2 Second Datasource name. CF_List_Compare is a custom tag that will compare the values of two given lists (List 1, and List 2)

Reinventing the wheel? August 7, 2002 SQL Script for Comparing the Contents of Two Tables Here's some SQL code from Eli Leiba that will all you to compare two tables -- say, table A and table B -- to determine if their content is the same. Assuming that A and B have the same structure, here's how it works. First, from set theory, recall that:Eli Leiba If ((|A| = |B|) && |A U B| = |A|)) ====>>> A = B |A| = NUMBER of rows in A |B| = NUMBER of rows in B

Reinventing the wheel? (continued) Here's the SQL code (with T-SQL syntax): int int int bit = count(*) from A = count(*) from B = count('x') from (select * from A UNION select * from B) as t if and begin = 1 print 'A = B' end else begin = 0 print 'A <> B' end go

Previous implementation – UNION/JOIN query in Access Query is messy: query for each column name query for extra rows in each of the 2 tables extra predicates for nulls extra predicates to flag duplicate rows (should table not have a primary key) Access permits union across dissimilar columns (different data types) Access DOES permit inner join and union across linked tables from different DBMS, but I have not tested this.

Previous implementation – UNIVAC’s Symbolic Stream Generator Generates source code (to be compiled and executed) according to parameters Old technology (no longer available) Required a lot of parameters One spec per column (location and type) Compared 2 files – very limited A query is much more flexible

General ColdFusion Approach Define 2 queries With the same column names rename with AS, if needed With a common key (possibly multi-column) Sort on the common key Merge queries on the common key Report extra keys Report data differences when keys match Feedback for user Column names Notification of errors

Parameters in General-Purpose Differencing In a FORM, prompt for: Datasource Table specification (query) Key specification Sort order Login parameters (username/password)

Demos

Challenges in General-Purpose Programming Column name(s) not known for SELECT * Number of columns not known Number of key columns not known Column name syntax in ORDER BY clause differs across databases

ColdFusion essential features CFQUERY’s returned variable: queryname.ColumnList ListGetAt(ISQLquery1.ColumnList,ii) CFQUERY column indexing: queryname.columnname[index] Evalute function: Evaluate(‘queryname.columnname’) Evaluate("ISQLquery1."&ListGetAt(ISQLquery1,ii)&"["&q1&"]")

Unexpected problems False matches SQL Case-sensitive vs CF case-insensitive ColdFusion null same as empty string (unless query uses COALESCE to give a value to nulls) False differences Extra rows on both sides (“ships passing in the night”) Trailing blanks (do not count in SQL, do in CF) Sort sequences differ Across database products Across database configurations of same product ColdFusion has its own sort sequence SQL query special characters hard to store need URLEncodedFormat

More Demos

Workarounds to sort problems Sort by UPPER(columnname) Replace known special characters with something that sorts the same UPPER(REPLACE(columnname,’_’,’ ’)) ReSort in ColdFusion, via CF5 query-on-query

Additional Problems In CFFORM my own javascript inadvertantly disables CFINPUT validation onSubmit="return SubmitDiffForm(_CF_this);“ Column names with special characters won’t “evaluate” (I warn and abort) My javascript function to uppercase character sort columns was too confusing (now disabled)

Additional Implementation Notes To limit extraneous white space (lots of it) Hidden radio button trick – form variable is always present and has values "Y,N“ or “N” thisTag.generatedContent gives “playback” Empty username/password attributes mean “use defaults” (instead of ODBC error) PreserveSingleQuotes needed in CFQUERY Sandbox security may limit DIFFing Written/tested in CF 4.5; enhanced with optional CF5 features

Security concerns This utility must be protected; Otherwise, it’s a hacker’s dream NOTE: I use a session variable to hold a login Security can be disabled (in application.cfm, set BypassSecurity=“Yes”) OK, iff protection already exists Security must be configured Use an existing username/password to login Avoids password management Provide parameters in LoginParam.cfm Database passwords for queries are omitted in stored DIFF specification

Feature Creep ( extra funcionality ) Javascript function cascades merge key to sort key input boxes ( less data entry ) Option to save entire DIFF specification in a file Batch execution ( can be scheduled in CF admin ) the differences report Resort ( CF5 query-on-query ) to avoid sort sequence variance

Future Enhancements? Case-sensitive search Parameters to limit output Numeric tolerances in a match Encrypted passwords for datasources CfScript to speed it up