-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise05part1_DDL.sql
40 lines (31 loc) · 1.11 KB
/
exercise05part1_DDL.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
CREATE DATABASE IF NOT EXISTS db_bufet_advocats;
USE db_bufet_advocats;
CREATE TABLE IF NOT EXISTS clients (
IdClients INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
DNI CHAR(9) UNIQUE,
Nom VARCHAR(20),
AdrecaClients VARCHAR(40)
);
DESCRIBE clients;
CREATE TABLE IF NOT EXISTS assumptes (
IdAssumptes INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Periode DATE,
Estat ENUM('actiu', 'inactiu') DEFAULT 'actiu',
IdClients INT UNSIGNED,
FOREIGN KEY (IdClients) REFERENCES clients(IdClients) ON DELETE SET NULL ON UPDATE CASCADE
);
DESCRIBE assumptes;
CREATE TABLE IF NOT EXISTS procuradors (
IdProcuradors INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Nom VARCHAR(20),
AdrecaProcuradors VARCHAR(40),
DNI CHAR(9) UNIQUE
);
DESCRIBE procuradors;
CREATE TABLE IF NOT EXISTS assumptes_procuradors (
IdAssumptes INT UNSIGNED,
IdProcuradors INT UNSIGNED,
FOREIGN KEY (IdAssumptes) REFERENCES assumptes(IdAssumptes) ON DELETE SET NULL ON UPDATE CASCADE,
FOREIGN KEY (IdProcuradors) REFERENCES procuradors(IdProcuradors) ON DELETE SET NULL ON UPDATE CASCADE
);
DESCRIBE assumptes_procuradors;