-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path04-user-defined-history-table.sql
More file actions
42 lines (40 loc) · 1.28 KB
/
04-user-defined-history-table.sql
File metadata and controls
42 lines (40 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
------------------------------------------------------------------------
-- Topic: SQL Server 2016 Temporal Tables
-- Author: Davide Mauri
-- Credits: -
-- Copyright: Attribution-NonCommercial-ShareAlike 2.5
-- Tab/indent size: 4
-- Last Update: 2016-10-10
-- Tested On: SQL SERVER 2016 RTM
------------------------------------------------------------------------
use [DemoTemporal]
GO
-- create a temporal table with an explicitly specified history table
create table dbo.OrderInfoHistory
(
id int not null,
[description] nvarchar(1000) not null,
[value] money not null,
[received_on] datetime2 not null,
[status] varchar(100) not null,
customer_id varchar(10) not null,
valid_from datetime2 not null,
valid_to datetime2 not null
)
go
create table dbo.OrderInfo
(
id int not null primary key,
[description] nvarchar(1000) not null,
[value] money not null,
[received_on] datetime2 not null,
[status] varchar(100) not null,
customer_id varchar(10) not null,
valid_from datetime2 generated always as row start not null,
valid_to datetime2 generated always as row end not null,
period for system_time (valid_from, valid_to)
)
go
alter table dbo.[OrderInfo]
set (system_versioning = on (history_table = dbo.OrderInfoHistory, data_consistency_check = on))
go