-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab02a.sql
More file actions
57 lines (45 loc) · 1.36 KB
/
Copy pathlab02a.sql
File metadata and controls
57 lines (45 loc) · 1.36 KB
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
/*
Lab 02: MariaDB Tutorial
CSC 362 Database Systems
Originally by Thomas E. Allen
Updated by William Bailey
*/
/* Create the database (dropping the previous version if necessary */
DROP DATABASE IF EXISTS bookstore;
CREATE DATABASE bookstore;
USE bookstore;
/* Create the two tables */
CREATE TABLE books (
PRIMARY KEY (isbn),
isbn CHAR(20),
title VARCHAR(50),
author_id INT,
publisher_id INT,
year_pub CHAR(4),
description TEXT
);
CREATE TABLE authors (
PRIMARY KEY (author_id),
author_id INT AUTO_INCREMENT,
name_last VARCHAR(50),
name_first VARCHAR(50),
country VARCHAR(50)
);
/* Populate the tables with sample data */
INSERT INTO authors (name_last, name_first, country)
VALUES ('Kafka', 'Franz', 'Czech Republic');
INSERT INTO books (title, author_id, isbn, year_pub)
VALUES ('The Castle', '1', '0805211063', '1998'),
('The Trial', '1', '0805210407', '1995'),
('The Metamorphosis', '1', '0553213695', '1995'),
('America', '1', '0805210644', '1995');
/* Use SELECT to display some "reports" from the 3 tables. */
SELECT title FROM books;
SELECT title, name_last
FROM books
JOIN authors USING (author_id);
SELECT title AS 'Kafka Books'
FROM books
JOIN authors USING (author_id)
WHERE name_last = 'Kafka';
/* End of file lab02a.sql */