SlideShare a Scribd company logo
1 of 36
Schema-less table &
Dynamic Schema
Davide Mauri
dmauri@solidq.com
@mauridb
Davide Mauri
• Microsoft SQL Server MVP
• Works with SQL Server from 6.5, on BI from 2003
• Specialized in Data Solution Architecture, Database Design, Performance
Tuning, High-Performance Data Warehousing, BI, Big Data
• President of UGISS (Italian SQL Server UG)
• Regular Speaker @ SQL Server events
• Consulting & Training, Mentor @ SolidQ
• E-mail: dmauri@solidq.com
• Twitter: @mauridb
• Blog: http://sqlblog.com/blogs/davide_mauri/default.aspx
Agenda
• Schema, Schemaless & Implicit Schemas
• Possible solutions
• Conclusion
Schema
• “A priori” definition of data structures
• Allows data to be inserted if and only if it is compatible with the
schema
• Es: RDBMS Table, XML Schema, Class, Struct
Schemaless (?)
• No definition at all on the data you expect to have.
• Unstructured data.
• For example: text files, binary files
• with no metadata and no position-based format
• In one word: chaos
Implicit Schema
• In reality a schema always exists, albeit implicit
• Otherwise it would be impossible to handle data
Implicit Schema
Any data that doesn't fit this implicit schema will not be
manipulated properly, leading to errors.
(Schemaless data structures, Martin Fowler)
Pros
• Flexibility
• Easy to manage
• actually, almost no management at all 
• Easy to be extended
• Just add a new element and you’re done
• Easy to be used
• No mismatch between OOP and other models
Cons
• Schema information are hidden somewhere
• Scattered all across the codebase
• It’s really difficult to keep under control the chaos that can
emerge
• For example two different element that contains the same information
• CustomerName and Customer_Name
• You still need to have a sort of «First Normal Form»  in order to avoid
inconsistency and code inefficiencies
Cons
• It’s really difficult to define and maintain integrity constraints
• Data Integrity is a value that must be preserved!
• Otherwise we’ll have data, not information 
• XML Schema were born for that specific reason
• Without Data Integrity, the process of extracting information from data
becomes
• Difficult
• Expensive
• Untrustable
Words of Wisdom
«Schemaless => implicit schema = bad.
Prefer an explicit schema»
(Schemaless data structures, Martin Fowler)
But if we need it anyway?
• What if my use case is one that perfectly fits the need for a
implicit schema?
• The only possible solution are the so-called «No-SQL»
databases
• Document Database or Key-Value store?
• How can I integrate it into already existing database?
• Integration does not come for free!
Schemaless & RDBMS
• (Usually) Are the exact opposite extremes
• Still is a very common request
• CRM, eCommerce, ERPs….
• Schemaless is used not only for pure data persistence
Solution within an RDBMS
• «Custom» columns
• Custom1, Custom2
• In-Table Data Structures
• BLOB, XML, JSON, «Complex» columns
• Entity-Attribute-Value Models
«Custom» Columns
• A problem until SQL Server 2008
• Space is still used for fixed length column even if they contain a NULL
value
• With SQL Server 2008 the «Sparse Column» feature comes to
help
• Helps to make the schema easily modifiable, even in presence of
existing data
• Changes to the schema must still be done with «ALTER TABLE»
«Custom» Columns
• Sparse Columns
• Are Columns at 100%
• Optionally you can have *all* the Sparse Columns returned as a single
XML column
• «Column Set»
• Make development easier
• Do not take space if not used 
• But use more space when used 
Demo
Dynamic Schema & Sparse Columns
In-Table Data Structures
• Complete support for XML
• XPath/XQuery
• XML Index
• Performance «Good Enough»
• But not optimal (compared with the equivalent relational approach)
• Use a lot of space
In-Table Data Structures
• XML Sometimes needs some help to boost performance
• Would be nice to be able to «promote» elements to turn them
into real columns
• Must be done manually using a choice of
• Triggers
• Stored Procedure
• Data Access Layer
• Service Broker
In-Table Data Structures
• JSON support is still missing in SQL Server
• But others database like PostgreSQL already have it…
• …so we can see it coming to MS Platform too 
• Right now one solution is to use SQLCLR
• Solutions available surfing the web:
• http://www.sqlservercentral.com/articles/SQLCLR/74160/
• http://www.json4sql.com/examples.html
• There is also a pure T-SQL solution
• https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-
in-sql-server/
In-Table Data Structures
• Blob is an option if you just need to do persistence
• Blob can be stored in different way
• «Classic» blob inside SQL Server pages & extents
• Blob in a filestream
• Blob in a filetable
Demo
Dynamic Schema & In-Table Data Structures
Entity-Attribute-Values
• Old and very common technique to store attribute-value pairs
• Some well-known samples: Wordpress
• Works on any RDBMS
• No «special» features required
• There’s a huge debate around it 
• http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_mo
del
• But until SQL 2005 no true alternative
Entity-Attribute-Values
Entity-Attribute-Values
• Offers maximum flexibility
• No real control over data types.
• Options to deal with data types
• All strings
• SQL Variant
• One-Column-Per-Type
• Complex query pattern for «AND» predicates between attributes
• «Return all the entities that have «CPU=i7» and «Display=15.4’»
Entity-Attribute-Values
• Queries requires the implementation of a relational operator not
implemented in common RDMBS
• «Relational Division»
• Document and well explained in theory
• It is quite easy to implement it. Follow theory + add some pepper to boost
performances 
Relational Division
• Let’s get back to theory a little bit, in order to see the problem
from a more open perspective:
Dividend
Divisor Result
Remainder
𝛼
𝛽
Relational Division
• How do we implement the division?
• Thanks to Codd and the relational theory we already have the
solution 
28
Relational Division
• Thanks to relational algebra we know that the division is
expressed as
• Generate all possibile pairings
• Remove existing pairing
• (Now we’ve found all pairings that are NOT answers)
• Remove the non-answers from the dividend
29
Demo
Dynamic Schema & EAV
Conclusions
• It works! 
• Performance more than good
• Choose the solution that better fits your use-case
• Search for attributes only?
• Persistence only?
• Search for attributes & values?
• Performance read, write, read/write?
Conclusions
• Use it if and only if when really needed
• Always remeber the «Words of Wisdom» 
• If you can define and use a schema.
• It may seem «not cool» and convoluted but in the long term is the best
solution.
• *data* *must* *be* *turned* *into* *information*
• Sooner or later 
• Without metadata (a schema) it’s really really really hard!
Questions?
Thanks!
• If you want to rate this session on my SpeakerScore page:
• www.speakerscore.com
• Feedback Key: TZQL
Demo Material
• Can be found here
• http://1drv.ms/1Av5mb5
• Everything is release under the Creative Common Attribution-
NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA
4.0)
• http://creativecommons.org/licenses/by-nc-sa/4.0/
Schema less table & dynamic schema

More Related Content

What's hot

DMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4ReportingDMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4Reporting
David Mann
 

What's hot (20)

SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2
 
Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014
 
Optimizing Access with SQL Server
Optimizing Access with SQL ServerOptimizing Access with SQL Server
Optimizing Access with SQL Server
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSON
 
DMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4ReportingDMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4Reporting
 
SenchaCon 2016: Oracle Forms Modernisation - Owen Pagan
SenchaCon 2016: Oracle Forms Modernisation - Owen PaganSenchaCon 2016: Oracle Forms Modernisation - Owen Pagan
SenchaCon 2016: Oracle Forms Modernisation - Owen Pagan
 
SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...
SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...
SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...
 
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
 
Indexes: The neglected performance all rounder
Indexes: The neglected performance all rounderIndexes: The neglected performance all rounder
Indexes: The neglected performance all rounder
 
No Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with BootiqueNo Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with Bootique
 
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
 
Building Ext JS Using HATEOAS - Jeff Stano
Building Ext JS Using HATEOAS - Jeff StanoBuilding Ext JS Using HATEOAS - Jeff Stano
Building Ext JS Using HATEOAS - Jeff Stano
 
Installing SharePoint 2013 – Step by Step presented by Alan Richards
Installing SharePoint 2013 – Step by Step presented by Alan RichardsInstalling SharePoint 2013 – Step by Step presented by Alan Richards
Installing SharePoint 2013 – Step by Step presented by Alan Richards
 
Georgia Tech Drupal Users Group - Local Drupal Development
Georgia Tech Drupal Users Group - Local Drupal DevelopmentGeorgia Tech Drupal Users Group - Local Drupal Development
Georgia Tech Drupal Users Group - Local Drupal Development
 
Solr
SolrSolr
Solr
 
La vita nella corsia di sorpasso; A tutta velocità, XPages!
La vita nella corsia di sorpasso; A tutta velocità, XPages!La vita nella corsia di sorpasso; A tutta velocità, XPages!
La vita nella corsia di sorpasso; A tutta velocità, XPages!
 
Building enterprise applications on the cloud (Level 100)
Building enterprise applications on the cloud (Level 100)Building enterprise applications on the cloud (Level 100)
Building enterprise applications on the cloud (Level 100)
 
RavenDB 4.0
RavenDB 4.0RavenDB 4.0
RavenDB 4.0
 
The databases in SSDT: A work with project and best practices
The databases in SSDT: A work with project and best practicesThe databases in SSDT: A work with project and best practices
The databases in SSDT: A work with project and best practices
 
PowerShell for the Hybrid Admin
PowerShell for the Hybrid AdminPowerShell for the Hybrid Admin
PowerShell for the Hybrid Admin
 

Similar to Schema less table & dynamic schema

Ds03 data analysis
Ds03   data analysisDs03   data analysis
Ds03 data analysis
DotNetCampus
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06
jimbojsb
 
Databases & Microsoft SQL Server
Databases & Microsoft SQL ServerDatabases & Microsoft SQL Server
Databases & Microsoft SQL Server
Mahmoud Abdallah
 

Similar to Schema less table & dynamic schema (20)

Ds03 data analysis
Ds03   data analysisDs03   data analysis
Ds03 data analysis
 
Revision
RevisionRevision
Revision
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
 
How to Survive as a Data Architect in a Polyglot Database World
How to Survive as a Data Architect in a Polyglot Database WorldHow to Survive as a Data Architect in a Polyglot Database World
How to Survive as a Data Architect in a Polyglot Database World
 
Data modeling trends for analytics
Data modeling trends for analyticsData modeling trends for analytics
Data modeling trends for analytics
 
50 Shades of Fail KScope16
50 Shades of Fail KScope1650 Shades of Fail KScope16
50 Shades of Fail KScope16
 
Sql vs NoSQL
Sql vs NoSQLSql vs NoSQL
Sql vs NoSQL
 
Oracle SQL Developer Tips and Tricks: Data Edition
Oracle SQL Developer Tips and Tricks: Data EditionOracle SQL Developer Tips and Tricks: Data Edition
Oracle SQL Developer Tips and Tricks: Data Edition
 
Scalable web architecture
Scalable web architectureScalable web architecture
Scalable web architecture
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06
 
Binder1.pdf
Binder1.pdfBinder1.pdf
Binder1.pdf
 
Databases & Microsoft SQL Server
Databases & Microsoft SQL ServerDatabases & Microsoft SQL Server
Databases & Microsoft SQL Server
 
Sebastian Cohnen – Building a Startup with NoSQL - NoSQL matters Barcelona 2014
Sebastian Cohnen – Building a Startup with NoSQL - NoSQL matters Barcelona 2014Sebastian Cohnen – Building a Startup with NoSQL - NoSQL matters Barcelona 2014
Sebastian Cohnen – Building a Startup with NoSQL - NoSQL matters Barcelona 2014
 
The SEO Magic of Structured Data
The SEO Magic of Structured DataThe SEO Magic of Structured Data
The SEO Magic of Structured Data
 
Building Data Warehouse in SQL Server
Building Data Warehouse in SQL ServerBuilding Data Warehouse in SQL Server
Building Data Warehouse in SQL Server
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
 
ECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site Review
ECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site ReviewECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site Review
ECMDay2015 - Kent Agerlund – Configuration Manager 2012 – A Site Review
 
MySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of viewMySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of view
 
UNIT I Introduction to NoSQL.pptx
UNIT I Introduction to NoSQL.pptxUNIT I Introduction to NoSQL.pptx
UNIT I Introduction to NoSQL.pptx
 
Taming the shrew Power BI
Taming the shrew Power BITaming the shrew Power BI
Taming the shrew Power BI
 

More from Davide Mauri

Agile Data Warehousing
Agile Data WarehousingAgile Data Warehousing
Agile Data Warehousing
Davide Mauri
 

More from Davide Mauri (20)

Azure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstartAzure serverless Full-Stack kickstart
Azure serverless Full-Stack kickstart
 
Agile Data Warehousing
Agile Data WarehousingAgile Data Warehousing
Agile Data Warehousing
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
 
When indexes are not enough
When indexes are not enoughWhen indexes are not enough
When indexes are not enough
 
Building a Real-Time IoT monitoring application with Azure
Building a Real-Time IoT monitoring application with AzureBuilding a Real-Time IoT monitoring application with Azure
Building a Real-Time IoT monitoring application with Azure
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep Dive
 
Azure Stream Analytics
Azure Stream AnalyticsAzure Stream Analytics
Azure Stream Analytics
 
Azure Machine Learning
Azure Machine LearningAzure Machine Learning
Azure Machine Learning
 
Dashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BIDashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BI
 
Event Hub & Azure Stream Analytics
Event Hub & Azure Stream AnalyticsEvent Hub & Azure Stream Analytics
Event Hub & Azure Stream Analytics
 
Real Time Power BI
Real Time Power BIReal Time Power BI
Real Time Power BI
 
AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)
 
Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)
 
Azure Machine Learning (Italian)
Azure Machine Learning (Italian)Azure Machine Learning (Italian)
Azure Machine Learning (Italian)
 
Back to the roots - SQL Server Indexing
Back to the roots - SQL Server IndexingBack to the roots - SQL Server Indexing
Back to the roots - SQL Server Indexing
 
BIML: BI to the next level
BIML: BI to the next levelBIML: BI to the next level
BIML: BI to the next level
 
Agile Data Warehousing
Agile Data WarehousingAgile Data Warehousing
Agile Data Warehousing
 
Data juice
Data juiceData juice
Data juice
 
Data Science Overview
Data Science OverviewData Science Overview
Data Science Overview
 
Delayed durability
Delayed durabilityDelayed durability
Delayed durability
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Schema less table & dynamic schema

  • 1. Schema-less table & Dynamic Schema Davide Mauri dmauri@solidq.com @mauridb
  • 2. Davide Mauri • Microsoft SQL Server MVP • Works with SQL Server from 6.5, on BI from 2003 • Specialized in Data Solution Architecture, Database Design, Performance Tuning, High-Performance Data Warehousing, BI, Big Data • President of UGISS (Italian SQL Server UG) • Regular Speaker @ SQL Server events • Consulting & Training, Mentor @ SolidQ • E-mail: dmauri@solidq.com • Twitter: @mauridb • Blog: http://sqlblog.com/blogs/davide_mauri/default.aspx
  • 3. Agenda • Schema, Schemaless & Implicit Schemas • Possible solutions • Conclusion
  • 4. Schema • “A priori” definition of data structures • Allows data to be inserted if and only if it is compatible with the schema • Es: RDBMS Table, XML Schema, Class, Struct
  • 5. Schemaless (?) • No definition at all on the data you expect to have. • Unstructured data. • For example: text files, binary files • with no metadata and no position-based format • In one word: chaos
  • 6. Implicit Schema • In reality a schema always exists, albeit implicit • Otherwise it would be impossible to handle data
  • 7. Implicit Schema Any data that doesn't fit this implicit schema will not be manipulated properly, leading to errors. (Schemaless data structures, Martin Fowler)
  • 8. Pros • Flexibility • Easy to manage • actually, almost no management at all  • Easy to be extended • Just add a new element and you’re done • Easy to be used • No mismatch between OOP and other models
  • 9. Cons • Schema information are hidden somewhere • Scattered all across the codebase • It’s really difficult to keep under control the chaos that can emerge • For example two different element that contains the same information • CustomerName and Customer_Name • You still need to have a sort of «First Normal Form»  in order to avoid inconsistency and code inefficiencies
  • 10. Cons • It’s really difficult to define and maintain integrity constraints • Data Integrity is a value that must be preserved! • Otherwise we’ll have data, not information  • XML Schema were born for that specific reason • Without Data Integrity, the process of extracting information from data becomes • Difficult • Expensive • Untrustable
  • 11. Words of Wisdom «Schemaless => implicit schema = bad. Prefer an explicit schema» (Schemaless data structures, Martin Fowler)
  • 12. But if we need it anyway? • What if my use case is one that perfectly fits the need for a implicit schema? • The only possible solution are the so-called «No-SQL» databases • Document Database or Key-Value store? • How can I integrate it into already existing database? • Integration does not come for free!
  • 13. Schemaless & RDBMS • (Usually) Are the exact opposite extremes • Still is a very common request • CRM, eCommerce, ERPs…. • Schemaless is used not only for pure data persistence
  • 14. Solution within an RDBMS • «Custom» columns • Custom1, Custom2 • In-Table Data Structures • BLOB, XML, JSON, «Complex» columns • Entity-Attribute-Value Models
  • 15. «Custom» Columns • A problem until SQL Server 2008 • Space is still used for fixed length column even if they contain a NULL value • With SQL Server 2008 the «Sparse Column» feature comes to help • Helps to make the schema easily modifiable, even in presence of existing data • Changes to the schema must still be done with «ALTER TABLE»
  • 16. «Custom» Columns • Sparse Columns • Are Columns at 100% • Optionally you can have *all* the Sparse Columns returned as a single XML column • «Column Set» • Make development easier • Do not take space if not used  • But use more space when used 
  • 17. Demo Dynamic Schema & Sparse Columns
  • 18. In-Table Data Structures • Complete support for XML • XPath/XQuery • XML Index • Performance «Good Enough» • But not optimal (compared with the equivalent relational approach) • Use a lot of space
  • 19. In-Table Data Structures • XML Sometimes needs some help to boost performance • Would be nice to be able to «promote» elements to turn them into real columns • Must be done manually using a choice of • Triggers • Stored Procedure • Data Access Layer • Service Broker
  • 20. In-Table Data Structures • JSON support is still missing in SQL Server • But others database like PostgreSQL already have it… • …so we can see it coming to MS Platform too  • Right now one solution is to use SQLCLR • Solutions available surfing the web: • http://www.sqlservercentral.com/articles/SQLCLR/74160/ • http://www.json4sql.com/examples.html • There is also a pure T-SQL solution • https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings- in-sql-server/
  • 21. In-Table Data Structures • Blob is an option if you just need to do persistence • Blob can be stored in different way • «Classic» blob inside SQL Server pages & extents • Blob in a filestream • Blob in a filetable
  • 22. Demo Dynamic Schema & In-Table Data Structures
  • 23. Entity-Attribute-Values • Old and very common technique to store attribute-value pairs • Some well-known samples: Wordpress • Works on any RDBMS • No «special» features required • There’s a huge debate around it  • http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_mo del • But until SQL 2005 no true alternative
  • 25. Entity-Attribute-Values • Offers maximum flexibility • No real control over data types. • Options to deal with data types • All strings • SQL Variant • One-Column-Per-Type • Complex query pattern for «AND» predicates between attributes • «Return all the entities that have «CPU=i7» and «Display=15.4’»
  • 26. Entity-Attribute-Values • Queries requires the implementation of a relational operator not implemented in common RDMBS • «Relational Division» • Document and well explained in theory • It is quite easy to implement it. Follow theory + add some pepper to boost performances 
  • 27. Relational Division • Let’s get back to theory a little bit, in order to see the problem from a more open perspective: Dividend Divisor Result Remainder 𝛼 𝛽
  • 28. Relational Division • How do we implement the division? • Thanks to Codd and the relational theory we already have the solution  28
  • 29. Relational Division • Thanks to relational algebra we know that the division is expressed as • Generate all possibile pairings • Remove existing pairing • (Now we’ve found all pairings that are NOT answers) • Remove the non-answers from the dividend 29
  • 31. Conclusions • It works!  • Performance more than good • Choose the solution that better fits your use-case • Search for attributes only? • Persistence only? • Search for attributes & values? • Performance read, write, read/write?
  • 32. Conclusions • Use it if and only if when really needed • Always remeber the «Words of Wisdom»  • If you can define and use a schema. • It may seem «not cool» and convoluted but in the long term is the best solution. • *data* *must* *be* *turned* *into* *information* • Sooner or later  • Without metadata (a schema) it’s really really really hard!
  • 34. Thanks! • If you want to rate this session on my SpeakerScore page: • www.speakerscore.com • Feedback Key: TZQL
  • 35. Demo Material • Can be found here • http://1drv.ms/1Av5mb5 • Everything is release under the Creative Common Attribution- NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) • http://creativecommons.org/licenses/by-nc-sa/4.0/

Editor's Notes

  1. http://martinfowler.com/articles/schemaless/