-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp_db.sql
61 lines (54 loc) · 1.42 KB
/
app_db.sql
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- create the customers table
CREATE TABLE dbo.customers (
customer_id INT NOT NULL IDENTITY PRIMARY KEY,
first_name NVARCHAR(128) NOT NULL,
last_name NVARCHAR(128) NOT NULL,
email NVARCHAR(128) NOT NULL,
city NVARCHAR(128) NOT NULL
);
-- insert a record into it
INSERT INTO dbo.customers VALUES(
'Bruce',
'Wayne',
'Gotham City'
)
-- enable CDC on the database
EXEC sys.sp_cdc_enable_db;
-- enable CDC on the customers table
-- NOTE: will not indicate a change for existing data
EXEC sys.sp_cdc_enable_table
@source_schema = N'dbo',
@source_name = N'customers',
@role_name = NULL;
-- insert more records
INSERT INTO dbo.customers VALUES(
'Clark',
'Kent',
'Metropolis'
);
INSERT INTO dbo.customers VALUES(
'Diana',
'Prince',
'UNKNOWN'
);
-- at some point Lex Luthor has broken in...
INSERT INTO dbo.customers VALUES(
'Lex',
'Luthor',
'Everywhere!!!'
);
-- and then revealed Clark's secret email
UPDATE dbo.customers
SET email = '[email protected]'
WHERE customer_id = 2;
-- cyborg is on the case and removes Lex's entry
DELETE FROM dbo.customers
WHERE email = '[email protected]';
-- and smoothes things over for Supes; nothing to see here
UPDATE dbo.customers
SET email = '[email protected]', city = 'Smallville'
WHERE customer_id = 2;