-
Notifications
You must be signed in to change notification settings - Fork 70
/
01-Tables.sql
64 lines (59 loc) · 1.98 KB
/
01-Tables.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
62
63
64
CREATE TABLE dbo.Question(
QuestionId int IDENTITY(1,1) NOT NULL,
Title nvarchar(100) NOT NULL,
Content nvarchar(max) NOT NULL,
UserId nvarchar(150) NOT NULL,
UserName nvarchar(150) NOT NULL,
Created datetime2(7) NOT NULL,
CONSTRAINT PK_Question PRIMARY KEY CLUSTERED
(
QuestionId ASC
)
)
GO
CREATE TABLE dbo.Answer(
AnswerId int IDENTITY(1,1) NOT NULL,
QuestionId int NOT NULL,
Content nvarchar(max) NOT NULL,
UserId nvarchar(150) NOT NULL,
UserName nvarchar(150) NOT NULL,
Created datetime2(7) NOT NULL,
CONSTRAINT PK_Answer PRIMARY KEY CLUSTERED
(
AnswerId ASC
)
)
GO
ALTER TABLE dbo.Answer WITH CHECK ADD CONSTRAINT FK_Answer_Question FOREIGN KEY(QuestionId)
REFERENCES dbo.Question (QuestionId)
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE dbo.Answer CHECK CONSTRAINT FK_Answer_Question
GO
SET IDENTITY_INSERT dbo.Question ON
GO
INSERT INTO dbo.Question(QuestionId, Title, Content, UserId, UserName, Created)
VALUES(1, 'Why should I learn TypeScript?',
'TypeScript seems to be getting popular so I wondered whether it is worth my time learning it? What benefits does it give over JavaScript?',
'1',
'bob.test@test.com',
'2019-05-18 14:32')
INSERT INTO dbo.Question(QuestionId, Title, Content, UserId, UserName, Created)
VALUES(2, 'Which state management tool should I use?',
'There seem to be a fair few state management tools around for React - React, Unstated, ... Which one should I use?',
'2',
'jane.test@test.com',
'2019-05-18 14:48')
GO
SET IDENTITY_INSERT dbo.Question OFF
GO
SET IDENTITY_INSERT dbo.Answer ON
GO
INSERT INTO dbo.Answer(AnswerId, QuestionId, Content, UserId, UserName, Created)
VALUES(1, 1, 'To catch problems earlier speeding up your developments', '2', 'jane.test@test.com', '2019-05-18 14:40')
INSERT INTO dbo.Answer(AnswerId, QuestionId, Content, UserId, UserName, Created)
VALUES(2, 1, 'So, that you can use the JavaScript features of tomorrow, today', '3', 'fred.test@test.com', '2019-05-18 16:18')
GO
SET IDENTITY_INSERT dbo.Answer OFF
GO