-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTG card database.sql
52 lines (44 loc) · 1.33 KB
/
MTG card database.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
-- start mtg tables--
--USE DUAL PRIMARY ID?--
CREATE TABLE decks (
deck_number INT PRIMARY KEY AUTO_INCREMENT,
deck_name VARCHAR(40)
);
CREATE TABLE mtg_cards (
multiverse_id INT PRIMARY KEY,
card_name VARCHAR (40),
set_name VARCHAR (40),
price DECIMAL (8,2),
location INT DEFAULT 1,
FOREIGN KEY(location) REFERENCES decks(deck_number) ON DELETE SET NULL
);
--moves cards to "unsorted" id location--
CREATE TRIGGER move_to_unsorted
BEFORE DELETE
ON decks FOR EACH ROW
UPDATE mtg_cards
SET location = 1
WHERE location = OLD.deck_number
;
CREATE TABLE wishlist(
multiverse_id INT PRIMARY KEY,
card_name VARCHAR(40),
goes_in INT,
FOREIGN KEY (goes_in) REFERENCES decks(deck_number) ON DELETE CASCADE
);
--DECKS--
INSERT INTO decks VALUES(1,'Unsorted');
INSERT INTO decks VALUES(2,'Prifddinas Tribe');
INSERT INTO decks VALUES(3,'Bosh Smasshhhh!!!');
INSERT INTO decks VALUES(4,'Best Served Cold');
INSERT INTO decks VALUES(5,'Trade Binder');
--CARDS---
INSERT INTO mtg_cards VALUES(420830,'Nath of the Gilt-Leaf','Commander 2016',NULL,2);
DELETE FROM decks
WHERE deck_name = 'Prifddinas Tribe';
select * from mtg_cards;
UPDATE mtg_cards
SET location = 2
WHERE card_name = 'Nath%';
DROP TABLE mtg_cards;
DROP TABLE decks ;