Skip to content

Commit

Permalink
Adicionado scripts e base demo
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebaltieri committed Apr 13, 2021
0 parents commit 439025f
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 0 deletions.
50 changes: 50 additions & 0 deletions 001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
USE [Curso]

DROP TABLE [Aluno]
CREATE TABLE [Aluno] (
[Id] INT NOT NULL,
[Nome] NVARCHAR(80) NOT NULL,
[Email] NVARCHAR(180) NOT NULL,
[Nascimento] DATETIME NULL,
[Active] BIT NOT NULL DEFAULT(0),

CONSTRAINT [PK_Aluno] PRIMARY KEY([Id]),
CONSTRAINT [UQ_Aluno_Email] UNIQUE([Email]),
)
GO

CREATE INDEX [IX_Aluno_Email] ON [Aluno]([Email])
DROP INDEX [IX_Aluno_Email] ON [Aluno]

SELECT NEWID()

DROP TABLE [Curso]
CREATE TABLE [Curso] (
[Id] INT NOT NULL IDENTITY(1, 1),
[Nome] NVARCHAR(80) NOT NULL,
[CategoriaId] INT NOT NULL,

CONSTRAINT [PK_Curso] PRIMARY KEY([Id]),
CONSTRAINT [FK_Curso_Categoria] FOREIGN KEY([CategoriaId])
REFERENCES [Categoria]([Id])
)
GO

CREATE TABLE [Categoria] (
[Id] INT NOT NULL,
[Nome] NVARCHAR(80) NOT NULL,

CONSTRAINT [PK_Categoria] PRIMARY KEY([Id])
)
GO

DROP TABLE [ProgressoCurso]
CREATE TABLE [ProgressoCurso] (
[AlunoId] INT NOT NULL,
[CursoId] INT NOT NULL,
[Progresso] INT NOT NULL,
[UltimaAtualizacao] DATETIME NOT NULL DEFAULT(GETDATE()),

CONSTRAINT PK_ProgressoCurso PRIMARY KEY([AlunoId], [CursoId]),
)
GO
110 changes: 110 additions & 0 deletions balta-database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Binary file added balta.zip
Binary file not shown.
23 changes: 23 additions & 0 deletions create_database_cursos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE DATABASE [Cursos]
GO

USE [Cursos]

CREATE TABLE [Categoria] (
[Id] INT NOT NULL IDENTITY(1, 1),
[Nome] NVARCHAR(80) NOT NULL,

CONSTRAINT [PK_Categoria] PRIMARY KEY([Id])
)
GO

CREATE TABLE [Curso] (
[Id] INT NOT NULL IDENTITY(1, 1),
[Nome] NVARCHAR(80) NOT NULL,
[CategoriaId] INT NOT NULL,

CONSTRAINT [PK_Curso] PRIMARY KEY([Id]),
CONSTRAINT [FK_Curso_Categoria] FOREIGN KEY([CategoriaId])
REFERENCES [Categoria]([Id])
)
GO
10 changes: 10 additions & 0 deletions drop_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
USE [master];

DECLARE @kill varchar(8000) = '';
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), session_id) + ';'
FROM sys.dm_exec_sessions
WHERE database_id = db_id('Curso')

EXEC(@kill);

DROP DATABASE [Curso]
8 changes: 8 additions & 0 deletions inserts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INSERT INTO [Categoria]([Nome]) VALUES('Backend')
INSERT INTO [Categoria]([Nome]) VALUES('Frontend')
INSERT INTO [Categoria]([Nome]) VALUES('Mobile')

INSERT INTO [Curso]([Nome], [CategoriaId]) VALUES('Fundamentos de C#', 1)
INSERT INTO [Curso]([Nome], [CategoriaId]) VALUES('Fundamentos OOP', 1)
INSERT INTO [Curso]([Nome], [CategoriaId]) VALUES('Angular', 2)
INSERT INTO [Curso]([Nome], [CategoriaId]) VALUES('Flutter', 3)
9 changes: 9 additions & 0 deletions select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT TOP 100
[Id], [Nome], [CategoriaId]
FROM
[Curso]
-- WHERE
-- [CategoriaId] = 1
ORDER BY
[Nome] DESC

8 changes: 8 additions & 0 deletions spListCourse.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE OR ALTER PROCEDURE [spListCourse]
@Category NVARCHAR(60),
@Par2 NVARCHAR(60)
AS
DECLARE @CategoryId INT
SET @CategoryId = (SELECT TOP 1 [Id] FROM [Categoria] WHERE [Nome] = @Category)

SELECT * FROM [Curso] WHERE [CategoriaId] = @CategoryId

0 comments on commit 439025f

Please sign in to comment.