-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbalta-database.sql
110 lines (101 loc) · 3.18 KB
/
balta-database.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
CREATE DATABASE [balta]
GO
USE [balta]
GO
CREATE TABLE [Student]
(
[Id] uniqueidentifier NOT NULL,
[Name] NVARCHAR(120) NOT NULL,
[Email] NVARCHAR(180) NOT NULL,
[Document] NVARCHAR(20) NULL,
[Phone] NVARCHAR(20) NULL,
[Birthdate] DATETIME NULL,
[CreateDate] DATETIME NOT NULL DEFAULT(GETDATE()),
CONSTRAINT [PK_Student] PRIMARY KEY ([Id])
);
GO
CREATE TABLE [Author]
(
[Id] uniqueidentifier NOT NULL,
[Name] NVARCHAR(80) NOT NULL,
[Title] NVARCHAR(80) NOT NULL,
[Image] NVARCHAR(1024) NOT NULL,
[Bio] NVARCHAR(2000) NOT NULL,
[Url] nvarchar(450) NULL,
[Email] NVARCHAR(160) NOT NULL,
[Type] TINYINT NOT NULL, -- 0 a 255
CONSTRAINT [PK_Author] PRIMARY KEY ([Id])
);
GO
CREATE TABLE [Career]
(
[Id] uniqueidentifier NOT NULL,
[Title] NVARCHAR(160) NOT NULL,
[Summary] NVARCHAR(2000) NOT NULL,
[Url] NVARCHAR(1024) NOT NULL,
[DurationInMinutes] INT NOT NULL,
[Active] BIT NOT NULL,
[Featured] BIT NOT NULL,
[Tags] NVARCHAR(160) NOT NULL,
CONSTRAINT [PK_Career] PRIMARY KEY ([Id])
);
GO
CREATE TABLE [Category]
(
[Id] uniqueidentifier NOT NULL,
[Title] NVARCHAR(160) NOT NULL,
[Url] NVARCHAR(1024) NOT NULL,
[Summary] NVARCHAR(2000) NOT NULL,
[Order] int NOT NULL,
[Description] TEXT NOT NULL,
[Featured] BIT NOT NULL,
CONSTRAINT [PK_Category] PRIMARY KEY ([Id])
);
GO
CREATE TABLE [Course]
(
[Id] uniqueidentifier NOT NULL,
[Tag] NVARCHAR(20) NOT NULL,
[Title] NVARCHAR(160) NOT NULL,
[Summary] NVARCHAR(2000) NOT NULL,
[Url] NVARCHAR(1024) NOT NULL,
[Level] TINYINT NOT NULL,
[DurationInMinutes] INT NOT NULL,
[CreateDate] DATETIME NOT NULL,
[LastUpdateDate] DATETIME NOT NULL,
[Active] BIT NOT NULL,
[Free] BIT NOT NULL,
[Featured] BIT NOT NULL,
[AuthorId] uniqueidentifier NOT NULL,
[CategoryId] uniqueidentifier NOT NULL,
[Tags] NVARCHAR(160) NOT NULL,
CONSTRAINT [PK_Course] PRIMARY KEY ([Id]),
CONSTRAINT [FK_Course_Author_AuthorId] FOREIGN KEY ([AuthorId]) REFERENCES [Author] ([Id]),
CONSTRAINT [FK_Course_Category_CategoryId] FOREIGN KEY ([CategoryId]) REFERENCES [Category] ([Id])
);
GO
CREATE TABLE [CareerItem]
(
[CareerId] uniqueidentifier NOT NULL,
[CourseId] uniqueidentifier NOT NULL,
[Title] NVARCHAR(160) NOT NULL,
[Description] TEXT NOT NULL,
[Order] TINYINT NOT NULL,
CONSTRAINT [PK_CareerItem] PRIMARY KEY ([CourseId], [CareerId]),
CONSTRAINT [FK_CareerItem_Career_CareerId] FOREIGN KEY ([CareerId]) REFERENCES [Career] ([Id]),
CONSTRAINT [FK_CareerItem_Course_CourseId] FOREIGN KEY ([CourseId]) REFERENCES [Course] ([Id])
);
GO
CREATE TABLE [StudentCourse]
(
[CourseId] uniqueidentifier NOT NULL,
[StudentId] uniqueidentifier NOT NULL,
[Progress] TINYINT NOT NULL,
[Favorite] BIT NOT NULL,
[StartDate] DATETIME NOT NULL,
[LastUpdateDate] DATETIME NULL DEFAULT(GETDATE()),
CONSTRAINT [PK_StudentCourse] PRIMARY KEY ([CourseId], [StudentId]),
CONSTRAINT [FK_StudentCourse_Course_CourseId] FOREIGN KEY ([CourseId]) REFERENCES [Course] ([Id]),
CONSTRAINT [FK_StudentCourse_Student_StudentId] FOREIGN KEY ([StudentId]) REFERENCES [Student] ([Id])
);
GO