Adding history to crud (Really) DINO ESPOSITO

Slides:



Advertisements
Similar presentations
Time in Databases CSCI 6442 With thanks to Richard Snodgrass, 1985 ACM /85/005/0236.
Advertisements

Accounting System Design
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Constraints, Triggers and Index James Wang.
USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES.
M1G Introduction to Database Development 2. Creating a Database.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
Getting started with Accurately Storing Data
With Temporal Tables and More
Fundamentals of DBMS Notes-1.
Trigger used in PosgreSQL
Rob Gleasure robgleasure.com
Fundamental of Database Systems
Developing modern applications with Temporal Tables and JSON
Temporal Tables Sam Nasr, MCSA, MVP NIS Technologies July 22, 2017
In-Memory Capabilities
Katowice,
Temporal Databases Microsoft SQL Server 2016
Rob Gleasure robgleasure.com
Managing Tables, Data Integrity, Constraints by Adrienne Watt
INLS 623– Database Systems II– File Structures, Indexing, and Hashing
Tables and Triggers.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 6 - Database Implementation and Use
David M. Kroenke and David J
Temporal Databases Microsoft SQL Server 2016
Introduction to SQL 2016 Temporal Tables
Instructor: Jason Carter
Database Keys and Constraints
A time travel with temporal tables
Example of a page header
Designing Tables for a Database System
MIS2502: Data Analytics SQL – Putting Information Into a Database
CIS 336 Competitive Success/snaptutorial.com
CIS 336 Education for Service-- snaptutorial.com.
CIS 336 Teaching Effectively-- snaptutorial.com
Module 5: Implementing Data Integrity by Using Constraints
DATABASE MANAGEMENT SYSTEM
STRUCTURED QUERY LANGUAGE
Traveling in time with SQL Server 2017
Accounting System Design
CS4222 Principles of Database System
Insert, Update, Delete Manipulating Data.
Physical Database Design
Structured Query Language
Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record.
CS122 Using Relational Databases and SQL
Accounting System Design
Statistics for beginners – In-Memory OLTP
MIS2502: Data Analytics SQL – Putting Information Into a Database
CS122 Using Relational Databases and SQL
Chapter 7 Using SQL in Applications
Chapter 7 Using SQL in Applications
CS1222 Using Relational Databases and SQL
…and web frameworks in general
Data Definition Language
CS122 Using Relational Databases and SQL
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Data Time Travel with Temporal Tables
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Applying Data Warehouse Techniques
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
Including Constraints
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
Data Time Travel with Temporal Tables
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
Data Time Travel with Temporal Tables
Presentation transcript:

Adding history to crud (Really) DINO ESPOSITO Press @despos facebook.com/naa4e Press

Why would you like to study medicine? TEACHER I want to defend mankind from diseases! STUDENT You have to study computer science then. TEACHER All I do as a researcher is analytics on bigdata.

WHERE’s YOURS?

Every time you update an existing table record, you automatically lose track of the state it had before. Ever heard about GDPR? Well, they claim every app should be tracking all processing being done on data.

Data is the most valuable asset of every company and the input of any business intelligence processes. No, you were not attending the wrong talk!

WHAT’s NEXT? Rewriting CRUD? Replacing CRUD? Evolving CRUD?

TODAY

C R U D CREATE READ UPDATE DELETE ENTITIES AGGREGATES

C R U D CREATE SUBJECT to APPLICATION LOGIC UPDATE DELETE SUBJECT to DOMAIN LOGIC C R U D READ SUBJECT to PRESENTATION LOGIC

CUSTOM API for SOFT UPDATES and DELETES A soft update is a standard update operation that preserves in some way the old state. A soft delete is an update that marks the state of the record USE an ad hoc DBMS ANSI SQL 2011 standard Historical data management

TEMPORAL TABLES in SQL SERVER 2016+

Temporal Tables Child history table automatically created Read-only for dev code, can’t be deleted Historical data can be queried through ad hoc SQL commands CASCADE not supported if tables are child tables in a foreign key relationship Can’t drop a temporal table Unless you first reset it back to non-temporal state https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-table-considerations-and-limitations

Creating a Temporal Table CREATE TABLE dbo.Employee ( [EmployeeID] int NOT NULL PRIMARY KEY CLUSTERED , [Name] nvarchar(100) NOT NULL , [Position] varchar(100) NOT NULL , [Department] varchar(100) NOT NULL , [Address] nvarchar(1024) NOT NULL , [AnnualSalary] decimal (10,2) NOT NULL , [SysStartTime] datetime2 GENERATED ALWAYS AS ROW START , [SysEndTime] datetime2 GENERATED ALWAYS AS ROW END , PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime) ) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.EmployeeHistory)); Creating a Temporal Table

DateTime columns can’t be NULL and can be arbitrarily named Must be marked as GENERATED ALWAYS AS ROW Reserved to the system The history table cannot have a primary key and can be created programmatically Default history tables have a clustered index on datetime columns (PERIOD) Custom history should also have clustered index for query perf and compression

Resetting a Temporal Table ALTER TABLE dbo.Employee SET (SYSTEM_VERSIONING = OFF) Resetting a Temporal Table

History Table Copy of the main table, plus a couple of datetime2 columns Date columns indicate the validity period for that particular state of the record ValidFrom indicates when the record got a given state ValidTo indicates when the validity of that state ceased Updates and deletes are database operations that cause the values in columns to change

TEMPORAL DATA

Entity Framework and Temporal Tables What’s not there yet (and won’t for more time to come…)

Fact 1: It’s an all-columns-or-nothing thing. Fact 2: CASCADE limitation removed in SQL2017. Fact 3: With BLOB columns can be painful size-wise*. Fact 4: Requires direct SQL commands. Fact 5: In EF Core, can mix with IQueryable. Fact 6: Basic step towards Event Sourcing. Fact 7: Still CRUD.

History tables don’t include any of the following: Indexes Statistics Triggers Permissions

Memory-optimized Temporal Tables use in-memory tables for storing current data (the temporal table) and disk-based tables for historical data. MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA added to T-SQL definition https://docs.microsoft.com/en-us/sql/relational-databases/tables/system-versioned-temporal-tables-with-memory-optimized-tables

Martin Fowler Event Sourcing captures all changes to an application state as a sequence of events. Greg Young State transitions are an important part of our problem space and should be modelled within our domain. Pluralsight courses UXDD/DDD

@despos http://www.dropbox.com/s/3p0pl1f30kqiew9/esposito_netdays_deliverables.zip