-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.sql
87 lines (80 loc) · 1.89 KB
/
blog.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
-- CREATE DATABASE IF NOT EXISTS
if not exists (select * from sys.databases where name = N'blog')
begin
create database [blog]
end;
USE blog
-- TABLE CATEGORIES
if not exists(select * from sys.tables where name='Categorias')
begin
CREATE TABLE Categorias(
Id Uniqueidentifier primary key,
Titulo varchar(MAX),
Texto varchar(MAX),
Fecha Date,
Estado Int);
end
-- TABLE POSTS
if not exists(select * from sys.tables where name='Posts')
begin
CREATE TABLE Posts(
Id Uniqueidentifier primary key,
Titulo varchar(250),
Contenido varbinary(max),
CategoriaId Uniqueidentifier,
Fecha Date,
UsuarioId UniqueIdentifier,
constraint FK_PostUsuarios_Id FOREIGN KEY (UsuarioId)
references dbo.Usuarios(Id),
constraint FK_Categorias_Id Foreign Key (CategoriaId)
references dbo.Categorias(Id)
);
end
go
-- TABLE TAGS
if not exists(select * from sys.tables where name='Tags')
begin
CREATE TABLE Tags(
Id Uniqueidentifier primary key,
Nombre varchar(50));
end
go
-- TABLE USERS
if not exists(select * from sys.tables where name='Usuarios')
begin
CREATE TABLE Usuarios(
Id Uniqueidentifier primary key,
Nombre varchar(20),
Apellidos varchar(50),
Estado int,
NombreUsuario varchar(50),
Password varchar(250));
end
go
-- TABLE USER PERFIL
if not exists(select * from sys.tables where name='UsuarioPerfil')
begin
CREATE TABLE UsuarioPerfil(
Id Uniqueidentifier primary key,
UsuarioId Uniqueidentifier,
Foto VarBinary(max),
Descripcion nvarchar(max),
constraint FK_Usuario_Id Foreign Key (UsuarioId)
references dbo.Usuarios(Id)
);
end
go
-- TABLE POST TAGS
if not exists(select * from sys.tables where name='PostTags')
begin
CREATE TABLE PostTags(
Id Uniqueidentifier primary key,
PostId Uniqueidentifier,
TagId UniqueIdentifier,
constraint FK_Post_tag_Id Foreign Key (PostId)
references dbo.Posts(Id),
constraint FK_Tag_Id Foreign Key (TagId)
references dbo.Tags(Id)
);
end
go