-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
32 lines (27 loc) · 803 Bytes
/
Copy pathschema.sql
File metadata and controls
32 lines (27 loc) · 803 Bytes
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
/*
Esta es el base de datos que debe ser importada primero
mysql -uroot < schema.sql
*/
DROP DATABASE IF EXISTS agenda;
CREATE DATABASE agenda;
USE agenda;
CREATE TABLE grupos(
id INT PRIMARY KEY AUTO_INCREMENT,
nombre VARCHAR(31) NOT NULL UNIQUE,
descr VARCHAR(2040)
);
CREATE TABLE contactos(
id INT PRIMARY KEY AUTO_INCREMENT,
nombre VARCHAR(31) NOT NULL,
apellido VARCHAR(31) NOT NULL,
telefono VARCHAR(31),
email VARCHAR(31)
);
/* many-to-many relation */
CREATE TABLE contactos_grupos(
contacto INT,
grupo INT,
FOREIGN KEY (contacto) REFERENCES contactos(id) ON DELETE CASCADE,
FOREIGN KEY (grupo) REFERENCES grupos(id) ON DELETE CASCADE,
PRIMARY KEY (contacto,grupo)
);