-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBStackOverFlow.sql
More file actions
107 lines (101 loc) · 2.23 KB
/
DBStackOverFlow.sql
File metadata and controls
107 lines (101 loc) · 2.23 KB
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
create database DBStackOverflow
use DBStackOverflow
create table Category(
IdCategory int identity primary key,
[Name] varchar(50) not null,
)
create table Post(
IdPost int identity primary key,
Title varchar(250) not null,
[Description] varchar(Max) not null,
Creation_Date date not null,
UpVote int not null,
DownVote int not null,
IdCategory int not null,
Foreign Key (IdCategory) references Category(IdCategory)
)
/*stored procedure*/
--
Create Procedure sp_List
as
begin
select * from Post;
end;
--
create Procedure sp_List_Category (@id int)
as
begin
select * from Post where IdCategory = @id;
end
--
Create Procedure sp_Get(@id int)
as
begin
select * from Post where IdPost = @id;
end
--
CREATE PROCEDURE sp_Insert
@Title NVARCHAR(255),
@Description NVARCHAR(MAX),
@Creation_Date DATE,
@IdCategory INT
AS
BEGIN
INSERT INTO Post (Title, [Description], Creation_Date, UpVote, DownVote, IdCategory)
VALUES (@Title, @Description, @Creation_Date, 0, 0, @IdCategory);
END;
--
CREATE PROCEDURE sp_Update
@IdPost int,
@Title NVARCHAR(255),
@Description NVARCHAR(MAX),
@Creation_Date DATE,
@IdCategory INT
AS
BEGIN
Update Post set Title = @Title, [Description] = @Description, Creation_Date = @Creation_Date, IdCategory = @IdCategory where IdPost = @IdPost;
END;
--
Create Procedure sp_Delete(@Id int)
as
begin
Delete Post where IdPost = @Id;
end
--
Create Procedure sp_VoteUp(@IdPost int, @VotingStatus int)
as
begin
Update Post set UpVote = @VotingStatus where IdPost = @IdPost;
end;
--
Create Procedure sp_VoteDown(@IdPost int, @VotingStatus int)
as
begin
Update Post set UpVote = @VotingStatus where IdPost = @IdPost;
end;
--
CREATE PROCEDURE sp_Insert_Category (@Title NVARCHAR(255))
AS
BEGIN
INSERT INTO Category([Name])
VALUES (@Title);
END;
--
Create Procedure sp_Delete_Category(@Id int)
as
begin
Delete Category where IdCategory = @Id;
end
--
Create Procedure sp_List_Categorys
as
begin
select * from Category;
end;
-- Estableciendo categorias
insert Into Category values ('Java')
insert Into Category values ('C#')
insert Into Category values ('Algorithms')
insert Into Category values ('Java Script')
insert Into Category values ('Python')
select * from Category