-
Notifications
You must be signed in to change notification settings - Fork 1
/
2. CuatroCuadras (Constraints).sql
86 lines (58 loc) · 2.93 KB
/
2. CuatroCuadras (Constraints).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
USE CuatroCuadras
GO
ALTER TABLE CATEGORIA ADD CONSTRAINT PK_IDCategoria PRIMARY KEY (ID_Categoria)
GO
ALTER TABLE LUGAR ADD CONSTRAINT PK_IDLugar PRIMARY KEY(ID_Lugar)
GO
ALTER TABLE LUGAR ADD CONSTRAINT FK_IDCat FOREIGN KEY (ID_Categoria) REFERENCES Categoria(ID_Categoria) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE ETIQUETA ADD CONSTRAINT PK_IDEtiqueta PRIMARY KEY(ID_Etiqueta)
GO
ALTER TABLE LUGAR ADD CONSTRAINT FK_IDEtiq FOREIGN KEY (ID_Etiqueta) REFERENCES ETIQUETA(ID_Etiqueta) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE CIUDAD ADD CONSTRAINT PK_IDCIudad PRIMARY KEY(ID_Ciudad)
GO
ALTER TABLE LUGAR ADD CONSTRAINT FK_L_IDCiudad FOREIGN KEY (ID_Ciudad) REFERENCES Ciudad(ID_Ciudad) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE INTERES ADD CONSTRAINT PK_InteresNickname PRIMARY KEY (ID_Interes)
GO
ALTER TABLE USUARIO ADD CONSTRAINT PK_Nickname PRIMARY KEY(Nickname)
GO
ALTER TABLE USUARIO ADD CONSTRAINT FK_U_IDCiudad FOREIGN KEY (ID_Ciudad) REFERENCES Ciudad(ID_Ciudad) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE VISITA ADD CONSTRAINT FK_IDLugar FOREIGN KEY (ID_Lugar) REFERENCES Lugar(ID_Lugar) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE VISITA ADD CONSTRAINT FK_Nickname FOREIGN KEY (Nickname) REFERENCES Usuario(Nickname) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE LOGRO ADD CONSTRAINT PK_IDLogro PRIMARY KEY(ID_Logro)
GO
ALTER TABLE AMIGO ADD CONSTRAINT FK_Nickname1 FOREIGN KEY (Nickname1) REFERENCES Usuario(Nickname) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE AMIGO ADD CONSTRAINT FK_Nickname2 FOREIGN KEY (Nickname2) REFERENCES Usuario(Nickname) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE AMIGO ADD CONSTRAINT U_Amigo UNIQUE (Nickname1,Nickname2)
GO
ALTER TABLE AMIGO ADD CONSTRAINT Check_EstadoAmigo CHECK (Estado IN ('P','A','R'))
GO
ALTER TABLE AMIGO ADD CONSTRAINT Check_Amigo CHECK (Nickname1!=Nickname2)
GO
ALTER TABLE LOGRO_USUARIO ADD CONSTRAINT FK_LUNickname FOREIGN KEY (Nickname) REFERENCES Usuario(Nickname) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE LOGRO_USUARIO ADD CONSTRAINT FK_IDLogro FOREIGN KEY (ID_Logro) REFERENCES LOGRO(ID_Logro) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE LOGRO_USUARIO add CONSTRAINT U_LogroUsuario UNIQUE (Nickname,ID_Logro)
GO
ALTER TABLE INTERES_USUARIO ADD CONSTRAINT FK_IUNickname FOREIGN KEY (Nickname) REFERENCES Usuario(Nickname)ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE INTERES_USUARIO ADD CONSTRAINT FK_IUID_Interes FOREIGN KEY (ID_Interes) REFERENCES Interes(ID_Interes) ON DELETE CASCADE ON UPDATE CASCADE
GO
ALTER TABLE USUARIO ADD CONSTRAINT Check_Sexo CHECK (Sexo IN ('M', 'F'))
GO
ALTER TABLE USUARIO ADD CONSTRAINT Check_Nacimiento CHECK (Fecha_Nacimiento<=GETDATE())
GO
ALTER TABLE CIUDAD ADD CONSTRAINT Check_Ciudad CHECK (Ciudad NOT LIKE '^[A-Za-zÁÉÍÓÚáéíóúñÑ ]+$')
GO
ALTER TABLE CIUDAD ADD CONSTRAINT U_Ciudad UNIQUE (Ciudad)
GO
ALTER TABLE USUARIO ADD CONSTRAINT U_Email UNIQUE(Email)
GO