diff --git a/insere_alunos_cursos.sql b/insere_alunos_cursos.sql new file mode 100644 index 0000000..a857dbc --- /dev/null +++ b/insere_alunos_cursos.sql @@ -0,0 +1,26 @@ +SELECT * FROM [Course] +SELECT * FROM [Student] +SELECT * FROM [StudentCourse] + +INSERT INTO + [Student] +VALUES ( + '79b82071-80a8-4e78-a79c-92c8cd1fd052', + 'André Baltieri', + 'hello@balta.io', + '12345678901', + '12345678', + NULL, + GETDATE() +) + +INSERT INTO + [StudentCourse] +VALUES ( + '5f5a33f8-4ff3-7e10-cc6e-3fa000000000', + '79b82071-80a8-4e78-a79c-92c8cd1fd052', + 50, + 0, + '2020-01-13 12:35:54', + GETDATE() +) \ No newline at end of file diff --git a/insert_into_studen_courses.sql b/insert_into_studen_courses.sql new file mode 100644 index 0000000..21e3137 --- /dev/null +++ b/insert_into_studen_courses.sql @@ -0,0 +1,22 @@ +INSERT INTO + [Student] +VALUES ( + 'c55390d4-71dd-4f3c-b978-d1582f51a327', + 'André Baltieri', + 'hello@balta.io', + '12345678901', + '11999999999', + NULL, + GETDATE() +) + +INSERT INTO + [StudentCourse] +VALUES ( + '5d8cf396-e717-9a02-2443-021b00000000', + 'c55390d4-71dd-4f3c-b978-d1582f51a327', + 50, + 0, + '2021-01-15 12:35:54', + GETDATE() +) \ No newline at end of file diff --git a/spDeleteStudent.sql b/spDeleteStudent.sql new file mode 100644 index 0000000..7b69501 --- /dev/null +++ b/spDeleteStudent.sql @@ -0,0 +1,15 @@ +CREATE OR ALTER PROCEDURE spDeleteStudent ( + @StudentId UNIQUEIDENTIFIER +) +AS + BEGIN TRANSACTION + DELETE FROM + [StudentCourse] + WHERE + [StudentId] = @StudentId + + DELETE FROM + [Student] + WHERE + [Id] = @StudentId + COMMIT \ No newline at end of file diff --git a/spStudentProgress.sql b/spStudentProgress.sql new file mode 100644 index 0000000..40bed9c --- /dev/null +++ b/spStudentProgress.sql @@ -0,0 +1,19 @@ +CREATE OR ALTER PROCEDURE spStudentProgress ( + @StudentId UNIQUEIDENTIFIER +) +AS + SELECT + [Student].[Name] AS [Student], + [Course].[Title] AS [Course], + [StudentCourse].[Progress], + [StudentCourse].[LastUpdateDate] + FROM + [StudentCourse] + INNER JOIN [Student] ON [StudentCourse].[StudentId] = [Student].[Id] + INNER JOIN [Course] ON [StudentCourse].[CourseId] = [Course].[Id] + WHERE + [StudentCourse].[StudentId] = @StudentId + AND [StudentCourse].[Progress] < 100 + AND [StudentCourse].[Progress] > 0 + ORDER BY + [StudentCourse].[LastUpdateDate] DESC \ No newline at end of file diff --git a/vwCareers.sql b/vwCareers.sql new file mode 100644 index 0000000..307cb86 --- /dev/null +++ b/vwCareers.sql @@ -0,0 +1,13 @@ +CREATE OR ALTER VIEW vwCareers AS + SELECT + [Career].[Id], + [Career].[Title], + [Career].[Url], + COUNT([Id]) AS [Courses] + FROM + [Career] + INNER JOIN [CareerItem] ON [CareerItem].[CareerId] = [Career].[Id] + GROUP BY + [Career].[Id], + [Career].[Title], + [Career].[Url] \ No newline at end of file diff --git a/vwCourses.sql b/vwCourses.sql new file mode 100644 index 0000000..c3748f4 --- /dev/null +++ b/vwCourses.sql @@ -0,0 +1,16 @@ +CREATE OR ALTER VIEW vwCourses AS + SELECT + [Course].[Id], + [Course].[Tag], + [Course].[Title], + [Course].[Url], + [Course].[Summary], + [Course].[CreateDate], + [Category].[Title] AS [Category], + [Author].[Name] AS [Author] + FROM + [Course] + INNER JOIN [Category] ON [Course].[CategoryId] = [Category].[Id] + INNER JOIN [Author] ON [Course].[AuthorId] = [Author].[Id] + WHERE + [Active] = 1 \ No newline at end of file