A Database Reverse Engineering Case Study: DAMA Chicago Aug 17, 2016
A Database Reverse Engineering Case Study: DAMA Chicago Aug 17, 2016
A Database Reverse Engineering Case Study: DAMA Chicago Aug 17, 2016
A Database Reverse
Engineering Case Study
wp_fqir_links 0
wp_fqir_options 359
wp_fqir_postmeta 656
wp_fqir_posts 406
wp_fqir_term_relationships 59
wp_fqir_term_taxonomy 15
wp_fqir_termmeta 0
wp_fqir_terms 15
wp_fqir_usermeta 47
wp_fqir_users 1
Manually Add FKs
Look for name similarity
Verify with data analysis
SELECT * FROM wp_fqir_commentmeta
WHERE comment_ID NOT IN
(SELECT comment_ID FROM wp_fqir_comments);
-- 0 records
SELECT * FROM wp_fqir_commentmeta
WHERE comment_ID IS NULL;
-- 0 records
DBRE ERwin Model
wp_fqir_commentmeta wp_fqir_comments wp_fqir_posts w p_fqir_postmeta
meta_id comment_ID ID meta_id
comment_ID (FK) comment_post_ID (FK) post_author post_ID (FK)
meta_key comment_author post_date meta_key
meta_value comment_author_email post_date_gmt meta_value
comment_author_url post_content
comment_author_IP post_title
comment_date post_excerpt
comment_date_gmt post_status
comment_content comment_status
comment_karma ping_status
comment_approved post_password
comment_agent post_name
comment_type to_ping
comment_parent pinged
user_id post_modified
post_modified_gmt
post_content_filtered
post_parent (FK)
guid
menu_order
post_type
post_mime_type
comment_count
HumanResources.Department 16 Person.ContactType 20
Purchasing.ShipMethod 5 Sales.SalesReason 10
Sales.SalesOrderDetail 121317
Processing Details
1. Import schema into ER/Studio
File / New / Reverse engineer AdventureWorks2012
All owners, user tables, no inferences
Add FK Production.WorkOrderRouting.ProductID ->
Production.Product.ProductID
2. Successively delete all entity types with 0,1
connections
3. Delete entity types with few (<= 3) connections
Step 1: ER/Studio Model
Data ba se L og
Da tab as e Lo gID
AW Bu ild Vers io n
Po s tT i m e
Sy s tem Info rm at io nID
Da tab as e Us er
Da ta ba s e Vers io n Ev e nt
Ve rs i o nDate Sc h em a
Shift
M od i fi ed Da te Ob j ec t
Sh i ftID
TSQL
Na m e Xm l Ev en t
Sta rtT i m e
En d Ti m e
M o di fi ed Date
Erro rL og T ran sa c tio n Histo ryArch ive
ErrorL og ID T ra n s a c ti o nID
Na m e M o di fi ed Da te Em ai l Pro m o tio n
Pu rch as e Ord erDeta il
Ad di ti on a lCo nta c tInfo Con tac tTy p e
M o di fi ed Da te
Pu rc ha s eOrde rID (FK)
De m o gra ph i c s Co n tac tT y pe ID
Pu rc ha s eOrde rDetai l ID ro wgu i d
Store Na m e
Du eDa te M o di fi ed Da te
Bu s i ne s s En tit y ID (F K) M o d ifi ed Date
Orde rQty Cu stom e r
Ve n do r
Tra ns ac tion His tory Prod uc tID (F K) Na m e Cu s tom erID
Bu s i ne s s En ti ty I D (FK)
T ran s a c ti o nID Un itPri c e Sa l e s Pers on ID (FK)
Pe rs on ID (F K)
L i ne To ta l Ac c o u ntNu m b er De m og ra p hi c s
Prod uc tID (FK) Store ID (FK)
Re c e iv e dQty Na m e rowg ui d
Refe re n c e Ord e rID T e rri tory ID (FK) Sa le sT a xRa te
Re je c t ed Qty Cred i tRa tin g M o d ifi ed Date
Refe re n c e Ord e rL i ne ID Ac c o un tNu m b er
Stoc k e d Qty Prefe rred Ve nd orStatu s Sa l e s T ax Ra te ID
T ran s a c ti o nDa te ro wg ui d
M od i fi ed Da te Ac ti v e Fl ag
T ran s a c ti o nT y pe M od i fi e dDa te Sta teProv i nc e ID (F K)
Pu rc ha s i ng We b Se rv i c e URL Sa le sT e rrito ry
Qua nti ty Ta x Ty pe
M od i fi ed Da te
Te rrito ry ID Ta x Ra te
Ac tu al Cos t
Bus ine ss EntityCon tac t Na m e
M od ifi e dDa te Na m e
Bus i ne s s Enti ty ID (F K) rowg ui d
Prod uc tVen do r Co u ntry Re gi on Cod e (F K)
Pro d uc t Pers on ID (FK) M o d ifi ed Date
Prod uc tID (F K) Gro up
Pro du c tID Con tac tT y pe ID (FK)
Bu s i ne s s En ti ty ID (F K) Sa l es YT D
Sh ipM etho d
Sa l es La s tYe ar rowg ui d
Na m e
Av erag e Le a dT im e Shi p M e tho dID
Sho pp ing CartIte m Pro du c tNum be r Co s tYTD M o d ifi ed Date
Stan da rdPri c e Co s tL as tYea r
Sh o pp in g Ca rtIte m ID M a k e Fl a g Nam e
L a s tRe c ei p tCo s t rowgu i d
Fi n i s h ed Go o ds Fl a g Shi p Ba s e Cou ntry Re g io n
Sh o pp in g Ca rtID L a s tRe c ei p tDa te Bu sine s sEn tity M o di fi ed Date
Co l or Shi p Ra te
M i nOrd e rQty Co u ntry Re gi on Cod e
Qu a nti ty Sa fety Sto c k Le v el ro wg ui d Bus i ne s s Enti ty ID
Pro du c tID (F K) M ax Ord erQty
Re o rd erPoi n t M od ifi e dDa te Na m e
On Orde rQty ro wg ui d
Da teCrea ted M o d ifi ed Date
Sta nd ard Co s t M od ifi e dDa te
M o di fi ed Da te Un itM e a s u reCod e (F K)
Li s tPri c e
M od i fi e dDa te
Si z e Sa le sOrde rHea de r
Si z eUni tM e a s u reCod e (F K) Sal e s Ord e rID
We i gh tUn itM ea s u reCo de (FK)
Rev i s i on Num be r
We i gh t
Da y s T oM an ufa c tu re Sa les Ord e rDeta il Ord e rDate
Pe rs on Cre d itCard
Pro du ctPho to Pro du c tL i ne Due Da te Co u ntryRe gion Curre nc y
Sa l es Ord erID (F K)
Shi p Da te Bus i ne s s Enti ty ID (F K)
Prod uc tPho toID Cl a s s Co un try Re g i on Co de (FK)
Sa l es Ord erDeta i lID Cre d itCard ID (F K)
Sta tus
Sty l e Cu rre nc y Co de (F K)
T h um b Nai l Pho to
Pro du c tSub c ate go ry ID (F K) Ca rri e rTrac k i ng Nu m b e r Onl i ne Ord e rF l ag
M o d ifi e dDate
T h um b n ai l Pho to F i le Nam e Ord erQty Sal e s Ord e rNu m b er M od i fi e dDa te
Pro du c tM od el ID (F K)
L a rg ePh oto Pro du c tID (F K) Purc ha s e Ord e rNum b er
Se l l StartDate
L a rg ePh oto Fi l eNa m e Sp ec i al Offe rID (FK) Ac c ou ntNu m b er
Se l l En dDate
M od i fi ed Da te
Di s c o nti n ue dDa te Un i tPri c e Cus tom e rID (F K)
Cred itCa rd
ro wgu i d Un i tPri c e Di s c o u nt Sal e s Pers on ID (FK)
Cred itCard ID
L i n eT ota l T erri to ry ID (F K)
M o di fi ed Da te
ro wgu i d Bil l T oAdd res s ID (F K) Card Ty pe Curren c y
M o di fi ed Da te Shi p To Ad d re s s ID (F K) Card Nu m b e r Cu rre n c y Co d e
Shi p M eth o dID (F K) Ex p M o nth
Pro d uc tPro du ctPho to
Pro du ctM od elIllus tra tion Cre d itCard ID (FK) Ex p Ye a r Na m e
Pro d uc tID (F K) Cre d itCard Ap p ro v a l Cod e M o di fi ed Da te
Pro d uc tM o de l ID (FK) M od ifi e dDa te
Pro d uc tPh otoI D (FK)
Sp ec ia lOffe rProd u ct Il lu s tra tio n ID (FK) Curren c y Rate ID (FK)
M o di fi ed Da te
Step 2: ER/Studio Model
Person
rowguid Title
ModifiedDate FirstName
MiddleName
Employee LastName
BusinessEntityID (FK) Suffix
EmailPromotion
NationalIDNumber C ount ryRegionC urrency
ProductVendor AdditionalContactInfo
LoginID Demographics CountryRegionCode (FK)
Produc tID ( FK) OrganizationNode rowguid CurrencyCode (FK)
BusinessEntityID ( FK) Vendor OrganizationLevel
UnitMeasure ModifiedDate
JobTitle ModifiedDate
UnitMeasureCode Av erageLeadTime BusinessEntityID (FK)
BirthDate
Standar dPr ice
BillOfMaterials Name AccountNumber MaritalStatus
LastReceiptCost
ModifiedDate Name Gender
BillOfMaterialsID LastReceiptDate
CreditRating HireDate PersonCreditCard
MinOrderQty Currency
ProductAssembly ID ( FK) PreferredVendorStatus SalariedFlag
MaxOrderQty BusinessEntityID (FK)
ComponentID (FK) ShipMethod CurrencyCode
ActiveFlag VacationHours CreditCardID (FK)
OnOrderQty
StartDate PurchasingWebServiceURL ShipMethodID SickLeaveHours
U nitMeasureC ode ( FK) C urrencyRate Name
EndDate ModifiedDate CurrentFlag ModifiedDate
ModifiedD ate PurchaseOrderDetail Name ModifiedD ate
UnitMeasureCode ( FK) rowguid CurrencyRateID
Purchas eOr der ID (FK) ShipBase
BOMLevel ModifiedDate
Purchas eOr der DetailID ShipRate CurrencyRateDate
PerAssemblyQty
rowguid FromCurrencyCode (FK)
ModifiedDate D ueDate
ModifiedDate ToCurrencyCode (FK)
OrderQty
AverageRate
ProductID ( FK)
PurchaseOrderHeader BusinessEntity BusinessEntityAddress EndOfDayRate
U nitPrice
ProductInventory BusinessEntityID BusinessEntityID (FK) ModifiedDate
LineTotal PurchaseOrderID
ProductID (FK) AddressID (FK)
R eceivedQty rowguid CreditCard
RevisionNumber
LocationID (FK) R ejectedQty
Status ModifiedDate CreditCardID rowguid
Shelf StockedQty ModifiedDate
EmployeeID (FK)
ModifiedD ate CardType
Bin VendorID (FK)
CardNumber
Quantity ShipMethodID (FK)
ExpMonth
r owguid OrderDate
ExpYear
ModifiedDate ShipDate
ModifiedDate
SubTotal A ddress
Product TaxAmt
AddressID
ProductID Freight
TotalDue AddressLine1
Location Name
ModifiedDate AddressLine2
ProductNumber SalesPerson
LocationID City Customer
MakeFlag
BusinessEntityID (FK) StateProvinceID (FK)
Name FinishedGoodsFlag CustomerID
PostalCode
CostRate Color TerritoryID (FK)
SpatialLocation PersonID (FK)
Availability SafetyStockLevel Document SalesQuota
rowguid StoreID (FK)
ModifiedDate ReorderPoint DocumentNode Bonus
ModifiedDate Terr itoryID (FK)
StandardC ost CommissionPct
DocumentLevel AccountNumber
WorkOrderRouting ListPrice SalesYTD
Title r owguid
WorkOrderID (FK) Size SalesLastYear
Owner (FK) ModifiedDate
ProductID (FK) SizeUnitMeasur eC ode (FK) rowguid
FolderFlag
WeightUnitMeasureCode (FK) ModifiedDate
OperationSequence FileName
Weight Stat eProvince
LocationID (FK) FileExtension
DaysToManufacture StateProvinceID
ScheduledStartDate Revision Store
WorkOrder ProductLine
ScheduledEndDate ChangeNumber StateProvinceC ode
Class BusinessEntityID (FK)
ActualStartDate WorkOrderID Status CountryR egionCode (FK)
Style
ActualEndDate DocumentSummary Name IsOnlyStateProvinceFlag
ProductID (FK) SellStartDate
ActualResourceHrs Document SalesPersonID (FK) Name
OrderQty SellEndDate
PlannedCost ProductDocument rowguid Demographics Terr itoryID (FK)
StockedQty DiscontinuedDate
ActualCost ModifiedDate rowguid row guid
ScrappedQty rowguid ProductID (FK)
ModifiedDate DocumentNode (FK) ModifiedDate ModifiedD ate
StartDate ModifiedDate
EndDate ModifiedDate
DueDate SalesOrderDetail
ModifiedDate
SalesOrderID (FK)
SalesOrderDetailID SalesOrderHeader
SalesOrderID CountryRegion
CarrierTrackingNumber
OrderQty RevisionNumber CountryRegionCode
SpecialOfferProduct ProductID (FK) OrderDate
Name
UnitPrice DueDate
ProductID (FK) ModifiedDate
UnitPriceDiscount ShipDate
rowguid LineTotal Status
ModifiedDate rowguid OnlineOrderFlag
ModifiedDate SalesOrderNumber
PurchaseOrderNumber SalesTerrit ory
AccountNumber Terr itoryID
CustomerID (FK)
SalesPersonID (FK) N ame
HumanResources.Department 16 Person.ContactType 20
Purchasing.ShipMethod 5 Sales.SalesReason 10
Sales.SalesOrderDetail 121317
Commentary
DBRE depends on having FKs
The 0,1 connection deletions lose little info
The few connections deletions are speculative
Customer
CustomerID
PersonID (FK)
StoreID (FK)
SalesPerson
BusinessEntityID (FK)
Case Study 3:
Core DBRE
Rationale
A project building a very large data warehouse
100 facts
200 dimensions
The primary operational feeder application has
8500 tables
I was new to the project and there was a lot to
learn
I wanted to reverse engineer the feeder
application so that I could understand it
Available Inputs
We had the following inputs (paper printouts) for
the feeder application
A thorough data dictionary
Primary key definitions
Foreign key definitions
The DBRE Problem
Reverse engineer a database with 8500 tables
With smaller schema, we could type the database
structure into a modeling tool and then analyze it
However, 8500 tables would take too long
We decided to determine the tightly connected
tables and hope that would yield a much smaller
model
We presume that the tightly connected tables are the
most important ones
DBRE Approach
Do a graph analysis
Create a meta-table with FK to PK references
The FK in the source table points to the PK in the
target table
Using SQL, successively delete tables with 0,1
FK connections
The final result is the multiply connected tables
Example
TableReferences
sourceTable targetTable
A B TableReferences
B A
D C sourceTable targetTable
E C A B
E D B A
G B D C
H A E C
F G E D
I G G B
H A B G I A B G
C F C
E D E D
Example
TableReferences
TableReferences
sourceTable targetTable
sourceTable targetTable
A B
B A A B
D C B A
E C D C
E D E C
G B E D
A B G C
A B
C E D
E D
FinancialScenario
DBRE and Zachman FW
The What column
Populated database Technician perspective
Database schema Engineer perspective
Physical data model Architect perspective
Logical data model Business mgmt. perspective
Conceptual data model Executive perspective
Thank you for attending
Any questions???